Version command implemented

This commit is contained in:
Davte 2020-02-20 11:06:47 +01:00
parent 086750c77e
commit 4487034c7d
3 changed files with 47 additions and 1 deletions

View File

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

View File

@ -778,6 +778,25 @@ def get_maintenance_exception_criterion(bot, allowed_command):
return criterion return criterion
async def _version_command(bot, update, user_record):
try:
_subprocess = await asyncio.create_subprocess_exec(
'git', 'rev-parse', 'HEAD',
stdout=asyncio.subprocess.PIPE
)
stdout, stderr = await _subprocess.communicate()
if stderr is not None:
raise stderr
version = stdout.decode().strip()
except Exception as e:
return f"{e}"
return bot.get_message(
'admin', 'version_command', 'result',
version=version,
update=update, user_record=user_record
)
def init(telegram_bot, talk_messages=None, admin_messages=None): def init(telegram_bot, talk_messages=None, admin_messages=None):
"""Assign parsers, commands, buttons and queries to given `bot`.""" """Assign parsers, commands, buttons and queries to given `bot`."""
if talk_messages is None: if talk_messages is None:
@ -927,3 +946,15 @@ def init(telegram_bot, talk_messages=None, admin_messages=None):
authorization_level='admin') authorization_level='admin')
async def maintenance_command(bot, update, user_record): async def maintenance_command(bot, update, user_record):
return await _maintenance_command(bot, update, user_record) return await _maintenance_command(bot, update, user_record)
@telegram_bot.command(
command='/version',
aliases=[],
reply_keyboard_button=admin_messages['version_command']['reply_keyboard_button'],
show_in_keyboard=False,
description=admin_messages['version_command']['description'],
help_section=admin_messages['version_command']['help_section'],
authorization_level='admin',
)
async def version_command(bot, update, user_record):
return await _version_command(bot=bot, update=update, user_record=user_record)

View File

@ -235,6 +235,21 @@ default_admin_messages = {
'en': "<i>Maintenance ended!</i>", 'en': "<i>Maintenance ended!</i>",
'it': "<i>Manutenzione terminata!</i>" 'it': "<i>Manutenzione terminata!</i>"
} }
},
'version_command': {
'reply_keyboard_button': {
'en': "Version #️⃣",
'it': "Versione #️⃣",
},
'description': {
'en': "Get source code version",
'it': "Chiedi la versione del codice sorgente",
},
'help_section': None,
'result': {
'en': "Last commit: {version}",
'it': "Ultimo commit: {version}",
},
} }
} }