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

Added ability to set message handler, inline handler, chosen inline handler with method calling

This commit is contained in:
Artem Kolesnikov 2016-02-20 15:58:16 +05:00
parent e0ae119512
commit 28417d18af

View File

@ -524,41 +524,65 @@ class TeleBot:
:param content_types: This commands' supported content types. Must be a list. Defaults to ['text'].
"""
def decorator(fn):
handler_dict = {'function': fn}
filters = {'content_types': content_types}
if regexp:
filters['regexp'] = regexp
if func:
filters['lambda'] = func
if commands:
filters['commands'] = commands
handler_dict['filters'] = filters
self.message_handlers.append(handler_dict)
return fn
def decorator(handler):
self.add_message_handler(handler, commands, regexp, func, content_types)
return handler
return decorator
def add_message_handler(self, handler, commands=None, regexp=None, func=None, content_types=None):
if content_types is None:
content_types = ['text']
filters = {'content_types': content_types}
if regexp:
filters['regexp'] = regexp
if func:
filters['lambda'] = func
if commands:
filters['commands'] = commands
handler_dict = {
'function': handler,
'filters': filters
}
self.message_handlers.append(handler_dict)
def inline_handler(self, func):
def decorator(fn):
handler_dict = {'function': fn}
filters = {'lambda': func}
handler_dict['filters'] = filters
self.inline_handlers.append(handler_dict)
return fn
def decorator(handler):
self.add_inline_handler(handler, func)
return handler
return decorator
def add_inline_handler(self, handler, func):
filters = {'lambda': func}
handler_dict = {
'function': handler,
'filters': filters
}
self.inline_handlers.append(handler_dict)
def chosen_inline_handler(self, func):
def decorator(fn):
handler_dict = {'function': fn}
filters = {'lambda': func}
handler_dict['filters'] = filters
self.chosen_inline_handlers.append(handler_dict)
return fn
def decorator(handler):
self.add_chosen_inline_handler(handler, func)
return handler
return decorator
def add_chosen_inline_handler(self, handler, func):
filters = {'lambda': func}
handler_dict = {
'function': handler,
'filters': filters
}
self.chosen_inline_handlers.append(handler_dict)
@staticmethod
def _test_message_handler(message_handler, message):
for filter, filter_value in six.iteritems(message_handler['filters']):