From e0a729c0811315265c4eff9e0f2423c8f756e91c Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 19 Dec 2024 11:10:31 -0800 Subject: [PATCH] feat: log bulk deleted messages --- src/events/registerEvents.ts | 147 +++++++++++++++-------------------- 1 file changed, 63 insertions(+), 84 deletions(-) diff --git a/src/events/registerEvents.ts b/src/events/registerEvents.ts index 919d1f53..cc6e43b0 100644 --- a/src/events/registerEvents.ts +++ b/src/events/registerEvents.ts @@ -19,90 +19,69 @@ const restrictedActivities = new Set([ "880218394199220334" ]); * Attaches the event listeners to the camperChan's instance. * @param camperChan - The camperChan's Discord instance. */ -export const registerEvents - = async(camperChan: ExtendedClient): Promise => { - try { - camperChan.on( - Events.ClientReady, - () => { - void handleReady(camperChan); - }, - ); - camperChan.on( - Events.MessageCreate, - (message) => { - void handleMessageCreate(camperChan, message); - }, - ); - camperChan.on( - Events.MessageUpdate, - (oldMessage, updatedMessage) => { - void handleMessageEdit(camperChan, oldMessage, updatedMessage); - }, - ); - camperChan.on( - Events.MessageDelete, - (message) => { - void handleMessageDelete(camperChan, message); - }, - ); - camperChan.on( - Events.InteractionCreate, - (interaction) => { - void handleInteractionCreate(camperChan, interaction); - }, - ); - camperChan.on( - Events.ThreadCreate, - (thread) => { - void handleThreadCreate(camperChan, thread); - }, - ); - camperChan.on( - Events.GuildMemberAdd, - (member) => { - void handleMemberAdd(camperChan, member); - }, - ); - camperChan.on( - Events.GuildMemberRemove, - (member) => { - void handleMemberRemove(camperChan, member); - }, - ); - camperChan.on(Events.Error, (error) => { - void errorHandler(camperChan, "client error event", error); - }); - camperChan.on( - Events.VoiceStateUpdate, - (oldState, updatedState) => { - void handleVoiceStateUpdate(camperChan, oldState, updatedState); - }, - ); - camperChan.on( - Events.GuildScheduledEventUpdate, - (oldEvent, updatedEvent) => { - if (!oldEvent) { - return; - } - void handleGuildScheduledEvents(camperChan, oldEvent, updatedEvent); - }, - ); - camperChan.on(Events.PresenceUpdate, (_old, updatedPresence) => { - const embeddedActivity = updatedPresence.activities.find((a) => { - return a.flags.has(ActivityFlagsBitField.Flags.Embedded); - }); - if ( - embeddedActivity?.applicationId === null +export const registerEvents = async( + camperChan: ExtendedClient, +): Promise => { + try { + camperChan.on(Events.ClientReady, () => { + void handleReady(camperChan); + }); + camperChan.on(Events.MessageCreate, (message) => { + void handleMessageCreate(camperChan, message); + }); + camperChan.on(Events.MessageUpdate, (oldMessage, updatedMessage) => { + void handleMessageEdit(camperChan, oldMessage, updatedMessage); + }); + camperChan.on(Events.MessageDelete, (message) => { + void handleMessageDelete(camperChan, message); + }); + camperChan.on(Events.InteractionCreate, (interaction) => { + void handleInteractionCreate(camperChan, interaction); + }); + camperChan.on(Events.ThreadCreate, (thread) => { + void handleThreadCreate(camperChan, thread); + }); + camperChan.on(Events.GuildMemberAdd, (member) => { + void handleMemberAdd(camperChan, member); + }); + camperChan.on(Events.GuildMemberRemove, (member) => { + void handleMemberRemove(camperChan, member); + }); + camperChan.on(Events.Error, (error) => { + void errorHandler(camperChan, "client error event", error); + }); + camperChan.on(Events.VoiceStateUpdate, (oldState, updatedState) => { + void handleVoiceStateUpdate(camperChan, oldState, updatedState); + }); + camperChan.on( + Events.GuildScheduledEventUpdate, + (oldEvent, updatedEvent) => { + if (!oldEvent) { + return; + } + void handleGuildScheduledEvents(camperChan, oldEvent, updatedEvent); + }, + ); + camperChan.on(Events.PresenceUpdate, (_old, updatedPresence) => { + const embeddedActivity = updatedPresence.activities.find((a) => { + return a.flags.has(ActivityFlagsBitField.Flags.Embedded); + }); + if ( + embeddedActivity?.applicationId === null || embeddedActivity?.applicationId === undefined || !restrictedActivities.has(embeddedActivity.applicationId) || !updatedPresence.member - ) { - return; - } - void updatedPresence.member.voice.disconnect(); - }); - } catch (error) { - await errorHandler(camperChan, "register events", error); - } - }; + ) { + return; + } + void updatedPresence.member.voice.disconnect(); + }); + camperChan.on(Events.MessageBulkDelete, (messages) => { + for (const message of messages.values()) { + void handleMessageDelete(camperChan, message); + } + }); + } catch (error) { + await errorHandler(camperChan, "register events", error); + } +};