from pyrogram import Client from pyrogram.errors import FloodPremiumWait, FloodWait, RPCError from userbot.modules.capture.context import CaptureContext from userbot.modules.stt.service import TranscribeError, transcribe_message from utils.logging import logger async def safe_transcribe( client: Client, ctx: CaptureContext, chat_id: int, message_id: int ) -> None: try: await transcribe_message(client, ctx, chat_id, message_id) except (FloodWait, FloodPremiumWait): from userbot.modules.jobs.repository import enqueue # noqa: PLC0415 await enqueue( ctx.pool, ctx.account_id, "transcribe", {"chat_id": chat_id, "message_id": message_id}, ) except (TranscribeError, RPCError) as exc: logger.warning(f"[yellow]STT failed for {chat_id}/{message_id}: {exc}[/]")