From ca988af2e0ea5a1654f1ae842de599527a38b9f6 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 27 Sep 2023 23:24:31 +1300 Subject: [PATCH] d->m accept emojis with longer names --- d2m/converters/message-to-event.js | 2 +- d2m/converters/message-to-event.test.js | 15 +++++++++++++ db/ooye-test-data.sql | 6 +++-- test/data.js | 30 +++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/d2m/converters/message-to-event.js b/d2m/converters/message-to-event.js index 15eaf344..69d1619d 100644 --- a/d2m/converters/message-to-event.js +++ b/d2m/converters/message-to-event.js @@ -158,7 +158,7 @@ async function messageToEvent(message, guild, options = {}, di) { // Handling emojis that we don't know about. The emoji has to be present in the DB for it to be picked up in the emoji markdown converter. // So we scan the message ahead of time for all its emojis and ensure they are in the DB. - const emojiMatches = [...content.matchAll(/<(a?):([^:>]{2,20}):([0-9]+)>/g)] + const emojiMatches = [...content.matchAll(/<(a?):([^:>]{2,64}):([0-9]+)>/g)] const emojiDownloads = [] for (const match of emojiMatches) { const id = match[3] diff --git a/d2m/converters/message-to-event.test.js b/d2m/converters/message-to-event.test.js index c09708dc..34f376fa 100644 --- a/d2m/converters/message-to-event.test.js +++ b/d2m/converters/message-to-event.test.js @@ -403,3 +403,18 @@ test("message2event: mid-message small bridged emoji", async t => { formatted_body: 'h is for :hippo:!' }]) }) + +test("message2event: emoji triple long name", async t => { + const events = await messageToEvent(data.message.emoji_triple_long_name, data.guild.general, {}) + t.deepEqual(events, [{ + $type: "m.room.message", + "m.mentions": {}, + msgtype: "m.text", + body: ":brillillillilliant_move::brillillillilliant_move::brillillillilliant_move:", + format: "org.matrix.custom.html", + formatted_body: + ':brillillillilliant_move:' + + ':brillillillilliant_move:' + + ':brillillillilliant_move:' + }]) +}) diff --git a/db/ooye-test-data.sql b/db/ooye-test-data.sql index 68c6d000..2a563819 100644 --- a/db/ooye-test-data.sql +++ b/db/ooye-test-data.sql @@ -74,12 +74,14 @@ INSERT INTO emoji (id, name, animated, mxc_url) VALUES ('230201364309868544', 'hippo', 0, 'mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC'), ('393635038903926784', 'hipposcope', 1, 'mxc://cadence.moe/WbYqNlACRuicynBfdnPYtmvc'), ('362741439211503616', 'bn_re', 0, 'mxc://cadence.moe/OIpqpfxTnHKokcsYqDusxkBT'), -('551636841284108289', 'ae_botrac4r', 0, 'mxc://cadence.moe/skqfuItqxNmBYekzmVKyoLzs'); +('551636841284108289', 'ae_botrac4r', 0, 'mxc://cadence.moe/skqfuItqxNmBYekzmVKyoLzs'), +('975572106295259148', 'brillillillilliant_move', 0, 'mxc://cadence.moe/scfRIDOGKWFDEBjVXocWYQHik'); INSERT INTO member_cache (room_id, mxid, displayname, avatar_url) VALUES ('!kLRqKKUQXcibIMtOpl:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', NULL), ('!BpMdOUkWWhFxmTrENV:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'malformed mxc'), ('!fGgIymcYWOqjbSRUdV:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'), -('!PnyBKvUBOhjuCucEfk:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'); +('!PnyBKvUBOhjuCucEfk:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'), +('!maggESguZBqGBZtSnr:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'); COMMIT; diff --git a/test/data.js b/test/data.js index a0e59d36..8cfa7174 100644 --- a/test/data.js +++ b/test/data.js @@ -1038,6 +1038,36 @@ module.exports = { flags: 0, components: [] }, + emoji_triple_long_name: { + id: "1156394116540805170", + type: 0, + content: "<:brillillillilliant_move:975572106295259148><:brillillillilliant_move:975572106295259148><:brillillillilliant_move:975572106295259148>", + channel_id: "112760669178241024", + author: { + id: "111604486476181504", + username: "kyuugryphon", + avatar: "e4ce31267ca524d19be80e684d4cafa1", + discriminator: "0", + public_flags: 0, + flags: 0, + banner: null, + accent_color: null, + global_name: "KyuuGryphon", + avatar_decoration_data: null, + banner_color: null + }, + attachments: [], + embeds: [], + mentions: [], + mention_roles: [], + pinned: false, + mention_everyone: false, + tts: false, + timestamp: "2023-09-27T00:57:22.147000+00:00", + edited_timestamp: null, + flags: 0, + components: [] + } }, message_with_embeds: { nothing_but_a_field: {