platforms.emoji_resolver module
Resolve custom emojis from Discord and Matrix into image Attachments.
Custom emojis are platform-specific rich content that arrives as text
tokens (Discord <:name:id>) or HTML <img> tags (Matrix). This
module extracts them from message text, downloads the images, and
returns Attachment objects so the LLM can
see the emojis as inline PNG images.
Both Discord and Matrix adapters call into these shared utilities from
their on_message handlers.
- class platforms.emoji_resolver.DiscordEmojiMatch(name, emoji_id, animated, full_match)[source]
Bases:
objectA single custom emoji found in Discord message text.
- platforms.emoji_resolver.extract_discord_emojis(text)[source]
Return unique custom emojis found in text, preserving order.
- Return type:
- Parameters:
text (str)
- platforms.emoji_resolver.rewrite_discord_emoji_text(text, matches)[source]
Replace every
<:name:id>token with[emoji: name].- Return type:
- Parameters:
text (str)
matches (list[DiscordEmojiMatch])
- async platforms.emoji_resolver.download_discord_emojis(matches, *, max_emojis=5, media_cache=None)[source]
Download up to max_emojis custom emojis in parallel.
Returns a list of successfully downloaded
Attachmentobjects. Failed downloads are silently skipped.- Return type:
- Parameters:
matches (list[DiscordEmojiMatch])
max_emojis (int)
media_cache (Any | None)
- class platforms.emoji_resolver.MatrixEmojiMatch(alt_text, mxc_url, full_tag)[source]
Bases:
objectA single custom emoji found in Matrix formatted_body HTML.
- platforms.emoji_resolver.extract_matrix_emojis(formatted_body)[source]
Return unique custom emojis found in Matrix formatted_body HTML.
- Return type:
- Parameters:
formatted_body (str)
- platforms.emoji_resolver.rewrite_matrix_emoji_text(body, matches)[source]
Replace Matrix emoji shortcodes in body with
[emoji: alt].Matrix clients typically put the shortcode (e.g.
:wave:) in the plain-text body. We strip the surrounding colons and wrap it in a descriptive bracket notation.- Return type:
- Parameters:
body (str)
matches (list[MatrixEmojiMatch])
- async platforms.emoji_resolver.download_matrix_emojis(matches, matrix_client, *, max_emojis=5, media_cache=None)[source]
Download up to max_emojis Matrix custom emojis in parallel.
Uses the matrix-nio
AsyncClient.download()method to fetch media from Matrix homeserver MXC URLs.- Return type:
- Parameters:
matches (list[MatrixEmojiMatch])
matrix_client (Any)
max_emojis (int)
media_cache (Any | None)