diff --git a/bin/run_bot.py b/bin/run_bot.py index a33422a..bba0b90 100644 --- a/bin/run_bot.py +++ b/bin/run_bot.py @@ -9,6 +9,7 @@ from pycamp_bot.commands import raffle from pycamp_bot.commands import schedule from pycamp_bot.commands import announcements +from pycamp_bot.commands import devtools from pycamp_bot.models import models_db_connection from pycamp_bot.logger import logger @@ -27,6 +28,7 @@ def set_handlers(application): raffle.set_handlers(application) schedule.set_handlers(application) announcements.set_handlers(application) + devtools.set_handlers(application) application.add_handler(MessageHandler(filters.COMMAND, unknown_command)) diff --git a/src/pycamp_bot/commands/devtools.py b/src/pycamp_bot/commands/devtools.py new file mode 100644 index 0000000..fc2a11c --- /dev/null +++ b/src/pycamp_bot/commands/devtools.py @@ -0,0 +1,46 @@ +import subprocess +import sys + +from telegram.ext import CommandHandler + +from pycamp_bot.utils import escape_markdown + + +async def show_version(update, context): + """Let people see the details about what is being run and how""" + + git_rev_parse = subprocess.run(['git', 'rev-parse', '--short', 'HEAD'], capture_output=True, check=True) + commit = git_rev_parse.stdout.decode().rstrip() + + git_log = subprocess.run(['git', 'log', '--max-count=1', '--pretty=format:%ai'], capture_output=True, check=True) + author_date = git_log.stdout.decode().rstrip() + + git_diff = subprocess.run(['git', 'diff', '--quiet'], capture_output=True) + if git_diff.returncode == 0: + clean_worktree = '🟢' + else: + clean_worktree = '🔴' + + python_version = '.'.join(str(component) for component in sys.version_info[:3]) + + pip_freeze = subprocess.run(['pip', 'freeze', '--exclude', 'PyCamp_Bot'], capture_output=True, check=True) + dependencies = [] + for pip_line in pip_freeze.stdout.decode().splitlines(): + dependencies.append(escape_markdown(pip_line)) + + lines = [ + f'Commit deployado: `{commit}`', + f'Fecha del commit \\(author date\\): `{escape_markdown(author_date)}`', + f'Clean worktree: {clean_worktree}', + f'Versión de Python: `{python_version}`', + 'Dependencias:', + '```', + *dependencies, + '```', + ] + + await update.message.reply_text('\n'.join(lines), parse_mode='MarkdownV2') + + +def set_handlers(application): + application.add_handler(CommandHandler('mostrar_version', show_version)) diff --git a/src/pycamp_bot/commands/help_msg.py b/src/pycamp_bot/commands/help_msg.py index d2cffe1..2d19f18 100644 --- a/src/pycamp_bot/commands/help_msg.py +++ b/src/pycamp_bot/commands/help_msg.py @@ -16,6 +16,7 @@ /anunciar: te pide el nombre de un proyecto y pingea por privado a les \ interesades avisando que esta por empezar (solo para admins u owners del proyecto). /su (passwrd): convierte al usuario en admin. Si sabe el password :P +/mostrar_version: te muestra qué versión del bot está corriendo y otros detalles /admins: lista a todos los admins. /ayuda: esta ayuda.'''