From 1525d7cafd5ac8a180a9ad2940bbe33875cc08d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Wed, 15 Mar 2023 16:03:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20the=20exception=20caused?= =?UTF-8?q?=20by=20player=20or=20cookie=20not=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/birthday.py | 7 ++++--- plugins/tools/challenge.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/genshin/birthday.py b/plugins/genshin/birthday.py index 98de5ab2..17dcc61e 100644 --- a/plugins/genshin/birthday.py +++ b/plugins/genshin/birthday.py @@ -17,7 +17,7 @@ from core.services.users.services import UserService from metadata.genshin import AVATAR_DATA from metadata.shortname import roleToId, roleToName from modules.apihelper.client.components.calendar import Calendar -from plugins.tools.genshin import GenshinHelper +from plugins.tools.genshin import GenshinHelper, CookiesNotFoundError, PlayerNotFoundError from utils.genshin import fetch_hk4e_token_by_cookie, recognize_genshin_game_biz from utils.log import logger @@ -147,8 +147,9 @@ class BirthdayPlugin(Plugin): self.add_delete_message_job(message) self.add_delete_message_job(reply_message) return - client = await self.helper.get_genshin_client(user.id) - if client is None: + try: + client = await self.helper.get_genshin_client(user.id) + except (CookiesNotFoundError, PlayerNotFoundError): buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] if filters.ChatType.GROUPS.filter(message): reply_msg = await message.reply_text( diff --git a/plugins/tools/challenge.py b/plugins/tools/challenge.py index 411eb314..e8f1b1c3 100644 --- a/plugins/tools/challenge.py +++ b/plugins/tools/challenge.py @@ -7,7 +7,7 @@ from core.plugin import Plugin from core.services.cookies import CookiesService from modules.apihelper.client.components.verify import Verify from modules.apihelper.error import ResponseException, APIHelperException -from plugins.tools.genshin import GenshinHelper, PlayerNotFoundError +from plugins.tools.genshin import GenshinHelper, PlayerNotFoundError, CookiesNotFoundError from utils.log import logger __all__ = ("ChallengeSystemException", "ChallengeSystem") @@ -49,6 +49,8 @@ class ChallengeSystem(Plugin): client = await self.genshin_helper.get_genshin_client(user_id) except PlayerNotFoundError: raise ChallengeSystemException("用户未找到") + except CookiesNotFoundError: + raise ChallengeSystemException("无需验证") if client.region != Region.CHINESE: raise ChallengeSystemException("非法用户") if need_verify: @@ -58,7 +60,7 @@ class ChallengeSystem(Plugin): if exc.retcode != 1034: raise exc else: - raise ChallengeSystemException("账户正常,无需认证") + raise ChallengeSystemException("账户正常,无需验证") verify = Verify(cookies=client.cookie_manager.cookies) try: data = await verify.create()