platforms.embed_media_resolver module

Resolve Discord embed images and stickers into first-class attachments.

Embed images (link previews, other bots’ rich embeds, crossposts) and stickers historically reached the pipeline as text only — a serialized <image>URL</image> line or [Sticker: name] label — so whether the model ever saw the pixels depended on a downstream URL regex that cannot match extension-less og:image links and never fires for stickers. This module downloads those assets at the gateway, exactly like attachments, so the bytes travel in the inbound envelope.

Mirrors platforms.emoji_resolver: candidate extraction is pure and separately testable; downloads go through the media cache when available.

platforms.embed_media_resolver.embed_image_candidates(message)

(download_url, origin_url) pairs for a message’s embed images.

Prefers each embed’s full image over its thumbnail (an embed can carry both for the same asset) and the Discord media-proxy URL over the origin (the proxy is cached, CORS-friendly, and carries a fresh signature for re-embedded CDN attachments). The gateway is the single owner of every embed image — including ones whose URL is pasted verbatim in the message text — because serialize_embed tags them as <image>URL</image> and the inference-side extractor skips tagged URLs; skipping here too would mean NOBODY fetches the image. Deduplicates across embeds, including forwarded-snapshot embeds.

Return type:

list[tuple[str, str]]

Parameters:

message (Any)

platforms.embed_media_resolver.sticker_candidates(message)

(url, mimetype, filename) for a message’s raster stickers.

Includes forwarded-snapshot stickers; skips lottie (vector JSON).

Return type:

list[tuple[str, str, str]]

Parameters:

message (Any)

async platforms.embed_media_resolver.collect_embed_images(message, *, max_images=4, media_cache=None, session=None)

Download up to max_images embed images as attachments.

session is an optional shared aiohttp.ClientSession to fetch through; it is only forwarded when non-None so that callers (and tests) which stub _download_image with the historical signature keep working unchanged.

Return type:

list[Attachment]

Parameters:
  • message (Any)

  • max_images (int)

  • media_cache (Any | None)

  • session (Any | None)

async platforms.embed_media_resolver.collect_sticker_images(message, *, max_stickers=3, media_cache=None, session=None)

Download up to max_stickers raster stickers as attachments.

session is forwarded only when non-None — see collect_embed_images().

Return type:

list[Attachment]

Parameters:
  • message (Any)

  • max_stickers (int)

  • media_cache (Any | None)

  • session (Any | None)