From 81e0c6f35d28b72eceebc1077563fc41f7ee3a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Thu, 22 Dec 2022 23:09:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Handle=20`InvalidCookies`=20Exce?= =?UTF-8?q?ption=20in=20Ledger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/ledger.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/genshin/ledger.py b/plugins/genshin/ledger.py index d3b65670..9f792eb6 100644 --- a/plugins/genshin/ledger.py +++ b/plugins/genshin/ledger.py @@ -2,7 +2,7 @@ import os import re from datetime import datetime, timedelta -from genshin import GenshinException, DataNotPublic +from genshin import GenshinException, DataNotPublic, InvalidCookies from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton from telegram.constants import ChatAction from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters @@ -123,7 +123,15 @@ class Ledger(Plugin, BasePlugin): await message.reply_chat_action(ChatAction.TYPING) try: client = await get_genshin_client(user.id) - render_result = await self._start_get_ledger(client, month) + try: + 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): buttons = [[InlineKeyboardButton("点我绑定账号", url=create_deep_linked_url(context.bot.username, "set_cookie"))]] if filters.ChatType.GROUPS.filter(message):