Compare commits

..

1 commit

Author SHA1 Message Date
Bea
f76974a8c0
Handle expired event/invite links from Discord 2026-03-02 01:34:06 +00:00
3 changed files with 4 additions and 38 deletions

View file

@ -769,19 +769,20 @@ async function messageToEvent(message, guild, options = {}, di) {
// Then scheduled events
if (message.content && di?.snow) {
for (const match of [...message.content.matchAll(/discord\.gg\/([A-Za-z0-9]+)\?event=([0-9]{18,})/g)]) { // snowflake has minimum 18 because the events feature is at least that old
// FIX: Wrap the API call in try/catch to handle expired events gracefully
let invite
try {
invite = await di.snow.invite.getInvite(match[1], {guild_scheduled_event_id: match[2]})
} catch (e) {
// Skip expired events and invites
if (e.code === 10006 || e.httpStatus === 404) {
// The event or invite is expired. Render a fallback notice so it's obvious, but don't crash.
console.warn(`[Backfill] Skipped expired scheduled event: ${match[0]}`)
const fallbackBody = `[Expired Scheduled Event: ${match[0]}]`
const fallbackHtml = `<blockquote>Expired Scheduled Event: <a href="https://${match[0]}">${match[0]}</a></blockquote>`
await addTextEvent(fallbackBody, fallbackHtml, "m.notice")
continue
}
throw e
throw e // Re-throw unexpected errors (like 429 Rate Limits or 500s)
}
const event = invite.guild_scheduled_event

View file

@ -1538,38 +1538,6 @@ test("message2event: vc invite event renders embed with room link", async t => {
])
})
test("message2event: expired event invite renders fallback notice", async t => {
const events = await messageToEvent({content: "https://discord.gg/placeholder?event=1381190945646710824"}, {}, {}, {
snow: {
invite: {
getInvite: async () => {
const error = new Error("Unknown Invite")
error.code = 10006
throw error
}
}
}
})
t.deepEqual(events, [
{
$type: "m.room.message",
body: "https://discord.gg/placeholder?event=1381190945646710824",
format: "org.matrix.custom.html",
formatted_body: "<a href=\"https://discord.gg/placeholder?event=1381190945646710824\">https://discord.gg/placeholder?event=1381190945646710824</a>",
"m.mentions": {},
msgtype: "m.text",
},
{
$type: "m.room.message",
msgtype: "m.notice",
body: "[Expired Scheduled Event: discord.gg/placeholder?event=1381190945646710824]",
format: "org.matrix.custom.html",
formatted_body: "<blockquote>Expired Scheduled Event: <a href=\"https://discord.gg/placeholder?event=1381190945646710824\">discord.gg/placeholder?event=1381190945646710824</a></blockquote>",
"m.mentions": {}
}
])
})
test("message2event: channel links are converted even inside lists (parser post-processer descends into list items)", async t => {
let called = 0
const events = await messageToEvent({

View file

@ -13,10 +13,7 @@ const {green} = require("ansi-colors")
const passthrough = require("../src/passthrough")
const db = new sqlite(":memory:")
const readReg = require("../src/matrix/read-registration")
readReg.reg = readReg.getTemplateRegistration("cadence.moe")
const {reg} = readReg
reg.url = "http://localhost:6693"
const {reg} = require("../src/matrix/read-registration")
reg.ooye.discord_token = "Njg0MjgwMTkyNTUzODQ0NzQ3.Xl3zlw.baby"
reg.ooye.server_origin = "https://matrix.cadence.moe" // so that tests will pass even when hard-coded
reg.ooye.server_name = "cadence.moe"