From f037e24155a52f68734955c1bdd484f2d7922377 Mon Sep 17 00:00:00 2001 From: sudoskys Date: Sun, 21 Jan 2024 17:52:23 +0800 Subject: [PATCH] :sparkles: feat(controller): Add photo and document handling in group chats - Added logic to handle photo and document messages in group chats. - Implemented image censorship using the pipeline_pass function. - If an image is detected as potentially illegal, the bot will delete the message and warn the user. - Added a command /report to report spam messages and perform image censorship on the replied message. - Implemented checks for settings.rules and settings.mode to determine whether to perform censorship. --- app/controller.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/controller.py b/app/controller.py index 4908822..d31b906 100644 --- a/app/controller.py +++ b/app/controller.py @@ -80,15 +80,42 @@ async def listen_help_command(message: types.Message): ) async def delete_or_warn(message: types.Message, reason: str): - reason_detail = f"For User {message.from_user.last_name}[{message.from_user.id}]\n{reason}" + reply_messages = [ + formatting.mbold("🔖 自动预警 "), + formatting.mlink( + message.from_user.full_name[:10], + f"tg://user?id={message.from_user.id}", + ), + formatting.mcode(reason), + ] + deleted = False try: await self.bot.delete_message( chat_id=message.chat.id, message_id=message.message_id ) except Exception as er: - logger.exception(er) + logger.error(er) + else: + deleted = True try: - await self.bot.reply_to(message=message, text=reason_detail) + admins = await self.bot.get_chat_administrators(chat_id=message.chat.id) + except Exception as er: + admins = [] + logger.error(er) + if not deleted: + reply_messages.append("🔨 Delete Failed") + for admin in admins[:4]: + reply_messages.append( + " " + + formatting.mlink( + admin.user.full_name[:10], f"tg://user?id={admin.user.id}" + ) + ) + reason_detail = formatting.format_text(*reply_messages, separator=" ") + try: + await self.bot.reply_to( + message=message, text=reason_detail, parse_mode="MarkdownV2" + ) except Exception as er: logger.exception(er) return True