Skip to content

Commit 36254ec

Browse files
committed
feat: add Telegram bot command menu with start, disk space and torrent list options
1 parent 7280f79 commit 36254ec

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import time
33
import os
44
import threading
5+
import requests
56
from dotenv import load_dotenv
7+
from telegram_utils import send_telegram, process_messages, set_bot_commands
68

79
# Carrega as variáveis de ambiente
810
load_dotenv()
@@ -24,6 +26,8 @@
2426
QBITTORRENT_AVAILABLE = False
2527

2628
def main():
29+
# Atualiza o menu de comandos do bot no Telegram
30+
set_bot_commands()
2731
# Inicializa a sessão do qBittorrent se disponível
2832
sess = None
2933
if QBITTORRENT_AVAILABLE:

telegram_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
TELEGRAM_CHAT_ID = os.getenv('TELEGRAM_CHAT_ID')
1313
AUTHORIZED_USERS = [uid.strip() for uid in os.getenv('AUTHORIZED_USERS', '').split(',') if uid.strip()]
1414

15+
def set_bot_commands():
16+
"""
17+
Define os comandos do menu do bot no Telegram.
18+
"""
19+
commands = [
20+
{"command": "start", "description": "Iniciar o bot"},
21+
{"command": "qespaco", "description": "Mostrar espaço em disco"},
22+
{"command": "qtorrents", "description": "Listar torrents"},
23+
]
24+
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/setMyCommands"
25+
try:
26+
resp = requests.post(url, json={"commands": commands}, timeout=10)
27+
resp.raise_for_status()
28+
print("Comandos do bot registrados com sucesso no Telegram.")
29+
except Exception as e:
30+
print(f"Erro ao registrar comandos do bot: {e}")
31+
1532
def send_telegram(msg: str, chat_id: Optional[Union[str, int]] = None, parse_mode: str = "HTML") -> bool:
1633
"""
1734
Envia uma mensagem para o Telegram.

0 commit comments

Comments
 (0)