mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
inline_hanlder done.
This commit is contained in:
parent
e912546680
commit
79c46bccae
@ -66,6 +66,7 @@ class TeleBot:
|
|||||||
self.pre_message_subscribers_next_step = {}
|
self.pre_message_subscribers_next_step = {}
|
||||||
|
|
||||||
self.message_handlers = []
|
self.message_handlers = []
|
||||||
|
self.inline_handlers = []
|
||||||
|
|
||||||
self.threaded = threaded
|
self.threaded = threaded
|
||||||
if self.threaded:
|
if self.threaded:
|
||||||
@ -117,13 +118,20 @@ class TeleBot:
|
|||||||
self.skip_pending = False
|
self.skip_pending = False
|
||||||
updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout)
|
updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout)
|
||||||
new_messages = []
|
new_messages = []
|
||||||
|
new_inline_querys = []
|
||||||
for update in updates:
|
for update in updates:
|
||||||
if update.update_id > self.last_update_id:
|
if update.update_id > self.last_update_id:
|
||||||
self.last_update_id = update.update_id
|
self.last_update_id = update.update_id
|
||||||
new_messages.append(update.message)
|
if update.message:
|
||||||
logger.debug('Received {0} new messages'.format(len(new_messages)))
|
new_messages.append(update.message)
|
||||||
|
if update.inline_query:
|
||||||
|
new_inline_querys.append(update.inline_query)
|
||||||
|
# TODO Chosen
|
||||||
|
logger.debug('Received {0} new updates'.format(len(updates)))
|
||||||
if len(new_messages) > 0:
|
if len(new_messages) > 0:
|
||||||
self.process_new_messages(new_messages)
|
self.process_new_messages(new_messages)
|
||||||
|
if len(new_inline_querys) > 0:
|
||||||
|
self.process_new_inline_query(new_inline_querys)
|
||||||
|
|
||||||
def process_new_messages(self, new_messages):
|
def process_new_messages(self, new_messages):
|
||||||
self._append_pre_next_step_handler()
|
self._append_pre_next_step_handler()
|
||||||
@ -132,6 +140,9 @@ class TeleBot:
|
|||||||
self._notify_message_subscribers(new_messages)
|
self._notify_message_subscribers(new_messages)
|
||||||
self._notify_message_next_handler(new_messages)
|
self._notify_message_next_handler(new_messages)
|
||||||
|
|
||||||
|
def process_new_inline_query(self, new_inline_querys):
|
||||||
|
self._notify_inline_handlers(new_inline_querys)
|
||||||
|
|
||||||
def __notify_update(self, new_messages):
|
def __notify_update(self, new_messages):
|
||||||
for listener in self.update_listener:
|
for listener in self.update_listener:
|
||||||
self.__exec_task(listener, new_messages)
|
self.__exec_task(listener, new_messages)
|
||||||
@ -504,6 +515,21 @@ class TeleBot:
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
def inline_handler(self, regexp=None, func=None):
|
||||||
|
|
||||||
|
def decorator(fn):
|
||||||
|
handler_dict = {'function': fn}
|
||||||
|
filters = {}
|
||||||
|
if regexp:
|
||||||
|
filters['regexp'] = regexp
|
||||||
|
if func:
|
||||||
|
filters['lambda'] = func
|
||||||
|
handler_dict['filters'] = filters
|
||||||
|
self.inline_handlers.append(handler_dict)
|
||||||
|
return fn
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
@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']):
|
||||||
@ -530,6 +556,13 @@ class TeleBot:
|
|||||||
self.__exec_task(message_handler['function'], message)
|
self.__exec_task(message_handler['function'], message)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def _notify_inline_handlers(self, inlien_querys):
|
||||||
|
for inline_query in inlien_querys:
|
||||||
|
for inline_handler in self.inline_handlers:
|
||||||
|
if self._test_message_handler(inline_handler, inline_query):
|
||||||
|
self.__exec_task(inline_handler['function'], inline_query)
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
class AsyncTeleBot(TeleBot):
|
class AsyncTeleBot(TeleBot):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user