From e54e3803f5bf489c3915ec910dcf8a98bafec300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Sun, 9 Oct 2022 13:45:50 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E6=94=B9=E8=BF=9B=E5=AF=B9=20`T?= =?UTF-8?q?ooManyRequestPublicCookies`=20=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/cookies/services.py | 1 + plugins/genshin/abyss.py | 5 ++++- plugins/genshin/uid.py | 2 +- plugins/genshin/userstats.py | 19 +++++++------------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/core/cookies/services.py b/core/cookies/services.py index b1a18408..0c613e14 100644 --- a/core/cookies/services.py +++ b/core/cookies/services.py @@ -59,6 +59,7 @@ class PublicCookiesService: """ user_times = await self._cache.incr_by_user_times(user_id) if int(user_times) > self.user_times_limiter: + logger.warning(f"用户 [{user_id}] 使用公共Cookie次数已经到达上限") raise TooManyRequestPublicCookies(user_id) while True: public_id, count = await self._cache.get_public_cookies(region) diff --git a/plugins/genshin/abyss.py b/plugins/genshin/abyss.py index 301740d1..cbbf7671 100644 --- a/plugins/genshin/abyss.py +++ b/plugins/genshin/abyss.py @@ -7,7 +7,7 @@ from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filter from core.base.assets import AssetsService from core.baseplugin import BasePlugin -from core.cookies.error import CookiesNotFoundError +from core.cookies.error import CookiesNotFoundError, TooManyRequestPublicCookies from core.cookies.services import CookiesService from core.plugin import Plugin, handler from core.template import TemplateService @@ -125,6 +125,9 @@ class Abyss(Plugin, BasePlugin): self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id, 10) self._add_delete_message_job(context, message.chat_id, message.message_id, 10) return + except TooManyRequestPublicCookies: + await message.reply_text("用户查询次数过多 请稍后重试") + return except (AbyssUnlocked, NoMostKills): await message.reply_text("本次深渊旅行者还没挑战呢,咕咕咕~~~") return diff --git a/plugins/genshin/uid.py b/plugins/genshin/uid.py index ae1f912d..ea16fe54 100644 --- a/plugins/genshin/uid.py +++ b/plugins/genshin/uid.py @@ -107,7 +107,7 @@ class SetUserUid(Plugin.Conversation, BasePlugin.Conversation): try: cookies = await self.public_cookies_service.get_cookies(user.id, region) except TooManyRequestPublicCookies: - await message.reply_text("Cookies公共池已经使用完,请稍后重试", reply_markup=ReplyKeyboardRemove()) + await message.reply_text("用户查询次数过多,请稍后重试", reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END if region == RegionEnum.HYPERION: client = genshin.Client(cookies=cookies.cookies, game=types.Game.GENSHIN, region=types.Region.CHINESE) diff --git a/plugins/genshin/userstats.py b/plugins/genshin/userstats.py index 8415e76a..5eb571fb 100644 --- a/plugins/genshin/userstats.py +++ b/plugins/genshin/userstats.py @@ -9,12 +9,11 @@ from telegram.ext import ( CallbackContext, CommandHandler, MessageHandler, - ConversationHandler, filters, ) from core.baseplugin import BasePlugin -from core.cookies.error import CookiesNotFoundError +from core.cookies.error import CookiesNotFoundError, TooManyRequestPublicCookies from core.plugin import Plugin, handler from core.template.services import TemplateService from core.user.error import UserNotFoundError @@ -24,10 +23,6 @@ from utils.helpers import url_to_file, get_genshin_client, get_public_genshin_cl from utils.log import logger -class TeapotUnlocked(Exception): - """尘歌壶未解锁""" - - class UserStatsPlugins(Plugin, BasePlugin): """玩家统计查询""" @@ -36,7 +31,7 @@ class UserStatsPlugins(Plugin, BasePlugin): @handler(CommandHandler, command="stats", block=False) @handler(MessageHandler, filters=filters.Regex("^玩家统计查询(.*)"), block=False) - @restricts(return_data=ConversationHandler.END) + @restricts() @error_callable async def command_start(self, update: Update, context: CallbackContext) -> Optional[int]: user = update.effective_user @@ -50,7 +45,7 @@ class UserStatsPlugins(Plugin, BasePlugin): except ValueError as exc: logger.warning(f"获取 uid 发生错误! 错误信息为 {repr(exc)}") await message.reply_text("输入错误") - return ConversationHandler.END + return try: try: client = await get_genshin_client(user.id) @@ -68,14 +63,14 @@ class UserStatsPlugins(Plugin, BasePlugin): context, message.chat_id, message.message_id, 30 ) return - except TeapotUnlocked: - await message.reply_text("角色尘歌壶未解锁 如果想要查看具体数据 嗯...... 咕咕咕~") - return ConversationHandler.END + except TooManyRequestPublicCookies: + await message.reply_text("用户查询次数过多 请稍后重试") + return except AttributeError as exc: logger.error("角色数据有误") logger.exception(exc) await message.reply_text("角色数据有误 估计是派蒙晕了") - return ConversationHandler.END + return await message.reply_chat_action(ChatAction.UPLOAD_PHOTO) await message.reply_photo( png_data, filename=f"{client.uid}.png", allow_sending_without_reply=True