Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log bulk deleted messages #746

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
};