🐛 Fix token v2 parse

This commit is contained in:
xtaodada 2024-04-06 16:14:41 +08:00
parent 330b1ff1bb
commit 3295afa8f5
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 9 additions and 6 deletions

View File

@ -81,6 +81,11 @@ class CookiesModel(BaseModel):
if self.ltuid is None and self.ltoken: if self.ltuid is None and self.ltoken:
self.ltuid = user_id 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: def check(self) -> bool:
"""检查Cookies是否完整 """检查Cookies是否完整
:return: 成功返回 True 失败返回 False :return: 成功返回 True 失败返回 False

View File

@ -268,10 +268,7 @@ class AccountCookiesPlugin(Plugin.Conversation):
logger.success("用户 %s[%s] 绑定时获取 ltoken 成功", user.full_name, user.id) logger.success("用户 %s[%s] 绑定时获取 ltoken 成功", user.full_name, user.id)
else: else:
cookies_model = await client.get_all_token_by_stoken(cookies.stoken, cookies.account_id) cookies_model = await client.get_all_token_by_stoken(cookies.stoken, cookies.account_id)
cookies.stoken = cookies_model.stoken cookies.set_by_dict(cookies_model.dict())
cookies.mid = cookies_model.mid
cookies.ltoken = cookies_model.ltoken
cookies.cookie_token = cookies_model.cookie_token
logger.success( logger.success(
"用户 %s[%s] 绑定时获取 stoken_v2, mid, ltoken, cookie_token 成功", user.full_name, user.id "用户 %s[%s] 绑定时获取 stoken_v2, mid, ltoken, cookie_token 成功", user.full_name, user.id
) )
@ -398,6 +395,7 @@ class AccountCookiesPlugin(Plugin.Conversation):
async def update_player(self, uid: int, genshin_account: Account, region: RegionEnum, account_id: int): 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) player = await self.players_service.get(uid, player_id=genshin_account.uid, region=region)
if player: if player:
if player.account_id != account_id:
player.account_id = account_id player.account_id = account_id
await self.players_service.update(player) await self.players_service.update(player)
else: else: