From 3295afa8f5ff4b0ef038221aaf0fb2eb0f940163 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 6 Apr 2024 16:14:41 +0800 Subject: [PATCH] :bug: Fix token v2 parse --- modules/apihelper/models/genshin/cookies.py | 5 +++++ plugins/account/cookies.py | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/apihelper/models/genshin/cookies.py b/modules/apihelper/models/genshin/cookies.py index 14ee86f8..9389dbba 100644 --- a/modules/apihelper/models/genshin/cookies.py +++ b/modules/apihelper/models/genshin/cookies.py @@ -81,6 +81,11 @@ class CookiesModel(BaseModel): if self.ltuid is None and self.ltoken: self.ltuid = user_id + def set_by_dict(self, new_cookies: dict): + for key, value in new_cookies.items(): + if hasattr(self, key) and value is not None: + setattr(self, key, value) + def check(self) -> bool: """检查Cookies是否完整 :return: 成功返回 True 失败返回 False diff --git a/plugins/account/cookies.py b/plugins/account/cookies.py index 8477bd05..e2f09766 100644 --- a/plugins/account/cookies.py +++ b/plugins/account/cookies.py @@ -268,10 +268,7 @@ class AccountCookiesPlugin(Plugin.Conversation): logger.success("用户 %s[%s] 绑定时获取 ltoken 成功", user.full_name, user.id) else: cookies_model = await client.get_all_token_by_stoken(cookies.stoken, cookies.account_id) - cookies.stoken = cookies_model.stoken - cookies.mid = cookies_model.mid - cookies.ltoken = cookies_model.ltoken - cookies.cookie_token = cookies_model.cookie_token + cookies.set_by_dict(cookies_model.dict()) logger.success( "用户 %s[%s] 绑定时获取 stoken_v2, mid, ltoken, cookie_token 成功", user.full_name, user.id ) @@ -398,8 +395,9 @@ class AccountCookiesPlugin(Plugin.Conversation): async def update_player(self, uid: int, genshin_account: Account, region: RegionEnum, account_id: int): player = await self.players_service.get(uid, player_id=genshin_account.uid, region=region) if player: - player.account_id = account_id - await self.players_service.update(player) + if player.account_id != account_id: + player.account_id = account_id + await self.players_service.update(player) else: player_model = Player( user_id=uid,