🐛 Replace all 1034 to NeedChallenge error

This commit is contained in:
xtaodada 2023-11-17 20:01:41 +08:00
parent 1f7d35ff95
commit 339f386997
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 19 additions and 22 deletions

View File

@ -11,7 +11,7 @@ from gram_core.services.cookies.services import (
)
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
@ -74,15 +74,16 @@ class PublicCookiesService(BaseService, BasePublicCookiesService):
await self._repository.update(cookies)
await self._cache.delete_public_cookies(cookies.user_id, region)
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:
if "invalid content type" in exc.message:
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.exception(exc)
logger.warning("用户 [%s] 获取账号信息发生错误,错误信息为", public_id)
logger.exception(exc)
await self._cache.delete_public_cookies(cookies.user_id, region)
raise NeedContinue
except RuntimeError as exc:

View File

@ -2,7 +2,7 @@ from typing import Tuple, Optional
from simnet import Region
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.dependence.redisdb import RedisDB
@ -62,9 +62,8 @@ class ChallengeSystem(Plugin):
if need_verify:
try:
await client.get_genshin_notes()
except SIMNetBadRequest as exc:
if exc.retcode != 1034:
raise exc
except NeedChallenge:
pass
else:
raise ChallengeSystemException("账户正常,无需验证")
finally:

View File

@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Union
from pydantic import ValidationError
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.chronicle.characters import Character
from simnet.utils.player import recognize_game_biz
@ -294,8 +294,8 @@ class GenshinHelper(Plugin):
if refresh:
raise CookieException(message="The cookie has been refreshed.") from exc
raise exc
except SimnetBadRequest as exc:
if exc.ret_code == 1034 and devices is not None:
except NeedChallenge as exc:
if devices is not None:
devices.is_valid = False
await self.devices_service.update(devices)
raise exc
@ -372,10 +372,9 @@ class GenshinHelper(Plugin):
) as client:
try:
yield client
except SimnetBadRequest as exc:
if exc.ret_code == 1034:
await self.public_cookies_service.undo(user_id)
await self.public_cookies_service.set_device_valid(client.account_id, False)
except NeedChallenge as exc:
await self.public_cookies_service.undo(user_id)
await self.public_cookies_service.set_device_valid(client.account_id, False)
raise exc
@asynccontextmanager
@ -396,7 +395,5 @@ class GenshinHelper(Plugin):
try:
client.public = True
yield client
except SimnetBadRequest as exc:
if exc.ret_code == 1034:
raise CookiesNotFoundError(user_id) from exc
raise exc
except NeedChallenge as exc:
raise CookiesNotFoundError(user_id) from exc