From 56cd3971dc406b0952aaa6cc7bb5ce8312b56cc1 Mon Sep 17 00:00:00 2001 From: _run Date: Mon, 16 Aug 2021 22:41:27 +0400 Subject: [PATCH] Update __init__.py --- telebot/__init__.py | 183 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 180 insertions(+), 3 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 5048863be..a3e6c0c13 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -594,7 +594,7 @@ def polling(self, none_stop: bool=False, skip_pending=False, interval: int=0, ti This allows the bot to retrieve Updates automagically and notify listeners and message handlers accordingly. Warning: Do not call this function more than once! - + Always get updates. :param interval: Delay between two update retrivals :param none_stop: Do not stop polling when an ApiException occurs. @@ -2520,6 +2520,23 @@ def add_message_handler(self, handler_dict): """ self.message_handlers.append(handler_dict) + def register_message_handler(self, callback, content_types=None, commands=None, regexp=None, func=None, **kwargs): + """ + Registers message handler. + :param callback: function to be called + :param content_types: list of content_types + :param commands: list of commands + :param regexp: + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + content_types=content_types, + commands=commands, + regexp=regexp, + func=func, + **kwargs) + self.add_message_handler(handler_dict) def edited_message_handler(self, commands=None, regexp=None, func=None, content_types=None, **kwargs): """ Edit message handler decorator @@ -2554,6 +2571,23 @@ def add_edited_message_handler(self, handler_dict): """ self.edited_message_handlers.append(handler_dict) + def register_edited_message_handler(self, callback, content_types=None, commands=None, regexp=None, func=None, **kwargs): + """ + Registers edited message handler. + :param callback: function to be called + :param content_types: list of content_types + :param commands: list of commands + :param regexp: + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + content_types=content_types, + commands=commands, + regexp=regexp, + func=func, + **kwargs) + self.add_edited_message_handler(handler_dict) def channel_post_handler(self, commands=None, regexp=None, func=None, content_types=None, **kwargs): """ Channel post handler decorator @@ -2587,7 +2621,24 @@ def add_channel_post_handler(self, handler_dict): :return: """ self.channel_post_handlers.append(handler_dict) - + + def register_channel_post_handler(self, callback, content_types=None, commands=None, regexp=None, func=None, **kwargs): + """ + Registers channel post message handler. + :param callback: function to be called + :param content_types: list of content_types + :param commands: list of commands + :param regexp: + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + content_types=content_types, + commands=commands, + regexp=regexp, + func=func, + **kwargs) + self.add_channel_post_handler(handler_dict) def edited_channel_post_handler(self, commands=None, regexp=None, func=None, content_types=None, **kwargs): """ Edit channel post handler decorator @@ -2622,6 +2673,24 @@ def add_edited_channel_post_handler(self, handler_dict): """ self.edited_channel_post_handlers.append(handler_dict) + def register_edited_channel_post_handler(self, callback, content_types=None, commands=None, regexp=None, func=None, **kwargs): + """ + Registers edited channel post message handler. + :param callback: function to be called + :param content_types: list of content_types + :param commands: list of commands + :param regexp: + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + content_types=content_types, + commands=commands, + regexp=regexp, + func=func, + **kwargs) + self.add_edited_channel_post_handler(handler_dict) + def inline_handler(self, func, **kwargs): """ Inline call handler decorator @@ -2645,6 +2714,18 @@ def add_inline_handler(self, handler_dict): """ self.inline_handlers.append(handler_dict) + def register_inline_handler(self, callback, func, **kwargs): + """ + Registers inline handler. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_inline_handler(handler_dict) + def chosen_inline_handler(self, func, **kwargs): """ Description: TBD @@ -2668,6 +2749,19 @@ def add_chosen_inline_handler(self, handler_dict): """ self.chosen_inline_handlers.append(handler_dict) + def register_chosen_inline_handler(self, callback, func, **kwargs): + """ + Registers chosen inline handler. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_chosen_inline_handler(handler_dict) + + def callback_query_handler(self, func, **kwargs): """ Callback request handler decorator @@ -2691,6 +2785,18 @@ def add_callback_query_handler(self, handler_dict): """ self.callback_query_handlers.append(handler_dict) + def register_callback_query_handler(self, callback, func, **kwargs): + """ + Registers callback query handler.. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_callback_query_handler(handler_dict) + def shipping_query_handler(self, func, **kwargs): """ Shipping request handler @@ -2714,6 +2820,18 @@ def add_shipping_query_handler(self, handler_dict): """ self.shipping_query_handlers.append(handler_dict) + def register_shipping_query_handler(self, callback, func, **kwargs): + """ + Registers shipping query handler. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_shipping_query_handler(handler_dict) + def pre_checkout_query_handler(self, func, **kwargs): """ Pre-checkout request handler @@ -2736,6 +2854,18 @@ def add_pre_checkout_query_handler(self, handler_dict): :return: """ self.pre_checkout_query_handlers.append(handler_dict) + + def register_pre_checkout_query_handler(self, callback, func, **kwargs): + """ + Registers pre-checkout request handler. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_pre_checkout_query_handler(handler_dict) def poll_handler(self, func, **kwargs): """ @@ -2760,6 +2890,18 @@ def add_poll_handler(self, handler_dict): """ self.poll_handlers.append(handler_dict) + def register_poll_handler(self, callback, func, **kwargs): + """ + Registers poll handler. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_poll_handler(handler_dict) + def poll_answer_handler(self, func=None, **kwargs): """ Poll_answer request handler @@ -2782,7 +2924,19 @@ def add_poll_answer_handler(self, handler_dict): :return: """ self.poll_answer_handlers.append(handler_dict) - + + def register_poll_answer_handler(self, callback, func, **kwargs): + """ + Registers poll answer handler. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_poll_answer_handler(handler_dict) + def my_chat_member_handler(self, func=None, **kwargs): """ my_chat_member handler @@ -2806,6 +2960,18 @@ def add_my_chat_member_handler(self, handler_dict): """ self.my_chat_member_handlers.append(handler_dict) + def register_my_chat_member_handler(self, callback, func=None, **kwargs): + """ + Registers my chat member handler. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_my_chat_member_handler(handler_dict) + def chat_member_handler(self, func=None, **kwargs): """ chat_member handler @@ -2829,6 +2995,17 @@ def add_chat_member_handler(self, handler_dict): """ self.chat_member_handlers.append(handler_dict) + def register_chat_member_handler(self, callback, func=None, **kwargs): + """ + Registers chat member handler. + :param callback: function to be called + :param func: + :return: decorated function + """ + handler_dict = self._build_handler_dict(callback, + func=func, + **kwargs) + self.add_chat_member_handler(handler_dict) def _test_message_handler(self, message_handler, message): """