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,4 +1,3 @@
from io import BytesIO
from typing import Any
from pyrogram import Client
@@ -6,6 +5,8 @@ from pyrogram.types import Message
from userbot.modules.capture import repository
from userbot.modules.capture.context import CaptureContext
from userbot.modules.download import download_bytes
from utils.logging import logger
from utils.policy.models import CaptureToggles
_MEDIA_ATTRS = (
@@ -80,9 +81,14 @@ async def capture_media( # noqa: PLR0913
downloaded = True
else:
target = message if getattr(message, kind or "", None) is obj else obj
buffer = await client.download_media(target, in_memory=True)
if isinstance(buffer, BytesIO):
data = buffer.getvalue()
try:
data = await download_bytes(client, target)
except TimeoutError:
logger.warning(
f"[yellow]Media download timed out for {chat_id}/{message_id}.[/]"
)
data = None
if data is not None:
storage_key = ctx.storage.put(data)
file_size = len(data)
downloaded = True