diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py
index 78b2544..ada1f54 100644
--- a/davtelepot/__init__.py
+++ b/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.4.6"
+__version__ = "2.4.7"
__maintainer__ = "Davide Testa"
__contact__ = "t.me/davte"
diff --git a/davtelepot/administration_tools.py b/davtelepot/administration_tools.py
index 44d266f..82d7df2 100644
--- a/davtelepot/administration_tools.py
+++ b/davtelepot/administration_tools.py
@@ -778,6 +778,25 @@ def get_maintenance_exception_criterion(bot, allowed_command):
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):
"""Assign parsers, commands, buttons and queries to given `bot`."""
if talk_messages is None:
@@ -927,3 +946,15 @@ def init(telegram_bot, talk_messages=None, admin_messages=None):
authorization_level='admin')
async def 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)
diff --git a/davtelepot/messages.py b/davtelepot/messages.py
index e481643..7d3638a 100644
--- a/davtelepot/messages.py
+++ b/davtelepot/messages.py
@@ -235,6 +235,21 @@ default_admin_messages = {
'en': "Maintenance ended!",
'it': "Manutenzione terminata!"
}
+ },
+ '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}",
+ },
}
}