diff --git a/modules/apihelper/models/genshin/cookies.py b/modules/apihelper/models/genshin/cookies.py index 14ee86f..9389dbb 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 8477bd0..e2f0976 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,