1
0
Fork 0

d->m bridge emojis in messages

This commit is contained in:
Cadence Ember 2023-09-19 17:43:57 +12:00
parent 94c4b6a262
commit 1657de4eef
5 changed files with 104 additions and 4 deletions

View file

@ -41,8 +41,12 @@ function getDiscordParseCallbacks(message, useHTML) {
/** @param {{animated: boolean, name: string, id: string, type: "discordEmoji"}} node */ /** @param {{animated: boolean, name: string, id: string, type: "discordEmoji"}} node */
emoji: node => { emoji: node => {
if (useHTML) { if (useHTML) {
// TODO: upload the emoji and actually use the right mxc!! const mxc = select("emoji", "mxc_url", "WHERE emoji_id = ?").pluck().get(node.id)
if (mxc) {
return `<img data-mx-emoticon height="32" src="${mxc}" title=":${node.name}:" alt=":${node.name}:">`
} else {
return `<img src="mxc://cadence.moe/${node.id}" data-mx-emoticon alt=":${node.name}:" title=":${node.name}:" height="24">` return `<img src="mxc://cadence.moe/${node.id}" data-mx-emoticon alt=":${node.name}:" title=":${node.name}:" height="24">`
}
} else { } else {
return `:${node.name}:` return `:${node.name}:`
} }

View file

@ -379,3 +379,27 @@ test("message2event: thread start message reference", async t => {
"m.mentions": {} "m.mentions": {}
}]) }])
}) })
test("message2event: single large bridged emoji", async t => {
const events = await messageToEvent(data.message.single_emoji, data.guild.general, {})
t.deepEqual(events, [{
$type: "m.room.message",
"m.mentions": {},
msgtype: "m.text",
body: ":hippo:",
format: "org.matrix.custom.html",
formatted_body: '<img data-mx-emoticon height="32" src="mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC" title=":hippo:" alt=":hippo:">'
}])
})
test("message2event: mid-message small bridged emoji", async t => {
const events = await messageToEvent(data.message.surrounded_emoji, data.guild.general, {})
t.deepEqual(events, [{
$type: "m.room.message",
"m.mentions": {},
msgtype: "m.text",
body: "h is for :hippo:!",
format: "org.matrix.custom.html",
formatted_body: 'h is for <img data-mx-emoticon height="32" src="mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC" title=":hippo:" alt=":hippo:">!'
}])
})

View file

@ -66,7 +66,11 @@ INSERT INTO file (discord_url, mxc_url) VALUES
('https://cdn.discordapp.com/attachments/112760669178241024/1128084851023675515/RDT_20230704_0936184915846675925224905.jpg', 'mxc://cadence.moe/WlAbFSiNRIHPDEwKdyPeGywa'), ('https://cdn.discordapp.com/attachments/112760669178241024/1128084851023675515/RDT_20230704_0936184915846675925224905.jpg', 'mxc://cadence.moe/WlAbFSiNRIHPDEwKdyPeGywa'),
('https://cdn.discordapp.com/guilds/112760669178241024/users/134826546694193153/avatars/38dd359aa12bcd52dd3164126c587f8c.png?size=1024', 'mxc://cadence.moe/rfemHmAtcprjLEiPiEuzPhpl'), ('https://cdn.discordapp.com/guilds/112760669178241024/users/134826546694193153/avatars/38dd359aa12bcd52dd3164126c587f8c.png?size=1024', 'mxc://cadence.moe/rfemHmAtcprjLEiPiEuzPhpl'),
('https://cdn.discordapp.com/icons/112760669178241024/a_f83622e09ead74f0c5c527fe241f8f8c.png?size=1024', 'mxc://cadence.moe/zKXGZhmImMHuGQZWJEFKJbsF'), ('https://cdn.discordapp.com/icons/112760669178241024/a_f83622e09ead74f0c5c527fe241f8f8c.png?size=1024', 'mxc://cadence.moe/zKXGZhmImMHuGQZWJEFKJbsF'),
('https://cdn.discordapp.com/avatars/113340068197859328/b48302623a12bc7c59a71328f72ccb39.png?size=1024', 'mxc://cadence.moe/UpAeIqeclhKfeiZNdIWNcXXL'); ('https://cdn.discordapp.com/avatars/113340068197859328/b48302623a12bc7c59a71328f72ccb39.png?size=1024', 'mxc://cadence.moe/UpAeIqeclhKfeiZNdIWNcXXL'),
('https://cdn.discordapp.com/emojis/230201364309868544.png', 'mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC');
INSERT INTO emoji (emoji_id, animated, mxc_url) VALUES
('230201364309868544', 0, 'mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC');
INSERT INTO member_cache (room_id, mxid, displayname, avatar_url) VALUES INSERT INTO member_cache (room_id, mxid, displayname, avatar_url) VALUES
('!kLRqKKUQXcibIMtOpl:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', NULL), ('!kLRqKKUQXcibIMtOpl:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', NULL),

6
db/orm-utils.d.ts vendored
View file

@ -62,6 +62,12 @@ export type Models = {
webhook_id: string webhook_id: string
webhook_token: string webhook_token: string
} }
emoji: {
emoji_id: string
animated: number
mxc_url: string
}
} }
export type Prepared<Row> = { export type Prepared<Row> = {

View file

@ -958,7 +958,69 @@ module.exports = {
}, },
attachments: [], attachments: [],
guild_id: "112760669178241024" guild_id: "112760669178241024"
} },
single_emoji: {
id: "1126733830494093453",
type: 0,
content: "<:hippo:230201364309868544>",
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: []
},
surrounded_emoji: {
id: "1126733830494093453",
type: 0,
content: "h is for <:hippo:230201364309868544>!",
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: []
},
}, },
message_with_embeds: { message_with_embeds: {
nothing_but_a_field: { nothing_but_a_field: {