Handle expired invites & fix test registration (#73)
This PR addresses a bridge crash discovered while backfilling old channels, alongside a wee QoL fix for the test suite. * **Expired Events (`d2m`):** Wraps Discord scheduled event/invite link lookups in a try-catch block. If a link is expired (404 or Discord error 10006), the bridge now posts a fallback `m.notice` rather than throwing an error and halting message conversion. * **Test Suite Setup:** Updates `test.js` to initialize the mock registration object using `getTemplateRegistration()` preventing test runner crashes when running without a local `registration.yaml` file. Co-authored-by: Cadence Ember <cadence@disroot.org> Reviewed-on: https://gitdab.com/cadence/out-of-your-element/pulls/73 Co-authored-by: Bea <beanie@theargo.space> Co-committed-by: Bea <beanie@theargo.space>
This commit is contained in:
committed by
cadence
co-authored by
Cadence Ember
parent
cd8549da38
commit
f5ee130463
@@ -770,7 +770,18 @@ 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
|
||||
const invite = await di.snow.invite.getInvite(match[1], {guild_scheduled_event_id: match[2]})
|
||||
let invite
|
||||
try {
|
||||
invite = await di.snow.invite.getInvite(match[1], {guild_scheduled_event_id: match[2]})
|
||||
} catch (e) {
|
||||
// Skip expired/invalid invites and events
|
||||
if (e.message === `{"message": "Unknown Invite", "code": 10006}`) {
|
||||
break
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
const event = invite.guild_scheduled_event
|
||||
if (!event) continue // the event ID provided was not valid
|
||||
|
||||
|
||||
Reference in New Issue
Block a user