From 7efdf1fe559f218fa49caf6878f0a67e485ad462 Mon Sep 17 00:00:00 2001 From: IoyoCode Date: Tue, 13 Jun 2023 12:36:34 +0100 Subject: [PATCH] feat(events): implemented more gateway events --- .../discordjar/events/DiscordListener.java | 51 +++++- .../events/model/channel/ChannelEvent.java | 17 ++ .../model/channel/ChannelPinsUpdateEvent.java | 77 +++++++++ .../channel/edit/ChannelCreateEvent.java | 13 ++ .../channel/edit/ChannelDeleteEvent.java | 12 ++ .../channel/edit/ChannelUpdateEvent.java | 12 ++ .../events/model/guild/GuildDeleteEvent.java | 37 ++++ .../events/model/guild/GuildUpdateEvent.java | 18 ++ .../model/message/TypingStartEvent.java | 115 +++++++++++++ .../gateway/events/DispatchedEvents.java | 162 +++++++++--------- 10 files changed, 433 insertions(+), 81 deletions(-) create mode 100644 src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java create mode 100644 src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java create mode 100644 src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java create mode 100644 src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java create mode 100644 src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java create mode 100644 src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java create mode 100644 src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java create mode 100644 src/main/java/com/seailz/discordjar/events/model/message/TypingStartEvent.java diff --git a/src/main/java/com/seailz/discordjar/events/DiscordListener.java b/src/main/java/com/seailz/discordjar/events/DiscordListener.java index 8d434f8b..12c49a5f 100644 --- a/src/main/java/com/seailz/discordjar/events/DiscordListener.java +++ b/src/main/java/com/seailz/discordjar/events/DiscordListener.java @@ -1,9 +1,18 @@ package com.seailz.discordjar.events; import com.seailz.discordjar.command.listeners.CommandListener; +import com.seailz.discordjar.events.model.automod.AutoModExecutionEvent; +import com.seailz.discordjar.events.model.automod.rule.AutoModRuleCreateEvent; +import com.seailz.discordjar.events.model.automod.rule.AutoModRuleUpdateEvent; +import com.seailz.discordjar.events.model.channel.ChannelPinsUpdateEvent; +import com.seailz.discordjar.events.model.channel.edit.ChannelCreateEvent; +import com.seailz.discordjar.events.model.channel.edit.ChannelUpdateEvent; import com.seailz.discordjar.events.model.command.CommandPermissionUpdateEvent; +import com.seailz.discordjar.events.model.gateway.GatewayResumedEvent; import com.seailz.discordjar.events.model.general.ReadyEvent; import com.seailz.discordjar.events.model.guild.GuildCreateEvent; +import com.seailz.discordjar.events.model.guild.GuildDeleteEvent; +import com.seailz.discordjar.events.model.guild.GuildUpdateEvent; import com.seailz.discordjar.events.model.guild.member.GuildMemberAddEvent; import com.seailz.discordjar.events.model.guild.member.GuildMemberRemoveEvent; import com.seailz.discordjar.events.model.guild.member.GuildMemberUpdateEvent; @@ -15,6 +24,7 @@ import com.seailz.discordjar.events.model.interaction.select.entity.RoleSelectMenuInteractionEvent; import com.seailz.discordjar.events.model.interaction.select.entity.UserSelectMenuInteractionEvent; import com.seailz.discordjar.events.model.message.MessageCreateEvent; +import com.seailz.discordjar.events.model.message.TypingStartEvent; import org.jetbrains.annotations.NotNull; /** @@ -33,12 +43,24 @@ public abstract class DiscordListener { public void onReady(@NotNull ReadyEvent event) { } + public void onGatewayResume(@NotNull GatewayResumedEvent event) { + } + // Message Events public void onMessageReceived(@NotNull MessageCreateEvent event) { } + public void onTypingStart(@NotNull TypingStartEvent event) { + } + // Guild Events - public void onGuildCreated(@NotNull GuildCreateEvent event) { + public void onGuildCreate(@NotNull GuildCreateEvent event) { + } + + public void onGuildUpdate(@NotNull GuildUpdateEvent event) { + } + + public void onGuildDelete(@NotNull GuildDeleteEvent event) { } // Guild Member Events @@ -51,6 +73,19 @@ public void onGuildMemberUpdate(@NotNull GuildMemberUpdateEvent event) { public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) { } + // Channel Events + public void onChannelCreate(@NotNull ChannelCreateEvent event) { + } + + public void onChannelUpdate(@NotNull ChannelUpdateEvent event) { + } + + public void onChannelDelete(@NotNull ChannelCreateEvent event) { + } + + public void onChannelPinsUpdate(@NotNull ChannelPinsUpdateEvent event) { + } + // Command Events public void onCommandPermissionUpdate(@NotNull CommandPermissionUpdateEvent event) { } @@ -86,4 +121,18 @@ public void onButtonClickInteractionEvent(@NotNull ButtonInteractionEvent event) public void onModalInteractionEvent(@NotNull ModalInteractionEvent event) { } + + // Automod + public void onAutoModRuleCreate(@NotNull AutoModRuleCreateEvent event) { + } + + public void onAutoModRuleUpdate(@NotNull AutoModRuleUpdateEvent event) { + } + + public void onAutoModRuleDelete(@NotNull AutoModRuleUpdateEvent event) { + } + + public void onAutoModActionExecution(@NotNull AutoModExecutionEvent event) { + } + } diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java new file mode 100644 index 00000000..a4118295 --- /dev/null +++ b/src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java @@ -0,0 +1,17 @@ +package com.seailz.discordjar.events.model.channel; + +import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.events.model.Event; +import com.seailz.discordjar.model.channel.Channel; +import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; + +public class ChannelEvent extends Event { + public ChannelEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + super(bot, sequence, data); + } + + public Channel getChannel() { + return Channel.decompile(getJson(), getBot()); + } +} diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java new file mode 100644 index 00000000..c63eb0fe --- /dev/null +++ b/src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java @@ -0,0 +1,77 @@ +package com.seailz.discordjar.events.model.channel; + +import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.events.model.Event; +import com.seailz.discordjar.model.channel.Channel; +import com.seailz.discordjar.model.channel.MessagingChannel; +import com.seailz.discordjar.model.guild.Guild; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.json.JSONObject; + +import java.util.Date; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Dispatched when the pins for a channel are updated. This could be because: + * + *

It is not dispatched when a pinned message is deleted.

+ */ +public class ChannelPinsUpdateEvent extends Event { + + private String guildId; + private Guild guild; + private String channelId; + private Channel channel; + private LocalDateTime lastPinTimestamp; + + + public ChannelPinsUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + super(bot, sequence, data); + + guildId = data.has("guild_id") ? data.getString("guild_id") : null; + channelId = data.getString("channel_id"); + // last_pin_timestamp is a iso8601 timestamp, so we need to get a Date object from it + if (data.has("last_pin_timestamp")) { + String timestampString = data.getString("last_pin_timestamp"); + DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; + lastPinTimestamp = LocalDateTime.parse(timestampString, formatter); + } + } + + @Nullable + public String getGuildId() { + return guildId; + } + + @Nullable + public Guild getGuild() { + if (guild == null && guildId != null) + guild = getBot().getGuildById(guildId); + return guild; + } + + @NotNull + public String getChannelId() { + return channelId; + } + + @Nullable + public Channel getChannel() { + if (channel == null) + channel = getBot().getChannelById(channelId); + return channel; + } + + /** + * The time at which the most recent pinned msg was pinned. + */ + @Nullable + public LocalDateTime getLastPinTimestamp() { + return lastPinTimestamp; + } +} diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java new file mode 100644 index 00000000..30693876 --- /dev/null +++ b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java @@ -0,0 +1,13 @@ +package com.seailz.discordjar.events.model.channel.edit; + +import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.events.model.Event; +import com.seailz.discordjar.events.model.channel.ChannelEvent; +import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; + +public class ChannelCreateEvent extends ChannelEvent { + public ChannelCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + super(bot, sequence, data); + } +} diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java new file mode 100644 index 00000000..9f1a0c64 --- /dev/null +++ b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java @@ -0,0 +1,12 @@ +package com.seailz.discordjar.events.model.channel.edit; + +import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.events.model.channel.ChannelEvent; +import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; + +public class ChannelDeleteEvent extends ChannelEvent { + public ChannelDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + super(bot, sequence, data); + } +} diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java new file mode 100644 index 00000000..c91fb70a --- /dev/null +++ b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java @@ -0,0 +1,12 @@ +package com.seailz.discordjar.events.model.channel.edit; + +import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.events.model.channel.ChannelEvent; +import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; + +public class ChannelUpdateEvent extends ChannelEvent { + public ChannelUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + super(bot, sequence, data); + } +} diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java new file mode 100644 index 00000000..ddf76557 --- /dev/null +++ b/src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java @@ -0,0 +1,37 @@ +package com.seailz.discordjar.events.model.guild; + +import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.events.model.Event; +import com.seailz.discordjar.model.guild.UnavailableGuild; +import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; + +/** + * Sent when the guild becomes or was already unavailable due to an outage, or when the user leaves or is removed from a guild. + */ +public class GuildDeleteEvent extends Event { + + private UnavailableGuild guild; + + public GuildDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + super(bot, sequence, data); + guild = UnavailableGuild.decompile(getJson().getJSONObject("d"), getBot()); + } + + /** + * Returns the {@link UnavailableGuild} that was deleted. + * @return {@link UnavailableGuild} object. + */ + public UnavailableGuild getGuild() { + return guild; + } + + /** + * Returns true if the current user was removed from the guild. + */ + public boolean wasRemoved() { + return !getJson().getJSONObject("d").has("unavailable") || !getJson().getJSONObject("d").getBoolean("unavailable"); + } + + +} diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java new file mode 100644 index 00000000..b272667d --- /dev/null +++ b/src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java @@ -0,0 +1,18 @@ +package com.seailz.discordjar.events.model.guild; + +import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.events.model.Event; +import com.seailz.discordjar.model.guild.Guild; +import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; + +public class GuildUpdateEvent extends Event { + public GuildUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + super(bot, sequence, data); + } + + @NotNull + public Guild getGuild() { + return Guild.decompile(getJson().getJSONObject("d"), getBot()); + } +} diff --git a/src/main/java/com/seailz/discordjar/events/model/message/TypingStartEvent.java b/src/main/java/com/seailz/discordjar/events/model/message/TypingStartEvent.java new file mode 100644 index 00000000..5ebac707 --- /dev/null +++ b/src/main/java/com/seailz/discordjar/events/model/message/TypingStartEvent.java @@ -0,0 +1,115 @@ +package com.seailz.discordjar.events.model.message; + +import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.events.model.Event; +import com.seailz.discordjar.model.channel.Channel; +import com.seailz.discordjar.model.guild.Guild; +import com.seailz.discordjar.model.guild.Member; +import com.seailz.discordjar.model.user.User; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.json.JSONObject; + +/** + * This event will fire when a user starts typing. + * You can listen for this event by extending the {@link com.seailz.discordjar.events.DiscordListener} class + * and overriding the {@link com.seailz.discordjar.events.DiscordListener#onTypingStart(TypingStartEvent)} method. + * + * @author Seailz + * @see com.seailz.discordjar.events.DiscordListener + * @since 1.0 + */ +public class TypingStartEvent extends Event { + + private final String channelId; + private Channel channel; + private final String guildId; + private Guild guild; + private final String userId; + private User user; + private final long timestamp; + private Member member; + + public TypingStartEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + super(bot, sequence, data); + JSONObject inner = data.getJSONObject("d"); + channelId = inner.getString("channel_id"); + guildId = inner.has("guild_id") && !inner.isNull("guild_id") ? inner.getString("guild_id") : null; + userId = inner.getString("user_id"); + timestamp = inner.getLong("timestamp"); + if (inner.has("member") && !inner.isNull("member")) + member = Member.decompile(inner.getJSONObject("member"), getBot(), guildId, getGuild()); + } + + /** + * Returns the id of the channel that the user started typing in. + */ + @NotNull + public String getChannelId() { + return channelId; + } + + /** + * Returns the {@link Channel} that the user started typing in. + */ + @Nullable + public Channel getChannel() { + if (channel == null) + channel = getBot().getChannelById(channelId); + return channel; + } + + /** + * Returns the id of the guild that the user started typing in, or null if it was a DM. + */ + @Nullable + public String getGuildId() { + return guildId; + } + + /** + * Returns the {@link Guild} that the user started typing in, or null if it was a DM. + */ + @Nullable + public Guild getGuild() { + if (guild == null && guildId != null) + guild = getBot().getGuildById(guildId); + return guild; + } + + /** + * Returns the id of the user that started typing. + */ + @NotNull + public String getUserId() { + return userId; + } + + /** + * Returns the {@link User} that started typing. + */ + @Nullable + public User getUser() { + if (user == null) + user = getBot().getUserById(userId); + return user; + } + + /** + * Returns the unix timestamp of when the user started typing (in seconds). + */ + public long getTimestamp() { + return timestamp; + } + + /** + * Returns the {@link Member} that started typing, or null if it was a DM. + */ + @Nullable + public Member getMember() { + Guild guild = getGuild(); + if (member == null && guild != null) + member = guild.getMemberById(userId); + return member; + } +} diff --git a/src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java b/src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java index bc38d1b9..8cb0d275 100644 --- a/src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java +++ b/src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java @@ -6,10 +6,16 @@ import com.seailz.discordjar.events.model.automod.rule.AutoModRuleCreateEvent; import com.seailz.discordjar.events.model.automod.rule.AutoModRuleDeleteEvent; import com.seailz.discordjar.events.model.automod.rule.AutoModRuleUpdateEvent; +import com.seailz.discordjar.events.model.channel.ChannelPinsUpdateEvent; +import com.seailz.discordjar.events.model.channel.edit.ChannelCreateEvent; +import com.seailz.discordjar.events.model.channel.edit.ChannelDeleteEvent; +import com.seailz.discordjar.events.model.channel.edit.ChannelUpdateEvent; import com.seailz.discordjar.events.model.command.CommandPermissionUpdateEvent; import com.seailz.discordjar.events.model.gateway.GatewayResumedEvent; import com.seailz.discordjar.events.model.general.ReadyEvent; import com.seailz.discordjar.events.model.guild.GuildCreateEvent; +import com.seailz.discordjar.events.model.guild.GuildDeleteEvent; +import com.seailz.discordjar.events.model.guild.GuildUpdateEvent; import com.seailz.discordjar.events.model.guild.member.GuildMemberAddEvent; import com.seailz.discordjar.events.model.guild.member.GuildMemberRemoveEvent; import com.seailz.discordjar.events.model.guild.member.GuildMemberUpdateEvent; @@ -24,6 +30,7 @@ import com.seailz.discordjar.events.model.interaction.select.entity.RoleSelectMenuInteractionEvent; import com.seailz.discordjar.events.model.interaction.select.entity.UserSelectMenuInteractionEvent; import com.seailz.discordjar.events.model.message.MessageCreateEvent; +import com.seailz.discordjar.events.model.message.TypingStartEvent; import com.seailz.discordjar.gateway.GatewayFactory; import com.seailz.discordjar.command.CommandType; import com.seailz.discordjar.model.channel.Channel; @@ -91,65 +98,33 @@ public enum DispatchedEvents { return GuildCreateEvent.class; }), - - CHANNEL_CREATE((p, g, d) -> { - // cache - Channel channel = Channel.decompile(p.getJSONObject("d"), d); - d.getChannelCache().cache(channel); - - // TODO: Create a ChannelCreateEvent - return null; - }), - - CHANNEL_UPDATE((p, g, d) -> { - // modify cached channel, if it exists - Channel channel = Channel.decompile(p.getJSONObject("d"), d); - d.getChannelCache().cache(channel); - - // TODO: Create a ChannelUpdateEvent - return null; - }), - - CHANNEL_DELETE((p, g, d) -> { - // remove cached channel, if it exists - Channel channel = Channel.decompile(p.getJSONObject("d"), d); - d.getChannelCache().remove(channel); - - // TODO: Create a ChannelDeleteEvent - return null; + GUILD_MEMBER_ADD((p, g, d) -> { + String guildId = p.getJSONObject("d").getString("guild_id"); + d.insertMemberCache(guildId, Member.decompile( + p.getJSONObject("d"), + d, + guildId, + d.getGuildById(guildId) + )); + return GuildMemberAddEvent.class; }), - - GUILD_UPDATE((p, g, d) -> { - // modify cached guild, if it exists - Guild guild = Guild.decompile(p.getJSONObject("d"), d); - d.getGuildCache().cache(guild); - - // TODO: Create a GuildUpdateEvent - return null; + GUILD_MEMBER_UPDATE((p, g, d) -> { + String guildId = p.getJSONObject("d").getString("guild_id"); + d.insertMemberCache(guildId, Member.decompile( + p.getJSONObject("d"), + d, + guildId, + d.getGuildById(guildId) + )); + return GuildMemberUpdateEvent.class; }), - - GUILD_DELETE((p, g, d) -> { - // remove cached guild, if it exists - Guild guild = Guild.decompile(p.getJSONObject("d"), d); - d.getGuildCache().remove(guild); - - // TODO: Create a GuildDeleteEvent - return null; + GUILD_MEMBER_REMOVE((p, g, d) -> { + String guildId = p.getJSONObject("d").getString("guild_id"); + d.removeMemberCache(guildId, p.getJSONObject("d").getString("user_id")); + return GuildMemberRemoveEvent.class; }), - - /* Sent when a gateway connection is resumed */ - RESUMED((p, d, g) -> GatewayResumedEvent.class), - /* Sent when a message is created */ - MESSAGE_CREATE((p, d, g) -> MessageCreateEvent.class), /* Sent when a command permission is updated */ APPLICATION_COMMAND_PERMISSIONS_UPDATE((p, g, d) -> CommandPermissionUpdateEvent.class), - - /* AUTOMOD */ - AUTO_MODERATION_RULE_CREATE((p, g, d) -> AutoModRuleCreateEvent.class), - AUTO_MODERATION_RULE_UPDATE((p, g, d) -> AutoModRuleUpdateEvent.class), - AUTO_MODERATION_RULE_DELETE((p, g, d) -> AutoModRuleDeleteEvent.class), - AUTO_MODERATION_ACTION_EXECUTION((p, g, d) -> AutoModExecutionEvent.class), - /* Sent when an interaction is created */ INTERACTION_CREATE((p, g, d) -> { switch (InteractionType.getType(p.getJSONObject("d").getInt("type"))) { @@ -224,6 +199,59 @@ public enum DispatchedEvents { } return null; }), + /* Sent when a message is created */ + MESSAGE_CREATE((p, d, g) -> MessageCreateEvent.class), + CHANNEL_CREATE((p, g, d) -> { + // cache + Channel channel = Channel.decompile(p.getJSONObject("d"), d); + d.getChannelCache().cache(channel); + + return ChannelCreateEvent.class; + }), + + CHANNEL_UPDATE((p, g, d) -> { + // modify cached channel, if it exists + Channel channel = Channel.decompile(p.getJSONObject("d"), d); + d.getChannelCache().cache(channel); + + return ChannelUpdateEvent.class; + }), + + CHANNEL_DELETE((p, g, d) -> { + // remove cached channel, if it exists + Channel channel = Channel.decompile(p.getJSONObject("d"), d); + d.getChannelCache().remove(channel); + + return ChannelDeleteEvent.class; + }), + + CHANNEL_PINS_UPDATE((p, g, d) -> ChannelPinsUpdateEvent.class), + + GUILD_UPDATE((p, g, d) -> { + // modify cached guild, if it exists + Guild guild = Guild.decompile(p.getJSONObject("d"), d); + d.getGuildCache().cache(guild); + + return GuildUpdateEvent.class; + }), + + GUILD_DELETE((p, g, d) -> { + // remove cached guild, if it exists + Guild guild = Guild.decompile(p.getJSONObject("d"), d); + d.getGuildCache().remove(guild); + + return GuildDeleteEvent.class; + }), + /* Sent when a user starts typing in a channel */ + TYPING_START((p, d, g) -> TypingStartEvent.class), + /* Sent when a gateway connection is resumed */ + RESUMED((p, d, g) -> GatewayResumedEvent.class), + + /* AUTOMOD */ + AUTO_MODERATION_RULE_CREATE((p, g, d) -> AutoModRuleCreateEvent.class), + AUTO_MODERATION_RULE_UPDATE((p, g, d) -> AutoModRuleUpdateEvent.class), + AUTO_MODERATION_RULE_DELETE((p, g, d) -> AutoModRuleDeleteEvent.class), + AUTO_MODERATION_ACTION_EXECUTION((p, g, d) -> AutoModExecutionEvent.class), GUILD_MEMBERS_CHUNK((p, g, d) -> { JSONObject payload = p.getJSONObject("d"); @@ -256,32 +284,6 @@ public enum DispatchedEvents { } return null; }), - - GUILD_MEMBER_ADD((p, g, d) -> { - String guildId = p.getJSONObject("d").getString("guild_id"); - d.insertMemberCache(guildId, Member.decompile( - p.getJSONObject("d"), - d, - guildId, - d.getGuildById(guildId) - )); - return GuildMemberAddEvent.class; - }), - GUILD_MEMBER_UPDATE((p, g, d) -> { - String guildId = p.getJSONObject("d").getString("guild_id"); - d.insertMemberCache(guildId, Member.decompile( - p.getJSONObject("d"), - d, - guildId, - d.getGuildById(guildId) - )); - return GuildMemberUpdateEvent.class; - }), - GUILD_MEMBER_REMOVE((p, g, d) -> { - String guildId = p.getJSONObject("d").getString("guild_id"); - d.removeMemberCache(guildId, p.getJSONObject("d").getString("user_id")); - return GuildMemberRemoveEvent.class; - }), /* Unknown */ UNKNOWN((p, g, d) -> null), ;