mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-29 02:57:22 +00:00
🎨 改进对 TooManyRequestPublicCookies
异常处理
This commit is contained in:
parent
4843e3d846
commit
e54e3803f5
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user