Skip to content

Commit

Permalink
Add show_version command
Browse files Browse the repository at this point in the history
  • Loading branch information
andresdelfino committed Jun 22, 2024
1 parent 68e8094 commit cad33b7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/run_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))


Expand Down
46 changes: 46 additions & 0 deletions src/pycamp_bot/commands/devtools.py
Original file line number Diff line number Diff line change
@@ -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))
1 change: 1 addition & 0 deletions src/pycamp_bot/commands/help_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'''

Expand Down

0 comments on commit cad33b7

Please sign in to comment.