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()
|
f = await v.get_file()
|
||||||
with tempfile.NamedTemporaryFile(suffix=".ogg", delete=False) as tmp:
|
with tempfile.NamedTemporaryFile(suffix=".ogg", delete=False) as tmp:
|
||||||
path = tmp.name
|
path = tmp.name
|
||||||
|
note = await update.message.reply_text("🎧 слушаю…")
|
||||||
try:
|
try:
|
||||||
await f.download_to_drive(path)
|
await f.download_to_drive(path)
|
||||||
text = await asyncio.to_thread(voice.transcribe, path, CFG["whisper"])
|
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:
|
finally:
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
await note.delete()
|
||||||
if not text:
|
if not text:
|
||||||
await update.message.reply_text("Не расслышал, повтори?")
|
await update.message.reply_text("Не расслышал, повтори?")
|
||||||
return
|
return
|
||||||
@@ -299,6 +305,9 @@ def make_api() -> web.Application:
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
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())
|
runner = web.AppRunner(make_api())
|
||||||
await runner.setup()
|
await runner.setup()
|
||||||
await web.TCPSite(runner, CFG["api_bind"], CFG["api_port"]).start()
|
await web.TCPSite(runner, CFG["api_bind"], CFG["api_port"]).start()
|
||||||
@@ -311,6 +320,9 @@ async def main():
|
|||||||
if CFG["proxy"]:
|
if CFG["proxy"]:
|
||||||
builder = builder.proxy(CFG["proxy"]).get_updates_proxy(CFG["proxy"])
|
builder = builder.proxy(CFG["proxy"]).get_updates_proxy(CFG["proxy"])
|
||||||
tg = builder.build()
|
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("start", cmd_start))
|
||||||
tg.add_handler(CommandHandler("today", cmd_today))
|
tg.add_handler(CommandHandler("today", cmd_today))
|
||||||
tg.add_handler(CommandHandler("tasks", cmd_tasks))
|
tg.add_handler(CommandHandler("tasks", cmd_tasks))
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
python-telegram-bot[socks]==21.11.1
|
python-telegram-bot[socks]==21.11.1
|
||||||
aiohttp==3.11.18
|
aiohttp==3.11.18
|
||||||
faster-whisper==1.1.1
|
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
|
requests==2.32.3
|
||||||
|
|||||||
Reference in New Issue
Block a user