1
0
Fork 0

d->m fix replying to matrix user in thread

This commit is contained in:
Cadence Ember 2023-10-13 02:05:44 +13:00
parent 93fa5b2e9a
commit 61ac535995
5 changed files with 136 additions and 3 deletions

View file

@ -215,6 +215,11 @@ async function messageToEvent(message, guild, options = {}, di) {
repliedToUserHtml = repliedToDisplayName repliedToUserHtml = repliedToDisplayName
} }
let repliedToContent = message.referenced_message?.content let repliedToContent = message.referenced_message?.content
if (repliedToContent?.startsWith("> <:L1:")) {
// If the Discord user is replying to a Matrix user's reply, the fallback is going to contain the emojis and stuff from the bridged rep of the Matrix user's reply quote.
// Need to remove that previous reply rep from this fallback body. The fallbody body should only contain the Matrix user's actual message.
repliedToContent = repliedToContent.split("\n").slice(2).join("\n")
}
if (repliedToContent == "") repliedToContent = "[Media]" if (repliedToContent == "") repliedToContent = "[Media]"
else if (!repliedToContent) repliedToContent = "[Replied-to message content wasn't provided by Discord]" else if (!repliedToContent) repliedToContent = "[Replied-to message content wasn't provided by Discord]"
const repliedToHtml = markdown.toHTML(repliedToContent, { const repliedToHtml = markdown.toHTML(repliedToContent, {

View file

@ -273,6 +273,45 @@ test("message2event: simple reply to matrix user, reply fallbacks disabled", asy
}]) }])
}) })
test("message2event: simple reply in thread to a matrix user's reply", async t => {
const events = await messageToEvent(data.message.simple_reply_to_reply_in_thread, data.guild.general, {}, {
api: {
getEvent: mockGetEvent(t, "!FuDZhlOAtqswlyxzeR:cadence.moe", "$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo", {
type: "m.room.message",
sender: "@cadence:cadence.moe",
content: {
msgtype: "m.text",
body: "> <@_ooye_cadence:cadence.moe> So what I'm wondering is about replies.\n\nWhat about them?",
format: "org.matrix.custom.html",
formatted_body: "<mx-reply><blockquote><a href=\"https://matrix.to/#/!FuDZhlOAtqswlyxzeR:cadence.moe/$fWQT8uOrzLzAXNVXz88VkGx7Oo724iS5uD8Qn5KUy9w?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_cadence:cadence.moe\">@_ooye_cadence:cadence.moe</a><br>So what I&#39;m wondering is about replies.</blockquote></mx-reply>What about them?",
"m.relates_to": {
"m.in_reply_to": {
event_id: "$fWQT8uOrzLzAXNVXz88VkGx7Oo724iS5uD8Qn5KUy9w"
}
}
},
event_id: "$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo",
room_id: "!FuDZhlOAtqswlyxzeR:cadence.moe"
})
}
})
t.deepEqual(events, [{
$type: "m.room.message",
"m.relates_to": {
"m.in_reply_to": {
event_id: "$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo"
}
},
"m.mentions": {
user_ids: ["@cadence:cadence.moe"]
},
msgtype: "m.text",
body: "> cadence: What about them?\n\nWell, they don't seem to...",
format: "org.matrix.custom.html",
formatted_body: "<mx-reply><blockquote><a href=\"https://matrix.to/#/!FuDZhlOAtqswlyxzeR:cadence.moe/$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">cadence</a><br>What about them?</blockquote></mx-reply>Well, they don't seem to...",
}])
})
test("message2event: simple written @mention for matrix user", async t => { test("message2event: simple written @mention for matrix user", async t => {
const events = await messageToEvent(data.message.simple_written_at_mention_for_matrix, data.guild.general, {}, { const events = await messageToEvent(data.message.simple_written_at_mention_for_matrix, data.guild.general, {}, {
api: { api: {

View file

@ -99,7 +99,7 @@ async function sendEvent(event) {
for (const message of messagesToSend) { for (const message of messagesToSend) {
const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message, threadID) const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message, threadID)
db.prepare("REPLACE INTO message_channel (message_id, channel_id) VALUES (?, ?)").run(messageResponse.id, channelID) db.prepare("REPLACE INTO message_channel (message_id, channel_id) VALUES (?, ?)").run(messageResponse.id, threadID || channelID)
db.prepare("INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, source) VALUES (?, ?, ?, ?, ?, 0)").run(event.event_id, event.type, event.content["msgtype"] || null, messageResponse.id, eventPart) // source 0 = matrix db.prepare("INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, source) VALUES (?, ?, ?, ?, ?, 0)").run(event.event_id, event.type, event.content["msgtype"] || null, messageResponse.id, eventPart) // source 0 = matrix
eventPart = 1 eventPart = 1

View file

@ -939,6 +939,92 @@ module.exports = {
attachments: [], attachments: [],
guild_id: "112760669178241024" guild_id: "112760669178241024"
}, },
simple_reply_to_reply_in_thread: {
type: 19,
tts: false,
timestamp: "2023-10-12T12:35:12.721000+00:00",
referenced_message: {
webhook_id: "1142275246532083723",
type: 0,
tts: false,
timestamp: "2023-10-12T12:35:06.578000+00:00",
position: 1,
pinned: false,
mentions: [
{
username: "cadence.worm",
public_flags: 0,
id: "772659086046658620",
global_name: "cadence",
discriminator: "0",
avatar_decoration_data: null,
avatar: "4b5c4b28051144e4c111f0113a0f1cf1"
}
],
mention_roles: [],
mention_everyone: false,
id: "1162005526675193909",
flags: 0,
embeds: [],
edited_timestamp: null,
content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/1100319549670301727/1162005314908999790/1162005501782011975 <@772659086046658620>:\n" +
"> So what I'm wondering is about replies.\n" +
"What about them?",
components: [],
channel_id: "1162005314908999790",
author: {
username: "cadence [they]",
id: "1142275246532083723",
global_name: null,
discriminator: "0000",
bot: true,
avatar: "af0ead3b92cf6e448fdad80b4e7fc9e5"
},
attachments: [],
application_id: "684280192553844747"
},
position: 2,
pinned: false,
nonce: "1162005551190638592",
message_reference: {
message_id: "1162005526675193909",
guild_id: "1100319549670301727",
channel_id: "1162005314908999790"
},
mentions: [],
mention_roles: [],
mention_everyone: false,
member: {
roles: [],
premium_since: null,
pending: false,
nick: "worm",
mute: false,
joined_at: "2023-04-25T07:17:03.696000+00:00",
flags: 0,
deaf: false,
communication_disabled_until: null,
avatar: null
},
id: "1162005552440815646",
flags: 0,
embeds: [],
edited_timestamp: null,
content: "Well, they don't seem to...",
components: [],
channel_id: "1162005314908999790",
author: {
username: "cadence.worm",
public_flags: 0,
id: "772659086046658620",
global_name: "cadence",
discriminator: "0",
avatar_decoration_data: null,
avatar: "4b5c4b28051144e4c111f0113a0f1cf1"
},
attachments: [],
guild_id: "1100319549670301727"
},
sticker: { sticker: {
id: "1106366167788044450", id: "1106366167788044450",
type: 0, type: 0,

View file

@ -8,6 +8,7 @@ INSERT INTO channel_room (channel_id, room_id, name, nick, thread_parent, custom
('497161350934560778', '!CzvdIdUQXgUjDVKxeU:cadence.moe', 'amanda-spam', NULL, NULL, NULL), ('497161350934560778', '!CzvdIdUQXgUjDVKxeU:cadence.moe', 'amanda-spam', NULL, NULL, NULL),
('160197704226439168', '!hYnGGlPHlbujVVfktC:cadence.moe', 'the-stanley-parable-channel', 'bots', NULL, NULL), ('160197704226439168', '!hYnGGlPHlbujVVfktC:cadence.moe', 'the-stanley-parable-channel', 'bots', NULL, NULL),
('1100319550446252084', '!BnKuBPCvyfOkhcUjEu:cadence.moe', 'worm-farm', NULL, NULL, NULL), ('1100319550446252084', '!BnKuBPCvyfOkhcUjEu:cadence.moe', 'worm-farm', NULL, NULL, NULL),
('1162005314908999790', '!FuDZhlOAtqswlyxzeR:cadence.moe', 'Hey.', NULL, '1100319550446252084', NULL),
('297272183716052993', '!rEOspnYqdOalaIFniV:cadence.moe', 'general', NULL, NULL, NULL), ('297272183716052993', '!rEOspnYqdOalaIFniV:cadence.moe', 'general', NULL, NULL, NULL),
('122155380120748034', '!cqeGDbPiMFAhLsqqqq:cadence.moe', 'cadences-mind', 'coding', NULL, NULL); ('122155380120748034', '!cqeGDbPiMFAhLsqqqq:cadence.moe', 'cadences-mind', 'coding', NULL, NULL);
@ -36,7 +37,8 @@ INSERT INTO message_channel (message_id, channel_id) VALUES
('1144865310588014633', '687028734322147344'), ('1144865310588014633', '687028734322147344'),
('1145688633186193479', '1100319550446252084'), ('1145688633186193479', '1100319550446252084'),
('1145688633186193480', '1100319550446252084'), ('1145688633186193480', '1100319550446252084'),
('1145688633186193481', '1100319550446252084'); ('1145688633186193481', '1100319550446252084'),
('1162005526675193909', '1162005314908999790');
INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, source) VALUES INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, source) VALUES
('$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg', 'm.room.message', 'm.text', '1126786462646550579', 0, 1), ('$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg', 'm.room.message', 'm.text', '1126786462646550579', 0, 1),
@ -57,7 +59,8 @@ INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part
('$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8', 'm.room.message', 'm.text', '1144874214311067708', 0, 0), ('$v_Gtr-bzv9IVlSLBO5DstzwmiDd-GSFaNfHX66IupV8', 'm.room.message', 'm.text', '1144874214311067708', 0, 0),
('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs', 'm.room.message', 'm.text', '1145688633186193479', 0, 0), ('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs', 'm.room.message', 'm.text', '1145688633186193479', 0, 0),
('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt', 'm.room.message', 'm.text', '1145688633186193480', 0, 0), ('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt', 'm.room.message', 'm.text', '1145688633186193480', 0, 0),
('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt', 'm.room.message', 'm.text', '1145688633186193481', 1, 0); ('$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt', 'm.room.message', 'm.text', '1145688633186193481', 1, 0),
('$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo', 'm.room.message', 'm.text', '1162005526675193909', 0, 0);
INSERT INTO file (discord_url, mxc_url) VALUES INSERT INTO file (discord_url, mxc_url) VALUES
('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'), ('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'),