mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-22 15:36:44 +00:00
🐛 Replace all 1034 to NeedChallenge error
This commit is contained in:
parent
1f7d35ff95
commit
339f386997
@ -11,7 +11,7 @@ from gram_core.services.cookies.services import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from simnet import GenshinClient, Region, Game
|
from simnet import GenshinClient, Region, Game
|
||||||
from simnet.errors import InvalidCookies, TooManyRequests, BadRequest as SimnetBadRequest
|
from simnet.errors import InvalidCookies, TooManyRequests, BadRequest as SimnetBadRequest, NeedChallenge
|
||||||
|
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
|
|
||||||
@ -74,13 +74,14 @@ class PublicCookiesService(BaseService, BasePublicCookiesService):
|
|||||||
await self._repository.update(cookies)
|
await self._repository.update(cookies)
|
||||||
await self._cache.delete_public_cookies(cookies.user_id, region)
|
await self._cache.delete_public_cookies(cookies.user_id, region)
|
||||||
raise NeedContinue
|
raise NeedContinue
|
||||||
|
except NeedChallenge:
|
||||||
|
logger.warning("用户 [%s] 触发验证", public_id)
|
||||||
|
await self.set_device_valid(client.account_id, False)
|
||||||
|
await self._cache.delete_public_cookies(cookies.user_id, region)
|
||||||
|
raise NeedContinue
|
||||||
except SimnetBadRequest as exc:
|
except SimnetBadRequest as exc:
|
||||||
if "invalid content type" in exc.message:
|
if "invalid content type" in exc.message:
|
||||||
raise exc
|
raise exc
|
||||||
if exc.ret_code == 1034:
|
|
||||||
logger.warning("用户 [%s] 触发验证", public_id)
|
|
||||||
await self.set_device_valid(client.account_id, False)
|
|
||||||
else:
|
|
||||||
logger.warning("用户 [%s] 获取账号信息发生错误,错误信息为", public_id)
|
logger.warning("用户 [%s] 获取账号信息发生错误,错误信息为", public_id)
|
||||||
logger.exception(exc)
|
logger.exception(exc)
|
||||||
await self._cache.delete_public_cookies(cookies.user_id, region)
|
await self._cache.delete_public_cookies(cookies.user_id, region)
|
||||||
|
@ -2,7 +2,7 @@ from typing import Tuple, Optional
|
|||||||
|
|
||||||
from simnet import Region
|
from simnet import Region
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
from simnet.errors import BadRequest as SIMNetBadRequest
|
from simnet.errors import NeedChallenge
|
||||||
|
|
||||||
from core.basemodel import RegionEnum
|
from core.basemodel import RegionEnum
|
||||||
from core.dependence.redisdb import RedisDB
|
from core.dependence.redisdb import RedisDB
|
||||||
@ -62,9 +62,8 @@ class ChallengeSystem(Plugin):
|
|||||||
if need_verify:
|
if need_verify:
|
||||||
try:
|
try:
|
||||||
await client.get_genshin_notes()
|
await client.get_genshin_notes()
|
||||||
except SIMNetBadRequest as exc:
|
except NeedChallenge:
|
||||||
if exc.retcode != 1034:
|
pass
|
||||||
raise exc
|
|
||||||
else:
|
else:
|
||||||
raise ChallengeSystemException("账户正常,无需验证")
|
raise ChallengeSystemException("账户正常,无需验证")
|
||||||
finally:
|
finally:
|
||||||
|
@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Union
|
|||||||
|
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
from simnet import GenshinClient, Region
|
from simnet import GenshinClient, Region
|
||||||
from simnet.errors import BadRequest as SimnetBadRequest, InvalidCookies, NetworkError, CookieException
|
from simnet.errors import BadRequest as SimnetBadRequest, InvalidCookies, NetworkError, CookieException, NeedChallenge
|
||||||
from simnet.models.genshin.calculator import CalculatorCharacterDetails
|
from simnet.models.genshin.calculator import CalculatorCharacterDetails
|
||||||
from simnet.models.genshin.chronicle.characters import Character
|
from simnet.models.genshin.chronicle.characters import Character
|
||||||
from simnet.utils.player import recognize_game_biz
|
from simnet.utils.player import recognize_game_biz
|
||||||
@ -294,8 +294,8 @@ class GenshinHelper(Plugin):
|
|||||||
if refresh:
|
if refresh:
|
||||||
raise CookieException(message="The cookie has been refreshed.") from exc
|
raise CookieException(message="The cookie has been refreshed.") from exc
|
||||||
raise exc
|
raise exc
|
||||||
except SimnetBadRequest as exc:
|
except NeedChallenge as exc:
|
||||||
if exc.ret_code == 1034 and devices is not None:
|
if devices is not None:
|
||||||
devices.is_valid = False
|
devices.is_valid = False
|
||||||
await self.devices_service.update(devices)
|
await self.devices_service.update(devices)
|
||||||
raise exc
|
raise exc
|
||||||
@ -372,8 +372,7 @@ class GenshinHelper(Plugin):
|
|||||||
) as client:
|
) as client:
|
||||||
try:
|
try:
|
||||||
yield client
|
yield client
|
||||||
except SimnetBadRequest as exc:
|
except NeedChallenge as exc:
|
||||||
if exc.ret_code == 1034:
|
|
||||||
await self.public_cookies_service.undo(user_id)
|
await self.public_cookies_service.undo(user_id)
|
||||||
await self.public_cookies_service.set_device_valid(client.account_id, False)
|
await self.public_cookies_service.set_device_valid(client.account_id, False)
|
||||||
raise exc
|
raise exc
|
||||||
@ -396,7 +395,5 @@ class GenshinHelper(Plugin):
|
|||||||
try:
|
try:
|
||||||
client.public = True
|
client.public = True
|
||||||
yield client
|
yield client
|
||||||
except SimnetBadRequest as exc:
|
except NeedChallenge as exc:
|
||||||
if exc.ret_code == 1034:
|
|
||||||
raise CookiesNotFoundError(user_id) from exc
|
raise CookiesNotFoundError(user_id) from exc
|
||||||
raise exc
|
|
||||||
|
Loading…
Reference in New Issue
Block a user