Queer European MD passionate about IT
Browse Source

Implemented button to delete all commands stored by BotFather

Davte 4 years ago
parent
commit
34cf987aa7
3 changed files with 96 additions and 5 deletions
  1. 1 1
      davtelepot/__init__.py
  2. 55 4
      davtelepot/administration_tools.py
  3. 40 0
      davtelepot/messages.py

+ 1 - 1
davtelepot/__init__.py

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

+ 55 - 4
davtelepot/administration_tools.py

@@ -1412,12 +1412,63 @@ async def _father_button(bot: Bot, user_record: OrderedDict,
                 )
             ]
         )
+    elif command == 'del':
+        if not Confirmator.get('del_bot_father_commands',
+                               confirm_timedelta=3
+                               ).confirm(user_record['id']):
+            return bot.get_message(
+                'admin', 'confirm',
+                language=language
+            )
+        stored_commands = await bot.getMyCommands()
+        if not len(stored_commands):
+            text = bot.get_message(
+                'admin', 'father_command', 'del', 'no_change',
+                language=language
+            )
+        else:
+            if isinstance(
+                    await bot.setMyCommands([]),
+                    Exception
+            ):
+                text = bot.get_message(
+                    'admin', 'father_command', 'del', 'error',
+                    language=language
+                )
+            else:
+                text = bot.get_message(
+                    'admin', 'father_command', 'del', 'done',
+                    language=language
+                )
+                reply_markup = make_inline_keyboard(
+                    [
+                        make_button(
+                            text=bot.get_message('admin', 'father_command', 'back',
+                                                 language=language),
+                            prefix='father:///',
+                            delimiter='|',
+                            data=['main']
+                        )
+                    ]
+                )
     elif command == 'get':
         commands = await bot.getMyCommands()
-        text = '<code>' + '\n'.join(
-            "{c[command]} - {c[description]}".format(c=command)
-            for command in commands
-        ) + '</code>'
+        if len(commands) == 0:
+            commands = bot.get_message(
+                'admin', 'father_command', 'get', 'empty',
+                language=language,
+                commands=commands
+            )
+        else:
+            commands = '<code>' + '\n'.join(
+                "{c[command]} - {c[description]}".format(c=command)
+                for command in commands
+            ) + '</code>'
+        text = bot.get_message(
+            'admin', 'father_command', 'get', 'panel',
+            language=language,
+            commands=commands
+        )
         reply_markup = make_inline_keyboard(
             [
                 make_button(

+ 40 - 0
davtelepot/messages.py

@@ -95,6 +95,20 @@ default_admin_messages = {
             'en': "↩️ Back",
             'it': "↩️ Indietro",
         },
+        'del': {
+            'done': {
+                'en': "✅ Commands deleted",
+                'it': "✅ Comandi rimossi",
+            },
+            'error': {
+                'en': "Something went wrong 😕",
+                'it': "Qualcosa è andato storto 😕",
+            },
+            'no_change': {
+                'en': "❌ No command stored",
+                'it': "❌ Nessun comando salvato",
+            },
+        },
         'description': {
             'en': "Edit the @BotFather commands",
             'it': "Modifica i comandi con @BotFather",
@@ -103,6 +117,20 @@ default_admin_messages = {
             'en': "❌ Error! ❌",
             'it': "❌ Errore! ❌",
         },
+        'get': {
+            'empty': {
+                'en': "No command set yet. You may use <code>✏️ Change</code> "
+                      "button",
+                'it': "Nessun comando impostato ancora. Puoi usare il bottone "
+                      "<code>✏️ Modifica</code>",
+            },
+            'panel': {
+                'en': "🤖 <b>BotFather commands</b> ℹ️\n\n"
+                      "{commands}",
+                'it': "🤖 <b>Comandi su BotFather</b> ℹ️\n\n"
+                      "{commands}",
+            },
+        },
         'modes': [
             {
                 'id': "get",
@@ -128,6 +156,18 @@ default_admin_messages = {
                     'it': "Modifica i comandi salvati su @BotFather"
                 },
             },
+            {
+                'id': "del",
+                'name': {
+                    'en': "Delete",
+                    'it': "Cancella"
+                },
+                'symbol': "🗑",
+                'description': {
+                    'en': "Delete commands stored by @BotFather",
+                    'it': "Cancella i comandi salvati su @BotFather"
+                },
+            },
             {
                 'id': "settings",
                 'name': {