diff --git a/bot.py b/bot.py index af5c214..f19451c 100644 --- a/bot.py +++ b/bot.py @@ -93,9 +93,9 @@ def delete_messages_that_match(*filters: BaseFilter) -> MessageHandler: bot.add_handler(CommandHandler('start', introduce_myself)) bot.add_handler(CommandHandler('ping', ping)) + bot.add_handler(delete_messages_that_match(IsMessageOnBehalfOfChat())) bot.add_handler(delete_messages_that_match(ContainsTelegramContact())) bot.add_handler(delete_messages_that_match(ContainsLink())) - bot.add_handler(delete_messages_that_match(IsMessageOnBehalfOfChat())) bot.add_handler(delete_messages_that_match(ContainsThreeOrMoreEmojies())) bot.add_handler(delete_messages_that_match(IsMedia())) diff --git a/filters.py b/filters.py index 81ec5c9..6a9b44d 100644 --- a/filters.py +++ b/filters.py @@ -31,10 +31,19 @@ def filter(self, message: Message) -> bool: return message.forward_from_message_id is None +class NotRootChatMessage(MessageFilter): + def filter(self, message: Message) -> bool: + if message.sender_chat is None: + return True + + return message.sender_chat.id != message.chat.id + + def with_default_filters(*filters: BaseFilter) -> BaseFilter: """Apply default filters to the given filter classes""" default_filters = [ ChatMessageOnly(), + NotRootChatMessage(), HasNoValidPreviousMessages(), ] return reduce(operator.and_, [*default_filters, *filters]) # МАМА Я УМЕЮ ФУНКЦИОНАЛЬНО ПРОГРАММИРОВАТЬ @@ -54,7 +63,6 @@ def filter(self, message: Message) -> bool: class ContainsLink(MessageFilter): - def filter(self, message: Message) -> bool: if message.text is None: return False