diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 7d166f8..a190c2f 100644 --- a/davtelepot/__init__.py +++ b/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" diff --git a/davtelepot/administration_tools.py b/davtelepot/administration_tools.py index 7a0af55..7a50d81 100644 --- a/davtelepot/administration_tools.py +++ b/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 = '' + '\n'.join( - "{c[command]} - {c[description]}".format(c=command) - for command in commands - ) + '' + if len(commands) == 0: + commands = bot.get_message( + 'admin', 'father_command', 'get', 'empty', + language=language, + commands=commands + ) + else: + commands = '' + '\n'.join( + "{c[command]} - {c[description]}".format(c=command) + for command in commands + ) + '' + text = bot.get_message( + 'admin', 'father_command', 'get', 'panel', + language=language, + commands=commands + ) reply_markup = make_inline_keyboard( [ make_button( diff --git a/davtelepot/messages.py b/davtelepot/messages.py index 3b04159..1d88067 100644 --- a/davtelepot/messages.py +++ b/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 ✏️ Change " + "button", + 'it': "Nessun comando impostato ancora. Puoi usare il bottone " + "✏️ Modifica", + }, + 'panel': { + 'en': "🤖 BotFather commands ℹ️\n\n" + "{commands}", + 'it': "🤖 Comandi su BotFather ℹ️\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': {