fix(userbot): drop stale media sessions and survive download timeouts

This commit is contained in:
hh committed 2026-09-01 21:05:48 +02:00
1 parent cf277c56cf
commit 9c12628304
6 files changed
+83 -24

No files matched your search

@@ -1,9 +1,9 @@
from io import BytesIO
from pyrogram import Client
from userbot.modules.avatars import repository
from userbot.modules.capture.context import CaptureContext
from userbot.modules.download import download_bytes
from utils.logging import logger
async def capture_avatar( # noqa: PLR0913
@@ -20,9 +20,12 @@ async def capture_avatar( # noqa: PLR0913
storage_key: str | None = None
file_size: int | None = None
downloaded = False
buffer = await client.download_media(file_id, in_memory=True)
if isinstance(buffer, BytesIO):
data = buffer.getvalue()
try:
data = await download_bytes(client, file_id)
except TimeoutError:
logger.warning(f"[yellow]Avatar download timed out for {owner_id}.[/]")
data = None
if data is not None:
storage_key = ctx.storage.put(data)
file_size = len(data)
downloaded = True