From 8b15e083b720a667a25e13002642a86fdc6ace6f Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Sat, 4 Nov 2023 19:43:27 +0800 Subject: [PATCH] :sparkles: Use stoken v2 instead of v1 --- plugins/account/cookies.py | 20 ++++++++++++++++---- plugins/account/players.py | 15 +++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/plugins/account/cookies.py b/plugins/account/cookies.py index 86be7afb..4eb19f9e 100644 --- a/plugins/account/cookies.py +++ b/plugins/account/cookies.py @@ -286,10 +286,22 @@ class AccountCookiesPlugin(Plugin.Conversation): await message.reply_text("检测到缺少 mid,请尝试添加 mid 后重新绑定。", reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END try: - cookies.cookie_token = await client.get_cookie_token_by_stoken(cookies.stoken, mid=cookies.mid) - logger.success("用户 %s[%s] 绑定时获取 cookie_token 成功", user.full_name, user.id) - cookies.ltoken = await client.get_ltoken_by_stoken() - logger.success("用户 %s[%s] 绑定时获取 ltoken 成功", user.full_name, user.id) + if region == Region.CHINESE: + cookies.stoken, cookies.mid = await client.get_stoken_v2_and_mid_by_by_stoken( + cookies.stoken, cookies.account_id + ) + logger.success("用户 %s[%s] 绑定时获取 stoken_v2, mid 成功", user.full_name, user.id) + cookies.cookie_token = await client.get_cookie_token_by_stoken(cookies.stoken, mid=cookies.mid) + logger.success("用户 %s[%s] 绑定时获取 cookie_token 成功", user.full_name, user.id) + cookies.ltoken = await client.get_ltoken_by_stoken() + 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 + logger.success("用户 %s[%s] 绑定时获取 stoken_v2, mid, ltoken, cookie_token 成功", user.full_name, user.id) except SimnetBadRequest as exc: logger.warning("用户 %s[%s] 获取账号信息发生错误 [%s]%s", user.full_name, user.id, exc.ret_code, exc.original) await message.reply_text("Stoken 无效,请重新绑定。", reply_markup=ReplyKeyboardRemove()) diff --git a/plugins/account/players.py b/plugins/account/players.py index c0f3bdfa..8d249222 100644 --- a/plugins/account/players.py +++ b/plugins/account/players.py @@ -5,8 +5,6 @@ from typing import Tuple, TYPE_CHECKING from simnet import Region, GenshinClient from telegram import InlineKeyboardMarkup, InlineKeyboardButton from telegram.ext import filters - -from core.basemodel import RegionEnum from core.plugin import Plugin, handler from core.services.cookies import CookiesService from core.services.players import PlayersService @@ -128,15 +126,12 @@ class PlayersManagesPlugin(Plugin): InlineKeyboardButton( "导出 Cookies", callback_data=f"players_manager|export_cookies|{user.id}|{player.player_id}", - ) + ), + InlineKeyboardButton( + "刷新 Cookies", + callback_data=f"players_manager|refresh_cookies|{user.id}|{player.player_id}", + ), ] - if player.region == RegionEnum.HYPERION: - temp_buttons.append( - InlineKeyboardButton( - "刷新 Cookies", - callback_data=f"players_manager|refresh_cookies|{user.id}|{player.player_id}", - ) - ) buttons.insert(-1, temp_buttons)