Queer European MD passionate about IT
浏览代码

Allow addition of help sections

Davte 5 年之前
父节点
当前提交
aa6f45887e
共有 2 个文件被更改,包括 14 次插入2 次删除
  1. 1 1
      davtelepot/__init__.py
  2. 13 1
      davtelepot/bot.py

+ 1 - 1
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"
 

+ 13 - 1
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):