bot_tools module replaced by davtelepot.administration_tools
This commit is contained in:
parent
e35bf55b53
commit
d38c4aa1fb
@ -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"
|
||||
|
@ -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,
|
||||
|
@ -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="<i>Restart was successful.</i>",
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user