Skip to content

Commit

Permalink
✨ feat(controller): Add photo and document handling in group chats
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
sudoskys committed Jan 21, 2024
1 parent a58a478 commit f037e24
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions app/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f037e24

Please sign in to comment.