Skip to content

Commit

Permalink
modules.ai_spam_detection: fix timed deleter
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimifr committed Jan 17, 2025
1 parent 902af20 commit 8510424
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tgbot_python_v2/modules/ai_spam_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def setup_module(cls, app: Application):
app.add_handler(MessageHandler(filters.TEXT, on_message, block=False), group=3)


async def timed_deleter(context: ContextTypes.DEFAULT_TYPE) -> None:
await context.bot.delete_message(context.job.data[0], context.job.data[1])


async def on_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
assert update.message is not None
if update.message.caption is not None:
Expand Down Expand Up @@ -135,6 +139,6 @@ async def on_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None
message = await update.get_bot().send_message(update.message.chat_id,
f"Deleted message from {update.message.from_user.first_name} due to suspected fraud\n"
f"Gemini 2.0 Flash (experiment) confidence rate: {confidence_rate}%")
context.job_queue.run_once(update.get_bot().delete_message, 120, [update.get_bot(), update.message.chat_id, update.message.message_id])
context.job_queue.run_once(timed_deleter, 30, data=[message.chat_id, message.message_id])
except telegram.error.BadRequest:
log.warning("Failed to delete message")

0 comments on commit 8510424

Please sign in to comment.