Queer European MD passionate about IT
Browse Source

/stop command implemented

Davte 5 years ago
parent
commit
191a2d2ecb
2 changed files with 23 additions and 1 deletions
  1. 1 1
      davtelepot/__init__.py
  2. 22 0
      davtelepot/administration_tools.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.1.23"
+__version__ = "2.1.24"
 __maintainer__ = "Davide Testa"
 __contact__ = "t.me/davte"
 

+ 22 - 0
davtelepot/administration_tools.py

@@ -502,6 +502,12 @@ default_admin_messages = {
             'en': "<i>Restart was successful.</i>",
             'it': "<i>Restart avvenuto con successo.</i>"
         }
+    },
+    'stop_command': {
+        'description': {
+            'en': "Stop bots",
+            'it': "Ferma i bot"
+        }
     }
 }
 
@@ -531,6 +537,11 @@ async def _restart_command(bot, update, user_record):
     return
 
 
+async def _stop_command(bot, update, user_record):
+    bot.__class__.stop(message='=== STOP ===', final_state=0)
+    return
+
+
 def init(bot, talk_messages=None, admin_messages=None, language='en'):
     """Assign parsers, commands, buttons and queries to given `bot`."""
     if talk_messages is None:
@@ -626,3 +637,14 @@ def init(bot, talk_messages=None, admin_messages=None, language='en'):
                     ensure=True
                 )
         return
+
+    stop_command_description = bot.get_message(
+        'admin', 'stop_command', 'description',
+        language=language
+    )
+
+    @bot.command(command='/stop', aliases=[], show_in_keyboard=False,
+                 description=stop_command_description,
+                 authorization_level='admin')
+    async def stop_command(bot, update, user_record):
+        return await _stop_command(bot, update, user_record)