From d5f8bf505adf2d18f55b04c8a026ba97489c5da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Tue, 29 Nov 2022 22:17:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Update=20get=20chat=20info=20of?= =?UTF-8?q?=20`clean=5Fmessage`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/baseplugin.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/core/baseplugin.py b/core/baseplugin.py index fccae736..feaebe41 100644 --- a/core/baseplugin.py +++ b/core/baseplugin.py @@ -10,30 +10,34 @@ from utils.log import logger async def clean_message(context: CallbackContext): job = context.job message_id = job.data - char_info = f"chat_id[{job.chat_id}]" + chat_info = f"chat_id[{job.chat_id}]" try: chat = await get_chat(job.chat_id) - char_info = f"{chat.full_name}[{chat.id}]" + full_name = chat.full_name + if full_name: + chat_info = f"{full_name}[{chat.id}]" + else: + chat_info = f"{chat.title}[{chat.id}]" except (BadRequest, Forbidden) as exc: logger.warning("获取 chat info 失败 %s", exc.message) except Exception as exc: logger.warning("获取 chat info 消息失败 %s", str(exc)) - logger.debug("删除消息 %s message_id[%s]", char_info, message_id) + logger.debug("删除消息 %s message_id[%s]", chat_info, message_id) try: # noinspection PyTypeChecker await context.bot.delete_message(chat_id=job.chat_id, message_id=message_id) except BadRequest as exc: if "not found" in exc.message: - logger.warning("删除消息 %s message_id[%s] 失败 消息不存在", char_info, message_id) + logger.warning("删除消息 %s message_id[%s] 失败 消息不存在", chat_info, message_id) elif "Message can't be deleted" in exc.message: - logger.warning("删除消息 %s message_id[%s] 失败 消息无法删除 可能是没有授权", char_info, message_id) + logger.warning("删除消息 %s message_id[%s] 失败 消息无法删除 可能是没有授权", chat_info, message_id) else: - logger.warning("删除消息 %s message_id[%s] 失败", char_info, message_id, exc_info=exc) + logger.warning("删除消息 %s message_id[%s] 失败", chat_info, message_id, exc_info=exc) except Forbidden as exc: if "bot was kicked" in exc.message: - logger.warning("删除消息 %s message_id[%s] 失败 已经被踢出群", char_info, message_id) + logger.warning("删除消息 %s message_id[%s] 失败 已经被踢出群", chat_info, message_id) else: - logger.warning("删除消息 %s message_id[%s] 失败", char_info, message_id, exc_info=exc) + logger.warning("删除消息 %s message_id[%s] 失败", chat_info, message_id, exc_info=exc) def add_delete_message_job(context: CallbackContext, chat_id: int, message_id: int, delete_seconds: int):