From ba44956dd4ccb5198ca3040faf94060f0b83b812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Wed, 30 Nov 2022 11:08:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20error=20handler=20in=20cal?= =?UTF-8?q?lback=20query=20of=20`error=5Fcallable`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复Bot在处理callback query的消息类型时回复的消息以和自动删除通知错误的问题 --- utils/decorators/error.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/decorators/error.py b/utils/decorators/error.py index 376a3f3..a12824c 100644 --- a/utils/decorators/error.py +++ b/utils/decorators/error.py @@ -41,6 +41,9 @@ async def send_user_notification(update: Update, context: CallbackContext, text: return None logger.info("尝试通知用户 %s[%s] 在 %s[%s] 的错误信息[%s]", user.full_name, user.id, chat.full_name, chat.id, text) try: + if update.callback_query: + await update.callback_query.answer(text, show_alert=True) + return None return await message.reply_text(text, reply_markup=buttons, allow_sending_without_reply=True) except ConnectTimeout: logger.error("httpx 模块连接服务器 ConnectTimeout 发送 update_id[%s] 错误信息失败", update.update_id) @@ -154,11 +157,10 @@ def error_callable(func: Callable) -> Callable: if text: notice_message = await send_user_notification(update, context, text) message = update.effective_message - if message: - if filters.ChatType.GROUPS.filter(message): - if notice_message: - add_delete_message_job(context, notice_message.chat_id, notice_message.message_id, 60) - add_delete_message_job(context, message.chat_id, message.message_id, 60) + if message and not update.callback_query and filters.ChatType.GROUPS.filter(message): + if notice_message: + add_delete_message_job(context, notice_message.chat_id, notice_message.message_id, 60) + add_delete_message_job(context, message.chat_id, message.message_id, 60) else: user = update.effective_user chat = update.effective_chat