ops: fix voice (pin PyAV 13), keep the bot token out of the journal
- faster-whisper 1.1.1 calls av.open(metadata_errors=…), removed in PyAV 14+: pin av. - httpx logged every Telegram URL, which contains the bot token: silenced to WARNING (the VM journal was vacuumed). - Voice notes: «слушаю…» while transcribing, an answer on failure; an error handler for the bot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user