From 1b47e5cc629ebfa50646a01178833aa073428887 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 13 Jun 2016 14:24:27 +0300 Subject: [PATCH] code duplication lessened --- telebot/__init__.py | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 4e3102f..18e6265 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -723,52 +723,34 @@ class TeleBot: def inline_handler(self, func): def decorator(handler): - self.add_inline_handler(handler, func) + handler_dict = self._build_handler_dict(handler, func=func) + self.add_inline_handler(handler_dict) return handler return decorator - def add_inline_handler(self, handler, func): - filters = {'lambda': func} - - handler_dict = { - 'function': handler, - 'filters': filters - } - + def add_inline_handler(self, handler_dict): self.inline_handlers.append(handler_dict) def chosen_inline_handler(self, func): def decorator(handler): - self.add_chosen_inline_handler(handler, func) + handler_dict = self._build_handler_dict(handler, func=func) + self.add_chosen_inline_handler(handler_dict) return handler return decorator - def add_chosen_inline_handler(self, handler, func): - filters = {'lambda': func} - - handler_dict = { - 'function': handler, - 'filters': filters - } - + def add_chosen_inline_handler(self, handler_dict): self.chosen_inline_handlers.append(handler_dict) def callback_query_handler(self, func): def decorator(handler): - self.add_callback_query_handler(handler, func) + handler_dict = self._build_handler_dict(handler, func=func) + self.add_callback_query_handler(handler_dict) return decorator - def add_callback_query_handler(self, handler, func): - filters = {'lambda': func} - - handler_dict = { - 'function': handler, - 'filters': filters - } - + def add_callback_query_handler(self, handler_dict): self.callback_query_handlers.append(handler_dict) @staticmethod @@ -786,7 +768,7 @@ class TeleBot: return message.content_type == 'text' and re.search(filter_value, message.text) if filter == 'commands': return message.content_type == 'text' and util.extract_command(message.text) in filter_value - if filter == 'lambda': + if filter == 'func': return filter_value(message) return False