1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

reupdated

This commit is contained in:
coder2020official 2021-09-11 23:02:56 +05:00
parent 8e4d70b9c6
commit 9d37503442
2 changed files with 41 additions and 10 deletions

View File

@ -3074,17 +3074,20 @@ class TeleBot:
elif message_filter == 'func':
return filter_value(message)
else:
if message_filter in self.custom_filters:
filter_check = self.custom_filters.get(message_filter)
if type(filter_value) is bool:
if filter_value == filter_check.check(message): return True
else: return False
else:
if filter_check.check(message,filter_value) is True: return True
else: return False
return self._check_filter(message_filter,filter_value,message)
def _check_filter(self, message_filter, filter_value, message):
if message_filter in self.custom_filters:
filter_check = self.custom_filters.get(message_filter)
if isinstance(filter_value, util.SimpleCustomFilter):
if filter_value == filter_check.check(message): return True
else: return False
else:
return False
if filter_check.check(message,filter_value) is True: return True
else: return False
else:
return False

View File

@ -456,3 +456,31 @@ def webhook_google_functions(bot, request):
else:
return 'Bot ON'
class SimpleCustomFilter:
"""
Simple Custom Filter base class.
Create child class with check() method.
Accepts only bool.
"""
def check(message):
"""
Perform a check.
"""
pass
class AdvancedCustomFilter:
"""
Simple Custom Filter base class.
Create child class with check() method.
Can accept to parameters.
message: Message class
text: Filter value given in handler
"""
def check(message, text):
"""
Perform a check.
"""
pass