-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor filter names and imports in bot.py
- Loading branch information
Showing
2 changed files
with
22 additions
and
15 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
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 |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import os | ||
from telegram import Update | ||
from telegram.ext.filters import UpdateFilter | ||
from telegram.ext.filters import UpdateFilter, COMMAND, TEXT, PHOTO | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
AUTHORIZED_USERS = [i.strip() for i in os.getenv("AUTHORIZED_USERS", "").split(",") if i.strip()] | ||
_AUTHORIZED_USERS = [ | ||
i.strip() for i in os.getenv("AUTHORIZED_USERS", "").split(",") if i.strip() | ||
] | ||
|
||
|
||
class AuthorizedUserFilter(UpdateFilter): | ||
def filter(self, update: Update): | ||
if not AUTHORIZED_USERS: | ||
if not _AUTHORIZED_USERS: | ||
return True | ||
return update.message.from_user.username in AUTHORIZED_USERS or str(update.message.from_user.id) in AUTHORIZED_USERS | ||
return ( | ||
update.message.from_user.username in _AUTHORIZED_USERS | ||
or str(update.message.from_user.id) in _AUTHORIZED_USERS | ||
) | ||
|
||
|
||
AuthFilter = AuthorizedUserFilter() | ||
MessageFilter = AuthFilter & ~COMMAND & TEXT | ||
PhotoFilter = AuthFilter & ~COMMAND & PHOTO |