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: object

A single custom emoji found in Discord message text.

Parameters:
name: str
emoji_id: str
animated: bool
full_match: str
platforms.emoji_resolver.extract_discord_emojis(text)[source]

Return unique custom emojis found in text, preserving order.

Return type:

list[DiscordEmojiMatch]

Parameters:

text (str)

platforms.emoji_resolver.rewrite_discord_emoji_text(text, matches)[source]

Replace every <:name:id> token with [emoji: name].

Return type:

str

Parameters:
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 Attachment objects. Failed downloads are silently skipped.

Return type:

list[Attachment]

Parameters:
class platforms.emoji_resolver.MatrixEmojiMatch(alt_text, mxc_url, full_tag)[source]

Bases: object

A single custom emoji found in Matrix formatted_body HTML.

Parameters:
  • alt_text (str)

  • mxc_url (str)

  • full_tag (str)

alt_text: str
mxc_url: str
full_tag: str
platforms.emoji_resolver.extract_matrix_emojis(formatted_body)[source]

Return unique custom emojis found in Matrix formatted_body HTML.

Return type:

list[MatrixEmojiMatch]

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:

str

Parameters:
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:

list[Attachment]

Parameters: