🎨 Handle InvalidCookies Exception in Ledger

This commit is contained in:
洛水居室 2022-12-22 23:09:01 +08:00
parent fe12095007
commit 81e0c6f35d
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -2,7 +2,7 @@ import os
import re import re
from datetime import datetime, timedelta from datetime import datetime, timedelta
from genshin import GenshinException, DataNotPublic from genshin import GenshinException, DataNotPublic, InvalidCookies
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.constants import ChatAction from telegram.constants import ChatAction
from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters
@ -123,7 +123,15 @@ class Ledger(Plugin, BasePlugin):
await message.reply_chat_action(ChatAction.TYPING) await message.reply_chat_action(ChatAction.TYPING)
try: try:
client = await get_genshin_client(user.id) client = await get_genshin_client(user.id)
try:
render_result = await self._start_get_ledger(client, month) render_result = await self._start_get_ledger(client, month)
except InvalidCookies: # 如果抛出InvalidCookies 判断是否真的玄学过期(或权限不足?)
await client.get_genshin_user(client.uid)
reply_message = await message.reply_text("出错了呜呜呜 ~ 当前账号无法请求旅行札记数据。")
if filters.ChatType.GROUPS.filter(message):
self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id, 30)
self._add_delete_message_job(context, message.chat_id, message.message_id, 30)
return
except (UserNotFoundError, CookiesNotFoundError): except (UserNotFoundError, CookiesNotFoundError):
buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]]
if filters.ChatType.GROUPS.filter(message): if filters.ChatType.GROUPS.filter(message):