Skip to content

Commit

Permalink
feat: log bulk deleted messages (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
naomi-lgbt authored Dec 19, 2024
1 parent 9d9d5ed commit 21d3617
Showing 1 changed file with 63 additions and 84 deletions.
147 changes: 63 additions & 84 deletions src/events/registerEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
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<void> => {
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);
}
};

0 comments on commit 21d3617

Please sign in to comment.