Compare commits
No commits in common. "5002f3046a0b23f77405080f65f8e22c55269565" and "c971ca3e3d6c1dea88fdc48ce10e787cbdb67a86" have entirely different histories.
5002f3046a
...
c971ca3e3d
5 changed files with 58 additions and 114 deletions
|
|
@ -247,20 +247,6 @@ async function pollToEvent(poll) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {DiscordTypes.APIMessageInteraction} interaction
|
|
||||||
* @param {boolean} isThinkingInteraction
|
|
||||||
*/
|
|
||||||
function getFormattedInteraction(interaction, isThinkingInteraction) {
|
|
||||||
const mxid = select("sim", "mxid", {user_id: interaction.user.id}).pluck().get()
|
|
||||||
const username = interaction.member?.nick || interaction.user.global_name || interaction.user.username
|
|
||||||
const thinkingText = isThinkingInteraction ? " — interaction loading..." : ""
|
|
||||||
return {
|
|
||||||
body: `↪️ ${username} used \`/${interaction.name}\`${thinkingText}`,
|
|
||||||
html: `<blockquote><sub>↪️ ${mxid ? tag`<a href="https://matrix.to/#/${mxid}">${username}</a>` : username} used <code>/${interaction.name}</code>${thinkingText}</sub></blockquote>`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {DiscordTypes.APIMessage} message
|
* @param {DiscordTypes.APIMessage} message
|
||||||
* @param {DiscordTypes.APIGuild} guild
|
* @param {DiscordTypes.APIGuild} guild
|
||||||
|
|
@ -335,8 +321,13 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const interaction = message.interaction_metadata || message.interaction
|
const interaction = message.interaction_metadata || message.interaction
|
||||||
const isInteraction = message.type === DiscordTypes.MessageType.ChatInputCommand && !!interaction && "name" in interaction
|
if (message.type === DiscordTypes.MessageType.ChatInputCommand && interaction && "name" in interaction) {
|
||||||
const isThinkingInteraction = isInteraction && !!((message.flags || 0) & DiscordTypes.MessageFlags.Loading)
|
// Commands are sent by the responding bot. Need to attach the metadata of the person using the command at the top.
|
||||||
|
let content = message.content
|
||||||
|
if (content) content = `\n${content}`
|
||||||
|
else if ((message.flags || 0) & DiscordTypes.MessageFlags.Loading) content = " — interaction loading..."
|
||||||
|
message.content = `> ↪️ <@${interaction.user.id}> used \`/${interaction.name}\`${content}`
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@type {{room?: boolean, user_ids?: string[]}}
|
@type {{room?: boolean, user_ids?: string[]}}
|
||||||
|
|
@ -630,12 +621,6 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInteraction && !isThinkingInteraction && events.length === 0) {
|
|
||||||
const formattedInteraction = getFormattedInteraction(interaction, false)
|
|
||||||
body = `${formattedInteraction.body}\n${body}`
|
|
||||||
html = `${formattedInteraction.html}${html}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const newTextMessageEvent = {
|
const newTextMessageEvent = {
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
"m.mentions": mentions,
|
"m.mentions": mentions,
|
||||||
|
|
@ -727,13 +712,8 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
events.push(...forwardedEvents)
|
events.push(...forwardedEvents)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isThinkingInteraction) {
|
|
||||||
const formattedInteraction = getFormattedInteraction(interaction, true)
|
|
||||||
await addTextEvent(formattedInteraction.body, formattedInteraction.html, "m.notice")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then text content
|
// Then text content
|
||||||
if (message.content && !isOnlyKlipyGIF && !isThinkingInteraction) {
|
if (message.content && !isOnlyKlipyGIF) {
|
||||||
// Mentions scenario 3: scan the message content for written @mentions of matrix users. Allows for up to one space between @ and mention.
|
// Mentions scenario 3: scan the message content for written @mentions of matrix users. Allows for up to one space between @ and mention.
|
||||||
let content = message.content
|
let content = message.content
|
||||||
if (options.scanTextForMentions !== false) {
|
if (options.scanTextForMentions !== false) {
|
||||||
|
|
@ -757,11 +737,6 @@ 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)
|
const {body, html} = await transformContent(content)
|
||||||
await addTextEvent(body, html, msgtype)
|
await addTextEvent(body, html, msgtype)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,31 +4,24 @@ const data = require("../../../test/data")
|
||||||
const {mockGetEffectivePower} = require("../../matrix/utils.test")
|
const {mockGetEffectivePower} = require("../../matrix/utils.test")
|
||||||
const {db} = require("../../passthrough")
|
const {db} = require("../../passthrough")
|
||||||
|
|
||||||
test("message2event embeds: interaction loading", async t => {
|
|
||||||
const events = await messageToEvent(data.interaction_message.thinking_interaction, data.guild.general, {})
|
|
||||||
t.deepEqual(events, [{
|
|
||||||
$type: "m.room.message",
|
|
||||||
body: "↪️ Brad used `/stats` — interaction loading...",
|
|
||||||
format: "org.matrix.custom.html",
|
|
||||||
formatted_body: "<blockquote><sub>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">Brad</a> used <code>/stats</code> — interaction loading...</sub></blockquote>",
|
|
||||||
"m.mentions": {},
|
|
||||||
msgtype: "m.notice",
|
|
||||||
}])
|
|
||||||
})
|
|
||||||
|
|
||||||
test("message2event embeds: nothing but a field", async t => {
|
test("message2event embeds: nothing but a field", async t => {
|
||||||
const events = await messageToEvent(data.message_with_embeds.nothing_but_a_field, data.guild.general, {})
|
const events = await messageToEvent(data.message_with_embeds.nothing_but_a_field, data.guild.general, {})
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
|
$type: "m.room.message",
|
||||||
|
body: "> ↪️ @papiophidian: used `/stats`",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: "<blockquote>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">@papiophidian</a> used <code>/stats</code></blockquote>",
|
||||||
|
"m.mentions": {},
|
||||||
|
msgtype: "m.text",
|
||||||
|
}, {
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
"m.mentions": {},
|
"m.mentions": {},
|
||||||
msgtype: "m.notice",
|
msgtype: "m.notice",
|
||||||
body: "↪️ PapiOphidian used `/stats`"
|
body: "| ### Amanda 🎵#2192 :online:"
|
||||||
+ "\n| ### Amanda 🎵#2192 :online:"
|
|
||||||
+ "\n| willow tree, branch 0"
|
+ "\n| willow tree, branch 0"
|
||||||
+ "\n| **❯ Uptime:**\n| 3m 55s\n| **❯ Memory:**\n| 64.45MB",
|
+ "\n| **❯ Uptime:**\n| 3m 55s\n| **❯ Memory:**\n| 64.45MB",
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: '<blockquote><sub>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">PapiOphidian</a> used <code>/stats</code></sub></blockquote>'
|
formatted_body: '<blockquote><p><strong>Amanda 🎵#2192 <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/LCEqjStXCxvRQccEkuslXEyZ\" title=\":online:\" alt=\":online:\">'
|
||||||
+ '<blockquote><p><strong>Amanda 🎵#2192 <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/LCEqjStXCxvRQccEkuslXEyZ\" title=\":online:\" alt=\":online:\">'
|
|
||||||
+ '<br>willow tree, branch 0</strong>'
|
+ '<br>willow tree, branch 0</strong>'
|
||||||
+ '<br><strong>❯ Uptime:</strong><br>3m 55s'
|
+ '<br><strong>❯ Uptime:</strong><br>3m 55s'
|
||||||
+ '<br><strong>❯ Memory:</strong><br>64.45MB</p></blockquote>'
|
+ '<br><strong>❯ Memory:</strong><br>64.45MB</p></blockquote>'
|
||||||
|
|
@ -152,12 +145,17 @@ test("message2event embeds: title without url", async t => {
|
||||||
const events = await messageToEvent(data.message_with_embeds.title_without_url, data.guild.general)
|
const events = await messageToEvent(data.message_with_embeds.title_without_url, data.guild.general)
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
msgtype: "m.notice",
|
body: "> ↪️ @papiophidian: used `/stats`",
|
||||||
body: "↪️ PapiOphidian used `/stats`"
|
|
||||||
+ "\n| ## Hi, I'm Amanda!\n| \n| I condone pirating music!",
|
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: '<blockquote><sub>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">PapiOphidian</a> used <code>/stats</code></sub></blockquote>'
|
formatted_body: "<blockquote>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">@papiophidian</a> used <code>/stats</code></blockquote>",
|
||||||
+ `<blockquote><p><strong>Hi, I'm Amanda!</strong></p><p>I condone pirating music!</p></blockquote>`,
|
"m.mentions": {},
|
||||||
|
msgtype: "m.text",
|
||||||
|
}, {
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.notice",
|
||||||
|
body: "| ## Hi, I'm Amanda!\n| \n| I condone pirating music!",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: `<blockquote><p><strong>Hi, I'm Amanda!</strong></p><p>I condone pirating music!</p></blockquote>`,
|
||||||
"m.mentions": {}
|
"m.mentions": {}
|
||||||
}])
|
}])
|
||||||
})
|
})
|
||||||
|
|
@ -166,12 +164,17 @@ test("message2event embeds: url without title", async t => {
|
||||||
const events = await messageToEvent(data.message_with_embeds.url_without_title, data.guild.general)
|
const events = await messageToEvent(data.message_with_embeds.url_without_title, data.guild.general)
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
msgtype: "m.notice",
|
body: "> ↪️ @papiophidian: used `/stats`",
|
||||||
body: "↪️ PapiOphidian used `/stats`"
|
|
||||||
+ "\n| I condone pirating music!",
|
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: '<blockquote><sub>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">PapiOphidian</a> used <code>/stats</code></sub></blockquote>'
|
formatted_body: "<blockquote>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">@papiophidian</a> used <code>/stats</code></blockquote>",
|
||||||
+ `<blockquote><p>I condone pirating music!</p></blockquote>`,
|
"m.mentions": {},
|
||||||
|
msgtype: "m.text",
|
||||||
|
}, {
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.notice",
|
||||||
|
body: "| I condone pirating music!",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: `<blockquote><p>I condone pirating music!</p></blockquote>`,
|
||||||
"m.mentions": {}
|
"m.mentions": {}
|
||||||
}])
|
}])
|
||||||
})
|
})
|
||||||
|
|
@ -180,12 +183,17 @@ test("message2event embeds: author without url", async t => {
|
||||||
const events = await messageToEvent(data.message_with_embeds.author_without_url, data.guild.general)
|
const events = await messageToEvent(data.message_with_embeds.author_without_url, data.guild.general)
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
msgtype: "m.notice",
|
body: "> ↪️ @papiophidian: used `/stats`",
|
||||||
body: "↪️ PapiOphidian used `/stats`"
|
|
||||||
+ "\n| ## Amanda\n| \n| I condone pirating music!",
|
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: '<blockquote><sub>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">PapiOphidian</a> used <code>/stats</code></sub></blockquote>'
|
formatted_body: "<blockquote>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">@papiophidian</a> used <code>/stats</code></blockquote>",
|
||||||
+ `<blockquote><p><strong>Amanda</strong></p><p>I condone pirating music!</p></blockquote>`,
|
"m.mentions": {},
|
||||||
|
msgtype: "m.text",
|
||||||
|
}, {
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.notice",
|
||||||
|
body: "| ## Amanda\n| \n| I condone pirating music!",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: `<blockquote><p><strong>Amanda</strong></p><p>I condone pirating music!</p></blockquote>`,
|
||||||
"m.mentions": {}
|
"m.mentions": {}
|
||||||
}])
|
}])
|
||||||
})
|
})
|
||||||
|
|
@ -194,12 +202,17 @@ test("message2event embeds: author url without name", async t => {
|
||||||
const events = await messageToEvent(data.message_with_embeds.author_url_without_name, data.guild.general)
|
const events = await messageToEvent(data.message_with_embeds.author_url_without_name, data.guild.general)
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
$type: "m.room.message",
|
$type: "m.room.message",
|
||||||
msgtype: "m.notice",
|
body: "> ↪️ @papiophidian: used `/stats`",
|
||||||
body: "↪️ PapiOphidian used `/stats`"
|
|
||||||
+ "\n| I condone pirating music!",
|
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: '<blockquote><sub>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">PapiOphidian</a> used <code>/stats</code></sub></blockquote>'
|
formatted_body: "<blockquote>↪️ <a href=\"https://matrix.to/#/@_ooye_papiophidian:cadence.moe\">@papiophidian</a> used <code>/stats</code></blockquote>",
|
||||||
+ `<blockquote><p>I condone pirating music!</p></blockquote>`,
|
"m.mentions": {},
|
||||||
|
msgtype: "m.text",
|
||||||
|
}, {
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.notice",
|
||||||
|
body: "| I condone pirating music!",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: `<blockquote><p>I condone pirating music!</p></blockquote>`,
|
||||||
"m.mentions": {}
|
"m.mentions": {}
|
||||||
}])
|
}])
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1171,18 +1171,6 @@ 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 => {
|
test("message2event: emoji triple long name", async t => {
|
||||||
const events = await messageToEvent(data.message.emoji_triple_long_name, data.guild.general, {})
|
const events = await messageToEvent(data.message.emoji_triple_long_name, data.guild.general, {})
|
||||||
t.deepEqual(events, [{
|
t.deepEqual(events, [{
|
||||||
|
|
|
||||||
31
test/data.js
31
test/data.js
|
|
@ -3219,37 +3219,6 @@ module.exports = {
|
||||||
flags: 0,
|
flags: 0,
|
||||||
components: []
|
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: {
|
emoji_triple_long_name: {
|
||||||
id: "1156394116540805170",
|
id: "1156394116540805170",
|
||||||
type: 0,
|
type: 0,
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,7 @@ 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/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/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/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
|
INSERT INTO emoji (emoji_id, name, animated, mxc_url) VALUES
|
||||||
('230201364309868544', 'hippo', 0, 'mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC'),
|
('230201364309868544', 'hippo', 0, 'mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue