mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-16 04:35:49 +00:00
🔥 Remove support for Chinese public cookies
Co-authored-by: xtaodada <xtao@xtaolink.cn>
This commit is contained in:
parent
7792503944
commit
635b8444d5
@ -17,7 +17,7 @@ __all__ = ("CookiesService", "PublicCookiesService")
|
||||
|
||||
|
||||
class PublicCookiesService(BaseService, BasePublicCookiesService):
|
||||
async def check_public_cookie(self, region: RegionEnum, cookies: Cookies, public_id: int):
|
||||
async def check_public_cookie(self, region: RegionEnum, cookies: Cookies, public_id: int): # skipcq: PY-R1000 #
|
||||
if region == RegionEnum.HYPERION:
|
||||
client = GenshinClient(cookies=cookies.data, region=Region.CHINESE)
|
||||
elif region == RegionEnum.HOYOLAB:
|
||||
@ -28,16 +28,17 @@ class PublicCookiesService(BaseService, BasePublicCookiesService):
|
||||
if client.account_id is None:
|
||||
raise RuntimeError("account_id not found")
|
||||
record_cards = await client.get_record_cards()
|
||||
for record_card in record_cards:
|
||||
if record_card.game == Game.GENSHIN:
|
||||
await client.get_partial_genshin_user(record_card.uid)
|
||||
break
|
||||
else:
|
||||
accounts = await client.get_game_accounts()
|
||||
for account in accounts:
|
||||
if account.game == Game.GENSHIN:
|
||||
await client.get_partial_genshin_user(account.uid)
|
||||
if client.region == Region.OVERSEAS:
|
||||
for record_card in record_cards:
|
||||
if record_card.game == Game.GENSHIN:
|
||||
await client.get_partial_genshin_user(record_card.uid)
|
||||
break
|
||||
else:
|
||||
accounts = await client.get_game_accounts()
|
||||
for account in accounts:
|
||||
if account.game == Game.GENSHIN:
|
||||
await client.get_partial_genshin_user(account.uid)
|
||||
break
|
||||
except InvalidCookies as exc:
|
||||
if exc.ret_code in (10001, -100):
|
||||
logger.warning("用户 [%s] Cookies无效", public_id)
|
||||
|
@ -86,13 +86,14 @@ class BindAccountPlugin(Plugin.Conversation):
|
||||
await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove())
|
||||
return ConversationHandler.END
|
||||
if message.text == "米游社":
|
||||
reply_keyboard = [["通过账号ID"], ["退出"]]
|
||||
bind_account_plugin_data.region = RegionEnum.HYPERION
|
||||
elif message.text == "HoYoLab":
|
||||
reply_keyboard = [["通过玩家ID", "通过账号ID"], ["退出"]]
|
||||
bind_account_plugin_data.region = RegionEnum.HOYOLAB
|
||||
else:
|
||||
await message.reply_text("选择错误,请重新选择")
|
||||
return CHECK_SERVER
|
||||
reply_keyboard = [["通过玩家ID", "通过账号ID"], ["退出"]]
|
||||
await message.reply_markdown_v2(
|
||||
"请选择你要绑定的方式", reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)
|
||||
)
|
||||
@ -100,12 +101,13 @@ class BindAccountPlugin(Plugin.Conversation):
|
||||
|
||||
@conversation.state(state=CHECK_METHOD)
|
||||
@handler.message(filters=filters.TEXT & ~filters.COMMAND, block=False)
|
||||
async def check_method(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> int:
|
||||
async def check_method(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> int:
|
||||
message = update.effective_message
|
||||
bind_account_plugin_data: BindAccountPluginData = context.chat_data.get("bind_account_plugin_data")
|
||||
if message.text == "退出":
|
||||
await message.reply_text("退出任务", reply_markup=ReplyKeyboardRemove())
|
||||
return ConversationHandler.END
|
||||
if message.text == "通过玩家ID":
|
||||
if message.text == "通过玩家ID" and bind_account_plugin_data.region != RegionEnum.HYPERION:
|
||||
await message.reply_text("请输入你的玩家ID(非通行证ID)", reply_markup=ReplyKeyboardRemove())
|
||||
return CHECK_PLAYER_ID
|
||||
if message.text == "通过账号ID":
|
||||
|
@ -18,6 +18,7 @@ from core.plugin import Plugin, handler
|
||||
from core.services.cookies.error import TooManyRequestPublicCookies
|
||||
from core.services.template.models import RenderGroupResult, RenderResult
|
||||
from core.services.template.services import TemplateService
|
||||
from gram_core.basemodel import RegionEnum
|
||||
from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper
|
||||
from utils.log import logger
|
||||
from utils.uid import mask_number
|
||||
@ -76,7 +77,7 @@ class AbyssPlugin(Plugin):
|
||||
|
||||
@handler.command("abyss", block=False)
|
||||
@handler.message(filters.Regex(msg_pattern), block=False)
|
||||
async def command_start(self, update: Update, _: CallbackContext) -> None:
|
||||
async def command_start(self, update: Update, _: CallbackContext) -> None: # skipcq: PY-R1000 #
|
||||
user = update.effective_user
|
||||
message = update.effective_message
|
||||
uid: Optional[int] = None
|
||||
@ -129,13 +130,13 @@ class AbyssPlugin(Plugin):
|
||||
async with self.helper.genshin(user.id) as client:
|
||||
await client.get_record_cards()
|
||||
images = await self.get_rendered_pic(client, client.player_id, floor, total, previous)
|
||||
except CookiesNotFoundError:
|
||||
except CookiesNotFoundError as exc:
|
||||
if exc.region == RegionEnum.HYPERION:
|
||||
raise exc
|
||||
# Cookie 不存在使用公开接口
|
||||
async with self.helper.public_genshin(user.id) as client:
|
||||
images = await self.get_rendered_pic(client, uid, floor, total, previous)
|
||||
except SimnetBadRequest as exc:
|
||||
if exc.ret_code == 1034 and uid and uid != client.player_id:
|
||||
raise CookiesNotFoundError(uid) from exc
|
||||
raise exc
|
||||
except AbyssUnlocked: # 若深渊未解锁
|
||||
await message.reply_text("还未解锁深渊哦~")
|
||||
@ -171,17 +172,7 @@ class AbyssPlugin(Plugin):
|
||||
|
||||
async def get_rendered_pic(
|
||||
self, client: GenshinClient, uid: int, floor: int, total: bool, previous: bool
|
||||
) -> Union[
|
||||
Tuple[
|
||||
Union[BaseException, Any],
|
||||
Union[BaseException, Any],
|
||||
Union[BaseException, Any],
|
||||
Union[BaseException, Any],
|
||||
Union[BaseException, Any],
|
||||
],
|
||||
List[RenderResult],
|
||||
None,
|
||||
]:
|
||||
) -> Union[Tuple[Any], List[RenderResult], None]:
|
||||
"""
|
||||
获取渲染后的图片
|
||||
|
||||
|
@ -9,6 +9,7 @@ from core.plugin import Plugin, handler
|
||||
from core.services.cookies.error import TooManyRequestPublicCookies
|
||||
from core.services.template.models import RenderResult
|
||||
from core.services.template.services import TemplateService
|
||||
from gram_core.basemodel import RegionEnum
|
||||
from plugins.tools.genshin import CookiesNotFoundError, GenshinHelper
|
||||
from utils.log import logger
|
||||
from utils.uid import mask_number
|
||||
@ -49,12 +50,12 @@ class PlayerStatsPlugins(Plugin):
|
||||
async with self.helper.genshin(user.id) as client:
|
||||
await client.get_record_cards()
|
||||
render_result = await self.render(client, uid)
|
||||
except CookiesNotFoundError:
|
||||
except CookiesNotFoundError as exc:
|
||||
if exc.region == RegionEnum.HYPERION:
|
||||
raise exc
|
||||
async with self.helper.public_genshin(user.id) as client:
|
||||
render_result = await self.render(client, uid)
|
||||
except SimnetBadRequest as exc:
|
||||
if exc.ret_code == 1034 and uid and uid != client.player_id:
|
||||
raise CookiesNotFoundError(uid) from exc
|
||||
raise exc
|
||||
except TooManyRequestPublicCookies:
|
||||
await message.reply_text("用户查询次数过多 请稍后重试")
|
||||
|
@ -193,7 +193,9 @@ class PlayerNotFoundError(Exception):
|
||||
|
||||
|
||||
class CookiesNotFoundError(Exception):
|
||||
def __init__(self, user_id):
|
||||
def __init__(self, user_id: int, region: Optional[RegionEnum] = None):
|
||||
self.user_id = user_id
|
||||
self.region = region
|
||||
super().__init__(f"{user_id} cookies not found")
|
||||
|
||||
|
||||
@ -221,10 +223,10 @@ class GenshinHelper(Plugin):
|
||||
raise PlayerNotFoundError(user_id)
|
||||
|
||||
if player.account_id is None:
|
||||
raise CookiesNotFoundError(user_id)
|
||||
raise CookiesNotFoundError(user_id, player.region)
|
||||
cookie_model = await self.cookies_service.get(player.user_id, player.account_id, player.region)
|
||||
if cookie_model is None:
|
||||
raise CookiesNotFoundError(user_id)
|
||||
raise CookiesNotFoundError(user_id, player.region)
|
||||
cookies = cookie_model.data
|
||||
|
||||
if player.region == RegionEnum.HYPERION: # 国服
|
||||
@ -298,10 +300,10 @@ class GenshinHelper(Plugin):
|
||||
raise PlayerNotFoundError(user_id)
|
||||
|
||||
if player.account_id is None:
|
||||
raise CookiesNotFoundError(user_id)
|
||||
raise CookiesNotFoundError(user_id, player.region)
|
||||
cookie_model = await self.cookies_service.get(player.user_id, player.account_id, player.region)
|
||||
if cookie_model is None:
|
||||
raise CookiesNotFoundError(user_id)
|
||||
raise CookiesNotFoundError(user_id, player.region)
|
||||
cookies = cookie_model.data
|
||||
|
||||
if player.region == RegionEnum.HYPERION:
|
||||
|
Loading…
Reference in New Issue
Block a user