fix: логирование Telegram listener + strip @botname из команд
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -351,7 +351,7 @@ def _start_telegram_listener(cfg, get_db_fn):
|
||||
def handle_command(text: str):
|
||||
# Resolve button text to command
|
||||
mapped = _button_map.get(text.strip().lower(), text.strip())
|
||||
cmd = mapped.split()[0].lower()
|
||||
cmd = mapped.split()[0].split("@")[0].lower() # strip @botname
|
||||
if cmd == "/status":
|
||||
conn = get_db_fn()
|
||||
report = format_status_report(cfg, conn)
|
||||
@@ -365,14 +365,18 @@ def _start_telegram_listener(cfg, get_db_fn):
|
||||
_send_help(cfg)
|
||||
|
||||
def poll_loop():
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
offset = 0
|
||||
base_url = f"https://api.telegram.org/bot{cfg.telegram.bot_token}"
|
||||
log.info("Telegram listener started")
|
||||
while True:
|
||||
try:
|
||||
resp = httpx.get(f"{base_url}/getUpdates",
|
||||
params={"offset": offset, "timeout": 30},
|
||||
timeout=35)
|
||||
if resp.status_code != 200:
|
||||
log.warning(f"Telegram poll: HTTP {resp.status_code}")
|
||||
time.sleep(5)
|
||||
continue
|
||||
updates = resp.json().get("result", [])
|
||||
@@ -382,8 +386,13 @@ def _start_telegram_listener(cfg, get_db_fn):
|
||||
text = msg.get("text", "")
|
||||
chat_id = str(msg.get("chat", {}).get("id", ""))
|
||||
if text and chat_id == cfg.telegram.chat_id:
|
||||
handle_command(text)
|
||||
except Exception:
|
||||
log.info(f"Telegram cmd: {text}")
|
||||
try:
|
||||
handle_command(text)
|
||||
except Exception as e:
|
||||
log.error(f"Telegram command error: {e}", exc_info=True)
|
||||
except Exception as e:
|
||||
log.error(f"Telegram poll error: {e}")
|
||||
time.sleep(10)
|
||||
|
||||
t = threading.Thread(target=poll_loop, daemon=True)
|
||||
|
||||
Reference in New Issue
Block a user