🎨 Update get chat info of clean_message

This commit is contained in:
洛水居室 2022-11-29 22:17:19 +08:00
parent 41b9bac0f2
commit d5f8bf505a
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -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):