diff --git a/d2m/actions/add-reaction.js b/d2m/actions/add-reaction.js index bbce42d..068962b 100644 --- a/d2m/actions/add-reaction.js +++ b/d2m/actions/add-reaction.js @@ -50,7 +50,8 @@ async function addReaction(data) { rel_type: "m.annotation", event_id: parentID, key - } + }, + shortcode: `:${data.emoji.name}:` }, senderMxid) return eventID } diff --git a/m2d/actions/add-reaction.js b/m2d/actions/add-reaction.js index a9e36c3..7cfbc61 100644 --- a/m2d/actions/add-reaction.js +++ b/m2d/actions/add-reaction.js @@ -21,16 +21,19 @@ async function addReaction(event) { let discordPreferredEncoding if (emoji.startsWith("mxc://")) { // Custom emoji - const row = select("emoji", ["id", "name"], "WHERE mxc_url = ?").get(emoji) - if (row) { - // Great, we know exactly what this emoji is! - discordPreferredEncoding = encodeURIComponent(`${row.name}:${row.id}`) - } else { + let row = select("emoji", ["id", "name"], "WHERE mxc_url = ?").get(emoji) + if (!row && event.content.shortcode) { + // Use the name to try to find a known emoji with the same name. + const name = event.content.shortcode.replace(/^:|:$/g, "") + row = select("emoji", ["id", "name"], "WHERE name = ?").get(name) + } + if (!row) { // We don't have this emoji and there's no realistic way to just-in-time upload a new emoji somewhere. - // We can't try using a known emoji with the same name because we don't even know what the name is. We only have the mxc url. // Sucks! return } + // Cool, we got an exact or a candidate emoji. + discordPreferredEncoding = encodeURIComponent(`${row.name}:${row.id}`) } else { // Default emoji // https://github.com/discord/discord-api-docs/issues/2723#issuecomment-807022205 ???????????? diff --git a/types.d.ts b/types.d.ts index db72eb3..3b4aacd 100644 --- a/types.d.ts +++ b/types.d.ts @@ -171,7 +171,8 @@ export namespace Event { rel_type: "m.annotation" event_id: string // the event that was reacted to key: string // the unicode emoji, mxc uri, or reaction text - } + }, + "shortcode"?: string // starts and ends with colons } export type Outer_M_Room_Redaction = Outer<{