From aa6f45887e23dca90cba3a0583424041c7bf0d62 Mon Sep 17 00:00:00 2001 From: Davte Date: Sun, 18 Aug 2019 23:23:48 +0200 Subject: [PATCH] Allow addition of help sections --- davtelepot/__init__.py | 2 +- davtelepot/bot.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 051eb20..edb0b19 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -14,7 +14,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.3.0" +__version__ = "2.3.1" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/bot.py b/davtelepot/bot.py index 8b5df27..4012843 100644 --- a/davtelepot/bot.py +++ b/davtelepot/bot.py @@ -1577,6 +1577,18 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): """ self._unknown_command_message = unknown_command_message + def add_help_section(self, help_section): + """Add `help_section`.""" + assert ( + isinstance(help_section, dict) + and 'name' in help_section + and 'label' in help_section + and 'description' in help_section + ), "Invalid help section!" + if 'authorization_level' not in help_section: + help_section['authorization_level'] = 'admin' + self.messages['help_sections'][help_section['name']] = help_section + def command(self, command, aliases=None, reply_keyboard_button=None, show_in_keyboard=False, description="", help_section=None, @@ -1641,7 +1653,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): if isinstance(help_section, dict): if 'authorization_level' not in help_section: help_section['authorization_level'] = authorization_level - self.messages['help_sections'][help_section['name']] = help_section + self.add_help_section(help_section) command = command.strip('/ ').lower() def command_decorator(command_handler):