forked from cadence/out-of-your-element
Compare commits
No commits in common. "bugfix/handle-expired-events" and "main" have entirely different histories.
bugfix/han
...
main
3 changed files with 2 additions and 51 deletions
|
|
@ -769,21 +769,7 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
// Then scheduled events
|
// Then scheduled events
|
||||||
if (message.content && di?.snow) {
|
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
|
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
|
||||||
let invite
|
const invite = await di.snow.invite.getInvite(match[1], {guild_scheduled_event_id: match[2]})
|
||||||
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) {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
const event = invite.guild_scheduled_event
|
const event = invite.guild_scheduled_event
|
||||||
if (!event) continue // the event ID provided was not valid
|
if (!event) continue // the event ID provided was not valid
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 => {
|
test("message2event: channel links are converted even inside lists (parser post-processer descends into list items)", async t => {
|
||||||
let called = 0
|
let called = 0
|
||||||
const events = await messageToEvent({
|
const events = await messageToEvent({
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,7 @@ const {green} = require("ansi-colors")
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite(":memory:")
|
const db = new sqlite(":memory:")
|
||||||
|
|
||||||
const readReg = require("../src/matrix/read-registration")
|
const {reg} = require("../src/matrix/read-registration")
|
||||||
readReg.reg = readReg.getTemplateRegistration("cadence.moe")
|
|
||||||
const {reg} = readReg
|
|
||||||
reg.url = "http://localhost:6693"
|
|
||||||
reg.ooye.discord_token = "Njg0MjgwMTkyNTUzODQ0NzQ3.Xl3zlw.baby"
|
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_origin = "https://matrix.cadence.moe" // so that tests will pass even when hard-coded
|
||||||
reg.ooye.server_name = "cadence.moe"
|
reg.ooye.server_name = "cadence.moe"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue