diff --git a/deploy/telegram-bridge/bridge.py b/deploy/telegram-bridge/bridge.py index 1a3ac0e..fe3f588 100644 --- a/deploy/telegram-bridge/bridge.py +++ b/deploy/telegram-bridge/bridge.py @@ -92,6 +92,34 @@ async def cmd_ping(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text(f"pong — webhook mode, tmux session «{TMUX_SESSION}»") +QUIET_FLAG = "/tmp/cc-tg-quiet" + + +async def cmd_quiet(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Заткнуть PreToolUse прогресс-ленту (Stop hook продолжает работать).""" + if not _allowed(update, context): + return + try: + open(QUIET_FLAG, "w").close() + await update.message.reply_text("🔕 Прогресс-лента отключена. Включить — /loud") + except Exception as exc: # noqa: BLE001 + await update.message.reply_text(f"⚠️ {exc}") + + +async def cmd_loud(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Включить обратно PreToolUse прогресс-ленту.""" + if not _allowed(update, context): + return + try: + os.unlink(QUIET_FLAG) + except FileNotFoundError: + pass + except Exception as exc: # noqa: BLE001 + await update.message.reply_text(f"⚠️ {exc}") + return + await update.message.reply_text("🔔 Прогресс-лента включена.") + + async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: if not _allowed(update, context): return @@ -130,6 +158,8 @@ def main() -> int: application = ApplicationBuilder().token(token).build() application.bot_data["chat_id"] = chat_id application.add_handler(CommandHandler("ping", cmd_ping)) + application.add_handler(CommandHandler("quiet", cmd_quiet)) + application.add_handler(CommandHandler("loud", cmd_loud)) application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message)) logger.info("starting webhook listener on %s:%d → %s", LISTEN_HOST, LISTEN_PORT, webhook_url)