Skip to content

Commit

Permalink
Deleting messages on behalf of chats (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
f213 authored Aug 27, 2024
1 parent 0582a50 commit 0de9a6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down
10 changes: 9 additions & 1 deletion filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]) # МАМА Я УМЕЮ ФУНКЦИОНАЛЬНО ПРОГРАММИРОВАТЬ
Expand All @@ -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
Expand Down

0 comments on commit 0de9a6a

Please sign in to comment.