mirror of
https://github.com/PaiGramTeam/PamGram.git
synced 2024-11-21 21:58:04 +00:00
🎨 改进部分函数异常处理
This commit is contained in:
parent
1aa0e3d38d
commit
62dbcafa8c
@ -1,5 +1,5 @@
|
||||
from telegram import Update, ReplyKeyboardRemove
|
||||
from telegram.error import BadRequest
|
||||
from telegram.error import BadRequest, Forbidden
|
||||
from telegram.ext import CallbackContext, ConversationHandler
|
||||
|
||||
from core.plugin import handler, conversation
|
||||
@ -12,14 +12,21 @@ async def clean_message(context: CallbackContext):
|
||||
try:
|
||||
# noinspection PyTypeChecker
|
||||
await context.bot.delete_message(chat_id=job.chat_id, message_id=job.data)
|
||||
except BadRequest as error:
|
||||
if "not found" in str(error):
|
||||
except BadRequest as exc:
|
||||
if "not found" in str(exc):
|
||||
logger.warning(f"Auth模块删除消息 chat_id[{job.chat_id}] message_id[{job.data}]失败 消息不存在")
|
||||
elif "Message can't be deleted" in str(error):
|
||||
elif "Message can't be deleted" in str(exc):
|
||||
logger.warning(
|
||||
f"Auth模块删除消息 chat_id[{job.chat_id}] message_id[{job.data}]失败 消息无法删除 可能是没有授权")
|
||||
else:
|
||||
logger.error(f"Auth模块删除消息 chat_id[{job.chat_id}] message_id[{job.data}]失败", error)
|
||||
logger.error(f"Auth模块删除消息 chat_id[{job.chat_id}] message_id[{job.data}]失败")
|
||||
logger.exception(exc)
|
||||
except Forbidden as exc:
|
||||
if "bot was kicked" in str(exc):
|
||||
logger.warning(f"Auth模块删除消息 chat_id[{job.chat_id}] message_id[{job.data}]失败 已经被踢出群")
|
||||
else:
|
||||
logger.error(f"Auth模块删除消息 chat_id[{job.chat_id}] message_id[{job.data}]失败")
|
||||
logger.exception(exc)
|
||||
|
||||
|
||||
def add_delete_message_job(context: CallbackContext, chat_id: int, message_id: int, delete_seconds: int):
|
||||
|
@ -66,8 +66,9 @@ class AdminPlugin(Plugin):
|
||||
except (BadRequest, Forbidden):
|
||||
pass
|
||||
await context.bot.leave_chat(chat_id)
|
||||
except (BadRequest, Forbidden) as error:
|
||||
logger.error(f"退出 chat_id[{chat_id}] 发生错误! 错误信息为 \n", error)
|
||||
await message.reply_text(f"退出 chat_id[{chat_id}] 发生错误! 错误信息为 {str(error)}")
|
||||
except (BadRequest, Forbidden) as exc:
|
||||
logger.error(f"退出 chat_id[{chat_id}] 发生错误! 错误信息为 \n")
|
||||
logger.exception(exc)
|
||||
await message.reply_text(f"退出 chat_id[{chat_id}] 发生错误! 错误信息为 {str(exc)}")
|
||||
return
|
||||
await message.reply_text(f"退出 chat_id[{chat_id}] 成功!")
|
||||
|
Loading…
Reference in New Issue
Block a user