From 5928f449c5a9c524860a0818b8953f8f55924be4 Mon Sep 17 00:00:00 2001 From: Fedor Borshev Date: Thu, 20 Jun 2024 23:24:17 +0300 Subject: [PATCH] Not logging messages for channel that have not installed us properly --- bot.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bot.py b/bot.py index 755f1d9..d4f88ca 100644 --- a/bot.py +++ b/bot.py @@ -9,11 +9,24 @@ from helpers import enable_logging, in_production, init_sentry +def get_previous_non_deleted_message_count(chat_id: int) -> int: + from models import LogEntry + + return LogEntry.select().where( + (LogEntry.chat_id == chat_id), + (LogEntry.action == 'deletion_error'), + ).count() + + async def log_message(message: Message | None, action: str | None = ''): """Create a log entry for telegram message""" if message is None or message.from_user is None: return + + if get_previous_non_deleted_message_count(message.chat_id) > 10: + return + from models import LogEntry LogEntry.create(