diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js index 2984e8e1..6b762b41 100644 --- a/m2d/converters/event-to-message.js +++ b/m2d/converters/event-to-message.js @@ -206,11 +206,10 @@ function getCodeContent(preCode) { */ function convertEmoji(mxcUrl, nameForGuess, allowSpriteSheetIndicator, allowLink) { // Get the known emoji from the database. - let row - if (mxcUrl) row = select("emoji", ["emoji_id", "name", "animated"], {mxc_url: mxcUrl}).get() + if (mxcUrl) var row = select("emoji", ["emoji_id", "name", "animated"], {mxc_url: mxcUrl}).get() // Now we have to search all servers to see if we're able to send this emoji. if (row) { - const found = [...discord.guilds.values()].find(g => g.emojis.find(e => e.id === row.id)) + const found = [...discord.guilds.values()].find(g => g.emojis.find(e => e.id === row?.emoji_id)) if (!found) row = null } // Or, if we don't have an emoji right now, we search for the name instead. @@ -220,7 +219,7 @@ function convertEmoji(mxcUrl, nameForGuess, allowSpriteSheetIndicator, allowLink /** @type {{name: string, id: string, animated: number}[]} */ // @ts-ignore const emojis = guild.emojis - const found = emojis.find(e => e.id === row?.id || e.name?.toLowerCase() === nameForGuessLower) + const found = emojis.find(e => e.name?.toLowerCase() === nameForGuessLower) if (found) { row = { animated: found.animated, diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js index b404e59f..a802d288 100644 --- a/m2d/converters/event-to-message.test.js +++ b/m2d/converters/event-to-message.test.js @@ -3794,6 +3794,36 @@ test("event2message: static emojis work", async t => { ) }) +test("event2message: emojis in other servers are reused if they have the same title text", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: ":hippo:", + format: "org.matrix.custom.html", + formatted_body: '\":hippo:\"' + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + room_id: "!CzvdIdUQXgUjDVKxeU:cadence.moe" + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "<:hippo:230201364309868544>", + avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: animated emojis work", async t => { t.deepEqual( await eventToMessage({