Handle mentioning sims from a different bridge

This commit is contained in:
Cadence Ember 2023-11-28 19:04:08 +13:00
parent cd2e012b8e
commit 024ff34cca
2 changed files with 40 additions and 4 deletions

View file

@ -390,10 +390,19 @@ async function eventToMessage(event, guild, di) {
// Handling mentions of Discord users // Handling mentions of Discord users
input = input.replace(/("https:\/\/matrix.to\/#\/(@[^"]+)")>/g, (whole, attributeValue, mxid) => { input = input.replace(/("https:\/\/matrix.to\/#\/(@[^"]+)")>/g, (whole, attributeValue, mxid) => {
if (!utils.eventSenderIsFromDiscord(mxid)) return whole if (utils.eventSenderIsFromDiscord(mxid)) {
const userID = select("sim", "user_id", {mxid: mxid}).pluck().get() // Handle mention of an OOYE sim user by their mxid
if (!userID) return whole const userID = select("sim", "user_id", {mxid: mxid}).pluck().get()
return `${attributeValue} data-user-id="${userID}">` if (!userID) return whole
return `${attributeValue} data-user-id="${userID}">`
} else {
// Handle mention of a Matrix user by their mxid
// Check if this Matrix user is actually the sim user from another old bridge in the room?
const match = mxid.match(/[^:]*discord[^:]*_([0-9]{6,}):/) // try to match @_discord_123456, @_discordpuppet_123456, etc.
if (match) return `${attributeValue} data-user-id="${match[1]}">`
// Nope, just a real Matrix user.
return whole
}
}) })
// Handling mentions of Discord rooms // Handling mentions of Discord rooms

View file

@ -2211,6 +2211,33 @@ test("event2message: guessed @mentions may join members to mention", async t =>
t.equal(called, 1, "searchGuildMembers should be called once") t.equal(called, 1, "searchGuildMembers should be called once")
}) })
test("event2message: guessed @mentions work with other matrix bridge old users", async t => {
t.deepEqual(
await eventToMessage({
type: "m.room.message",
sender: "@cadence:cadence.moe",
content: {
msgtype: "m.text",
body: "extremity#0: zenosia#0717: back me up on this sentiment, if not necessarily the phrasing",
format: "org.matrix.custom.html",
formatted_body: "<a href=\"https://matrix.to/#/@_discord_114147806469554185:cadence.moe\">extremity#0</a>: <a href=\"https://matrix.to/#/@_discordpuppet_176943908762006200:cadence.moe\">zenosia#0717</a>: back me up on this sentiment, if not necessarily the phrasing"
},
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe",
event_id: "$SiXetU9h9Dg-M9Frcw_C6ahnoXZ3QPZe3MVJR5tcB9A"
}),
{
messagesToDelete: [],
messagesToEdit: [],
messagesToSend: [{
username: "cadence [they]",
content: "<@114147806469554185> <@176943908762006200> back me up on this sentiment, if not necessarily the phrasing",
avatar_url: undefined
}],
ensureJoined: [] // we already think it worked on Matrix side due to the pill, so no need for the OOYE sim user to join the room to indicate success.
}
)
})
slow()("event2message: unknown emoji in the end is reuploaded as a sprite sheet", async t => { slow()("event2message: unknown emoji in the end is reuploaded as a sprite sheet", async t => {
const messages = await eventToMessage({ const messages = await eventToMessage({
type: "m.room.message", type: "m.room.message",