-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added a custom filter to check if sender is admin
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |