Convert emojihax to real emoji
This commit is contained in:
@@ -757,6 +757,11 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||
}
|
||||
}
|
||||
|
||||
// Scan the content for emojihax and replace them with real emojis
|
||||
content = content.replaceAll(/\[([a-zA-Z0-9_-]{2,32})(?:~[0-9]+)?\]\(https:\/\/cdn\.discordapp\.com\/emojis\/([0-9]+)\.[^ \n)`]+\)/g, (_, name, id) => {
|
||||
return `<:${name}:${id}>`
|
||||
})
|
||||
|
||||
const {body, html} = await transformContent(content)
|
||||
await addTextEvent(body, html, msgtype)
|
||||
}
|
||||
|
||||
@@ -1171,6 +1171,18 @@ test("message2event: emoji that hasn't been registered yet", async t => {
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: emojihax", async t => {
|
||||
const events = await messageToEvent(data.message.emojihax, data.guild.general, {})
|
||||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
"m.mentions": {},
|
||||
msgtype: "m.text",
|
||||
body: "I only violate the don't modify our console part of terms of service :troll:",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `I only violate the don't modify our console part of terms of service <img data-mx-emoticon height="32" src="mxc://cadence.moe/bvVJFgOIyNcAknKCbmaHDktG" title=":troll:" alt=":troll:">`
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: emoji triple long name", async t => {
|
||||
const events = await messageToEvent(data.message.emoji_triple_long_name, data.guild.general, {})
|
||||
t.deepEqual(events, [{
|
||||
|
||||
31
test/data.js
31
test/data.js
@@ -3219,6 +3219,37 @@ module.exports = {
|
||||
flags: 0,
|
||||
components: []
|
||||
},
|
||||
emojihax: {
|
||||
id: "1126733830494093453",
|
||||
type: 0,
|
||||
content: "I only violate the don't modify our console part of terms of service [troll~1](https://cdn.discordapp.com/emojis/1254940125948022915.webp?size=48&name=troll%7E1&lossless=true)",
|
||||
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: null,
|
||||
display_name: "KyuuGryphon",
|
||||
banner_color: null
|
||||
},
|
||||
attachments: [],
|
||||
embeds: [],
|
||||
mentions: [],
|
||||
mention_roles: [],
|
||||
pinned: false,
|
||||
mention_everyone: false,
|
||||
tts: false,
|
||||
timestamp: "2023-07-07T04:37:58.892000+00:00",
|
||||
edited_timestamp: null,
|
||||
flags: 0,
|
||||
components: []
|
||||
},
|
||||
emoji_triple_long_name: {
|
||||
id: "1156394116540805170",
|
||||
type: 0,
|
||||
|
||||
@@ -152,7 +152,8 @@ INSERT INTO file (discord_url, mxc_url) VALUES
|
||||
('https://cdn.discordapp.com/attachments/1099031887500034088/1112476845502365786/voice-message.ogg', 'mxc://cadence.moe/MRRPDggXQMYkrUjTpxQbmcxB'),
|
||||
('https://cdn.discordapp.com/attachments/122155380120748034/1174514575220158545/the.yml', 'mxc://cadence.moe/HnQIYQmmlIKwOQsbFsIGpzPP'),
|
||||
('https://cdn.discordapp.com/attachments/112760669178241024/1296237494987133070/100km.gif', 'mxc://cadence.moe/qDAotmebTfEIfsAIVCEZptLh'),
|
||||
('https://cdn.discordapp.com/attachments/123/456/my_enemies.txt', 'mxc://cadence.moe/y89EOTRp2lbeOkgdsEleGOge');
|
||||
('https://cdn.discordapp.com/attachments/123/456/my_enemies.txt', 'mxc://cadence.moe/y89EOTRp2lbeOkgdsEleGOge'),
|
||||
('https://cdn.discordapp.com/emojis/1254940125948022915.webp', 'mxc://cadence.moe/bvVJFgOIyNcAknKCbmaHDktG');
|
||||
|
||||
INSERT INTO emoji (emoji_id, name, animated, mxc_url) VALUES
|
||||
('230201364309868544', 'hippo', 0, 'mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC'),
|
||||
|
||||
Reference in New Issue
Block a user