1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Exception if middleware is used but not enabled.

This commit is contained in:
Badiboy 2020-12-24 19:55:24 +03:00
parent ded0d257fc
commit 2534dc5925
2 changed files with 5 additions and 4 deletions

View File

@ -68,7 +68,7 @@ def process_sex_step(message):
if (sex == u'Male') or (sex == u'Female'): if (sex == u'Male') or (sex == u'Female'):
user.sex = sex user.sex = sex
else: 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) bot.send_message(chat_id, 'Nice to meet you ' + user.name + '\n Age:' + str(user.age) + '\n Sex:' + user.sex)
except Exception as e: except Exception as e:
bot.reply_to(message, 'oooops') bot.reply_to(message, 'oooops')

View File

@ -1432,10 +1432,9 @@ class TeleBot:
:param timeout: :param timeout:
:return: :return:
""" """
parse_mode = self.parse_mode if (parse_mode is None) else parse_mode
if isinstance(question, types.Poll): 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( return types.Message.de_json(
apihelper.send_poll( apihelper.send_poll(
@ -1759,7 +1758,6 @@ class TeleBot:
def decorator(handler): def decorator(handler):
self.add_middleware_handler(handler, update_types) self.add_middleware_handler(handler, update_types)
return handler return handler
return decorator return decorator
@ -1771,6 +1769,9 @@ class TeleBot:
:param update_types: :param update_types:
:return: :return:
""" """
if not apihelper.ENABLE_MIDDLEWARE:
raise RuntimeError("Middleware is not enabled. Use apihelper.ENABLE_MIDDLEWARE.")
if update_types: if update_types:
for update_type in update_types: for update_type in update_types:
self.typed_middleware_handlers[update_type].append(handler) self.typed_middleware_handlers[update_type].append(handler)