From d38c4aa1fb37a28be01c7ee2158dc73e086f3d4b Mon Sep 17 00:00:00 2001 From: Davte Date: Sat, 20 Jul 2019 17:09:31 +0200 Subject: [PATCH] bot_tools module replaced by davtelepot.administration_tools --- ciclopibot/__init__.py | 2 +- ciclopibot/bot.py | 5 ++-- ciclopibot/bot_tools.py | 63 ----------------------------------------- 3 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 ciclopibot/bot_tools.py diff --git a/ciclopibot/__init__.py b/ciclopibot/__init__.py index f5ede8f..a9bc094 100644 --- a/ciclopibot/__init__.py +++ b/ciclopibot/__init__.py @@ -3,6 +3,6 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __license__ = "GNU General Public License v3.0" -__version__ = "1.0.6" +__version__ = "1.0.7" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/ciclopibot/bot.py b/ciclopibot/bot.py index 178fe38..46c3851 100644 --- a/ciclopibot/bot.py +++ b/ciclopibot/bot.py @@ -7,10 +7,9 @@ import sys # Third party modules import davtelepot -from davtelepot import authorization, languages +from davtelepot import administration_tools, authorization, languages # Project modules -from . import bot_tools from . import ciclopi from . import helper from .data.passwords import bot_token @@ -122,7 +121,7 @@ if __name__ == '__main__': ), ['telegram_id'] ) - bot_tools.init(bot) + administration_tools.init(bot, language='it') ciclopi.init(bot) helper.init( bot=bot, diff --git a/ciclopibot/bot_tools.py b/ciclopibot/bot_tools.py deleted file mode 100644 index b0f8e50..0000000 --- a/ciclopibot/bot_tools.py +++ /dev/null @@ -1,63 +0,0 @@ -"""Administration tools for CicloPiBot.""" - -# Standard library modules -import asyncio -import datetime - - -async def _restart_command(bot, update, user_record): - with bot.db as db: - db['restart_messages'].insert( - dict( - text="Restart was successful.", - chat_id=update['chat']['id'], - parse_mode='HTML', - reply_to_message_id=update['message_id'], - sent=None - ) - ) - await bot.reply( - update=update, - text="I bot verranno riavviati in pochi secondi, caricando prima le " - "eventuali modifiche al codice." - ) - bot.__class__.stop(message='=== RESTART ===', final_state=65) - return - - -def init(bot): - """Assign commands to `bot`.""" - @bot.command(command='/restart', aliases=[], show_in_keyboard=False, - description="Riavvia i bot", - authorization_level='admin') - async def restart_command(bot, update, user_record): - return await _restart_command(bot, update, user_record) - - @bot.additional_task('BEFORE') - async def load_handovers(): - """Perform handovers before running.""" - with bot.db as db: - for restart_message in db['restart_messages'].find(sent=None): - asyncio.ensure_future( - bot.send_message( - **{ - key: val - for key, val in restart_message.items() - if key in ( - 'chat_id', - 'text', - 'parse_mode', - 'reply_to_message_id' - ) - } - ) - ) - db['restart_messages'].update( - dict( - sent=datetime.datetime.now(), - id=restart_message['id'] - ), - ['id'], - ensure=True - ) - return