Allow addition of help sections

This commit is contained in:
Davte 2019-08-18 23:23:48 +02:00
parent 45e2bbfa3d
commit aa6f45887e
2 changed files with 14 additions and 2 deletions

View File

@ -14,7 +14,7 @@ __author__ = "Davide Testa"
__email__ = "davide@davte.it" __email__ = "davide@davte.it"
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
__license__ = "GNU General Public License v3.0" __license__ = "GNU General Public License v3.0"
__version__ = "2.3.0" __version__ = "2.3.1"
__maintainer__ = "Davide Testa" __maintainer__ = "Davide Testa"
__contact__ = "t.me/davte" __contact__ = "t.me/davte"

View File

@ -1577,6 +1577,18 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
""" """
self._unknown_command_message = unknown_command_message 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, def command(self, command, aliases=None, reply_keyboard_button=None,
show_in_keyboard=False, description="", show_in_keyboard=False, description="",
help_section=None, help_section=None,
@ -1641,7 +1653,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
if isinstance(help_section, dict): if isinstance(help_section, dict):
if 'authorization_level' not in help_section: if 'authorization_level' not in help_section:
help_section['authorization_level'] = authorization_level 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() command = command.strip('/ ').lower()
def command_decorator(command_handler): def command_decorator(command_handler):