From 2534dc5925b91b7f0ddfd54228e7007a8960fe73 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Thu, 24 Dec 2020 19:55:24 +0300 Subject: [PATCH] Exception if middleware is used but not enabled. --- examples/step_example.py | 2 +- telebot/__init__.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/step_example.py b/examples/step_example.py index 0fc17e5..0291c66 100644 --- a/examples/step_example.py +++ b/examples/step_example.py @@ -68,7 +68,7 @@ def process_sex_step(message): if (sex == u'Male') or (sex == u'Female'): user.sex = sex else: - raise Exception() + raise Exception("Unknown sex") bot.send_message(chat_id, 'Nice to meet you ' + user.name + '\n Age:' + str(user.age) + '\n Sex:' + user.sex) except Exception as e: bot.reply_to(message, 'oooops') diff --git a/telebot/__init__.py b/telebot/__init__.py index f5ee53a..9f7674f 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1432,10 +1432,9 @@ class TeleBot: :param timeout: :return: """ - parse_mode = self.parse_mode if (parse_mode is None) else parse_mode if isinstance(question, types.Poll): - raise Exception("The send_poll signature was changed, please see send_poll function details.") + raise RuntimeError("The send_poll signature was changed, please see send_poll function details.") return types.Message.de_json( apihelper.send_poll( @@ -1759,7 +1758,6 @@ class TeleBot: def decorator(handler): self.add_middleware_handler(handler, update_types) - return handler return decorator @@ -1771,6 +1769,9 @@ class TeleBot: :param update_types: :return: """ + if not apihelper.ENABLE_MIDDLEWARE: + raise RuntimeError("Middleware is not enabled. Use apihelper.ENABLE_MIDDLEWARE.") + if update_types: for update_type in update_types: self.typed_middleware_handlers[update_type].append(handler)