Skip to content

Commit

Permalink
feat: added a custom filter to check if sender is admin
Browse files Browse the repository at this point in the history
  • Loading branch information
alepiaz committed Nov 30, 2023
1 parent 94a0844 commit 7380b9b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/spotted/handlers/custom_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Defines custom filters to use for commands"""
from telegram import Message, Chat
from telegram.ext.filters import MessageFilter


class IsAdminFilter(MessageFilter):
"""Check if the message from the update was sent by
one of the administrators of the group
Args:
MessageFilter: the superclass for the filter
"""

def filter(self, message: Message):
chat = message.chat
sender_id = message.from_user.id
if chat.type in [Chat.SUPERGROUP, Chat.GROUP]:
return sender_id in [admin.id for admin in chat.get_administrators(chat.id)]
return False

0 comments on commit 7380b9b

Please sign in to comment.