mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #117 from Dejust/add-handler-setters
Added setters for message/inline/chosen-inline handlers.
This commit is contained in:
commit
45d6f8980c
@ -524,41 +524,65 @@ class TeleBot:
|
|||||||
:param content_types: This commands' supported content types. Must be a list. Defaults to ['text'].
|
:param content_types: This commands' supported content types. Must be a list. Defaults to ['text'].
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def decorator(fn):
|
def decorator(handler):
|
||||||
handler_dict = {'function': fn}
|
self.add_message_handler(handler, commands, regexp, func, content_types)
|
||||||
filters = {'content_types': content_types}
|
return handler
|
||||||
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
|
|
||||||
|
|
||||||
return decorator
|
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 inline_handler(self, func):
|
||||||
def decorator(fn):
|
def decorator(handler):
|
||||||
handler_dict = {'function': fn}
|
self.add_inline_handler(handler, func)
|
||||||
filters = {'lambda': func}
|
return handler
|
||||||
handler_dict['filters'] = filters
|
|
||||||
self.inline_handlers.append(handler_dict)
|
|
||||||
return fn
|
|
||||||
|
|
||||||
return decorator
|
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 chosen_inline_handler(self, func):
|
||||||
def decorator(fn):
|
def decorator(handler):
|
||||||
handler_dict = {'function': fn}
|
self.add_chosen_inline_handler(handler, func)
|
||||||
filters = {'lambda': func}
|
return handler
|
||||||
handler_dict['filters'] = filters
|
|
||||||
self.chosen_inline_handlers.append(handler_dict)
|
|
||||||
return fn
|
|
||||||
|
|
||||||
return decorator
|
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
|
@staticmethod
|
||||||
def _test_message_handler(message_handler, message):
|
def _test_message_handler(message_handler, message):
|
||||||
for filter, filter_value in six.iteritems(message_handler['filters']):
|
for filter, filter_value in six.iteritems(message_handler['filters']):
|
||||||
|
Loading…
Reference in New Issue
Block a user