diff --git a/ops/brovops/app.py b/ops/brovops/app.py index e7309f7..36835cc 100644 --- a/ops/brovops/app.py +++ b/ops/brovops/app.py @@ -148,11 +148,17 @@ async def on_voice(update: Update, ctx): f = await v.get_file() with tempfile.NamedTemporaryFile(suffix=".ogg", delete=False) as tmp: path = tmp.name + note = await update.message.reply_text("🎧 слушаю…") try: await f.download_to_drive(path) text = await asyncio.to_thread(voice.transcribe, path, CFG["whisper"]) + except Exception as e: + log.exception("voice") + await note.edit_text(f"Не смог распознать голосовое: {e.__class__.__name__}. Напиши текстом?") + return finally: os.unlink(path) + await note.delete() if not text: await update.message.reply_text("Не расслышал, повтори?") return @@ -299,6 +305,9 @@ def make_api() -> web.Application: async def main(): logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s") + # httpx logs every request URL, and Telegram URLs carry the bot token. + logging.getLogger("httpx").setLevel(logging.WARNING) + logging.getLogger("httpx2").setLevel(logging.WARNING) runner = web.AppRunner(make_api()) await runner.setup() await web.TCPSite(runner, CFG["api_bind"], CFG["api_port"]).start() @@ -311,6 +320,9 @@ async def main(): if CFG["proxy"]: builder = builder.proxy(CFG["proxy"]).get_updates_proxy(CFG["proxy"]) tg = builder.build() + async def on_error(update, ctx): + log.error("handler failed", exc_info=ctx.error) + tg.add_error_handler(on_error) tg.add_handler(CommandHandler("start", cmd_start)) tg.add_handler(CommandHandler("today", cmd_today)) tg.add_handler(CommandHandler("tasks", cmd_tasks)) diff --git a/ops/requirements.txt b/ops/requirements.txt index ec80d49..ae87f78 100644 --- a/ops/requirements.txt +++ b/ops/requirements.txt @@ -1,4 +1,6 @@ python-telegram-bot[socks]==21.11.1 aiohttp==3.11.18 faster-whisper==1.1.1 +# faster-whisper 1.1.1 passes metadata_errors to av.open, removed in PyAV 14+. +av==13.1.0 requests==2.32.3