Skip to content

Commit cad33b7

Browse files
committed
Add show_version command
1 parent 68e8094 commit cad33b7

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

bin/run_bot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pycamp_bot.commands import raffle
1010
from pycamp_bot.commands import schedule
1111
from pycamp_bot.commands import announcements
12+
from pycamp_bot.commands import devtools
1213
from pycamp_bot.models import models_db_connection
1314
from pycamp_bot.logger import logger
1415

@@ -27,6 +28,7 @@ def set_handlers(application):
2728
raffle.set_handlers(application)
2829
schedule.set_handlers(application)
2930
announcements.set_handlers(application)
31+
devtools.set_handlers(application)
3032
application.add_handler(MessageHandler(filters.COMMAND, unknown_command))
3133

3234

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import subprocess
2+
import sys
3+
4+
from telegram.ext import CommandHandler
5+
6+
from pycamp_bot.utils import escape_markdown
7+
8+
9+
async def show_version(update, context):
10+
"""Let people see the details about what is being run and how"""
11+
12+
git_rev_parse = subprocess.run(['git', 'rev-parse', '--short', 'HEAD'], capture_output=True, check=True)
13+
commit = git_rev_parse.stdout.decode().rstrip()
14+
15+
git_log = subprocess.run(['git', 'log', '--max-count=1', '--pretty=format:%ai'], capture_output=True, check=True)
16+
author_date = git_log.stdout.decode().rstrip()
17+
18+
git_diff = subprocess.run(['git', 'diff', '--quiet'], capture_output=True)
19+
if git_diff.returncode == 0:
20+
clean_worktree = '🟢'
21+
else:
22+
clean_worktree = '🔴'
23+
24+
python_version = '.'.join(str(component) for component in sys.version_info[:3])
25+
26+
pip_freeze = subprocess.run(['pip', 'freeze', '--exclude', 'PyCamp_Bot'], capture_output=True, check=True)
27+
dependencies = []
28+
for pip_line in pip_freeze.stdout.decode().splitlines():
29+
dependencies.append(escape_markdown(pip_line))
30+
31+
lines = [
32+
f'Commit deployado: `{commit}`',
33+
f'Fecha del commit \\(author date\\): `{escape_markdown(author_date)}`',
34+
f'Clean worktree: {clean_worktree}',
35+
f'Versión de Python: `{python_version}`',
36+
'Dependencias:',
37+
'```',
38+
*dependencies,
39+
'```',
40+
]
41+
42+
await update.message.reply_text('\n'.join(lines), parse_mode='MarkdownV2')
43+
44+
45+
def set_handlers(application):
46+
application.add_handler(CommandHandler('mostrar_version', show_version))

src/pycamp_bot/commands/help_msg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/anunciar: te pide el nombre de un proyecto y pingea por privado a les \
1717
interesades avisando que esta por empezar (solo para admins u owners del proyecto).
1818
/su (passwrd): convierte al usuario en admin. Si sabe el password :P
19+
/mostrar_version: te muestra qué versión del bot está corriendo y otros detalles
1920
/admins: lista a todos los admins.
2021
/ayuda: esta ayuda.'''
2122

0 commit comments

Comments
 (0)