Skip to content

Commit

Permalink
fix: modfied dummy events setup in setupDummyEvents to be more accura…
Browse files Browse the repository at this point in the history
…te, also added comments to make it easier to maintain
  • Loading branch information
AwesomeStickz committed Aug 14, 2024
1 parent d23e0a7 commit feb0cbe
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions setupDummyEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,32 @@ export const setupDummyEvents = <B extends Bot>(bot: BotWithProxyCache<ProxyCach
for (const event of eventsRequired) bot.events[event] ??= ignore;
};

/*
Explanation about the comments for setupDummy functions:
Handlers: All the handlers that run these transformers.
Transformers: All the transformers that run these transformers.
Inside the transformers list for a transformer X:
- A means that transformer X is called by transformer A, means we have to add the events that run A.
- A (B) means that transformer X is called by transformer A which is called only by transformer B, so we only add the events that run B. This has the following possibilities:
- A (B): A is called only by B, target B.
- A (B, C, ...): A is called by only by B and C, target B and C.
- A (B (C (...))): A is called by B which is called by C, target C.
- A (REST Only) means that transformer A is only called inside the REST functions, which means that they directly call X, so we can ignore.
- X (Self) means that X calls itself, so we can ignore.
The purpose of this is to know what we've already handled and what we still need to handle if we want to update in the future when more events are added/updated.
*/

// Handlers: GUILD_CREATE, GUILD_UPDATE
// Transformers: None
const setupDummyGuildEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('guildCreate');
eventsRequired.add('guildDelete');
eventsRequired.add('guildUpdate');
};

// Handlers: CHANNEL_CREATE, CHANNEL_DELETE, CHANNEL_UPDATE, THREAD_CREATE, THREAD_DELETE, THREAD_UPDATE, THREAD_LIST_SYNC
// Transformers: Guild, Interaction, Message
const setupDummyChannelEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('channelCreate');
eventsRequired.add('channelDelete');
Expand All @@ -36,9 +57,12 @@ const setupDummyChannelEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('threadListSync');

setupDummyGuildEvents(eventsRequired);
setupDummyInteractionEvents(eventsRequired);
setupDummyMessageEvents(eventsRequired);
};

// Handlers: GUILD_ROLE_CREATE, GUILD_ROLE_UPDATE
// Transformers: Guild, Interaction
const setupDummyRoleEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('roleCreate');
eventsRequired.add('roleUpdate');
Expand All @@ -47,9 +71,10 @@ const setupDummyRoleEvents = (eventsRequired: Set<keyof EventHandlers>) => {
setupDummyInteractionEvents(eventsRequired);
};

// Handlers: GUILD_MEMBER_ADD, GUILD_MEMBER_UPDATE, MESSAGE_REACTION_ADD, TYPING_START
// Transformers: Guild, Interaction, Message, Stage Invite Instance (Invite)
const setupDummyMemberEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('guildMemberAdd');
eventsRequired.add('guildMemberRemove');
eventsRequired.add('guildMemberUpdate');
eventsRequired.add('reactionAdd');
eventsRequired.add('typingStart');
Expand All @@ -60,6 +85,8 @@ const setupDummyMemberEvents = (eventsRequired: Set<keyof EventHandlers>) => {
setupDummyInviteEvents(eventsRequired);
};

// Handlers: GUILD_BAN_ADD, GUILD_BAN_REMOVE, GUILD_MEMBER_ADD, GUILD_MEMBER_REMOVE, GUILD_MEMBER_UPDATE, MESSAGE_REACTION_ADD, READY, USER_UPDATE
// Transformers: Application (Invite), Channel, Emoji, Integration, Interaction, Invite, Member, Message, Presence, Scheduled Event, Sticker Pack (REST Only), Team (Application (Invite)), Template (REST Only), Webhook (REST Only)
const setupDummyUserEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('guildBanAdd');
eventsRequired.add('guildBanRemove');
Expand All @@ -70,6 +97,7 @@ const setupDummyUserEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('ready');
eventsRequired.add('botUpdate');

setupDummyChannelEvents(eventsRequired);
setupDummyEmojiEvents(eventsRequired);
setupDummyIntegrationEvents(eventsRequired);
setupDummyInteractionEvents(eventsRequired);
Expand All @@ -78,10 +106,12 @@ const setupDummyUserEvents = (eventsRequired: Set<keyof EventHandlers>) => {
setupDummyMessageEvents(eventsRequired);
setupDummyPresenceEvents(eventsRequired);
setupDummyScheduledEventEvents(eventsRequired);
setupDummyStickerEvents(eventsRequired);
};

// Handlers: GUILD_EMOJIS_UPDATE, MESSAGE_REACTION_ADD, MESSAGE_REACTION_REMOVE_EMOJI, MESSAGE_REACTION_REMOVE
// Transformers: Guild, Message, Onboarding (REST Only), Poll (Message)
const setupDummyEmojiEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('guildEmojisUpdate');
eventsRequired.add('reactionAdd');
eventsRequired.add('reactionRemoveEmoji');
eventsRequired.add('reactionRemove');
Expand All @@ -90,41 +120,48 @@ const setupDummyEmojiEvents = (eventsRequired: Set<keyof EventHandlers>) => {
setupDummyMessageEvents(eventsRequired);
};

// Handlers: INTEGRATION_CREATE, INTEGRATION_UPDATE
// Transformers: None
const setupDummyIntegrationEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('integrationCreate');
eventsRequired.add('integrationUpdate');
};

// Handlers: INTERACTION_CREATE
// Transformers: None
const setupDummyInteractionEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('interactionCreate');
};

// Handlers: INVITE_CREATE
// Transformers: None
const setupDummyInviteEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('inviteCreate');
};

// Handlers: MESSAGE_CREATE, MESSAGE_UPDATE
// Transformers: Interaction, Message (Self)
const setupDummyMessageEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('messageCreate');
eventsRequired.add('messageUpdate');

setupDummyInteractionEvents(eventsRequired);
};

// Handlers: PRESENCE_UPDATE
// Transformers: Guild
const setupDummyPresenceEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('presenceUpdate');

setupDummyGuildEvents(eventsRequired);
};

// Handlers: GUILD_SCHEDULED_EVENT_CREATE, GUILD_SCHEDULED_EVENT_DELETE, GUILD_SCHEDULED_EVENT_UPDATE
// Transformers: Invite
const setupDummyScheduledEventEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('scheduledEventCreate');
eventsRequired.add('scheduledEventDelete');
eventsRequired.add('scheduledEventUpdate');

setupDummyInviteEvents(eventsRequired);
};

const setupDummyStickerEvents = (eventsRequired: Set<keyof EventHandlers>) => {
eventsRequired.add('guildStickersUpdate');

setupDummyGuildEvents(eventsRequired);
};

0 comments on commit feb0cbe

Please sign in to comment.