-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
filters.py
40 lines (27 loc) · 1.27 KB
/
filters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from telegram import Message
from telegram.ext import BaseFilter
from tg_bot import SUPPORT_USERS, SUDO_USERS, DEV_USERS
class CustomFilters(object):
class _Supporters(BaseFilter):
def filter(self, message: Message):
return bool(message.from_user and message.from_user.id in SUPPORT_USERS)
support_filter = _Supporters()
class _Sudoers(BaseFilter):
def filter(self, message: Message):
return bool(message.from_user and message.from_user.id in SUDO_USERS)
sudo_filter = _Sudoers()
class _Developers(BaseFilter):
def filter(self, message: Message):
return bool(message.from_user and message.from_user.id in DEV_USERS)
dev_filter = _Developers()
class _MimeType(BaseFilter):
def __init__(self, mimetype):
self.mime_type = mimetype
self.name = "CustomFilters.mime_type({})".format(self.mime_type)
def filter(self, message: Message):
return bool(message.document and message.document.mime_type == self.mime_type)
mime_type = _MimeType
class _HasText(BaseFilter):
def filter(self, message: Message):
return bool(message.text or message.sticker or message.photo or message.document or message.video)
has_text = _HasText()