From 26b7b7158abe1ed57890966c198b5d95fab75c5c Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 10:40:51 +0100 Subject: [PATCH] add role color and icon update, and add channel nsfw and user limit update logging --- .../fascinated/bat/common/HexColorUtils.java | 10 ++ .../fascinated/bat/event/EventListener.java | 19 ++- .../logging/listeners/ChannelListener.java | 54 +++++-- .../logging/listeners/EmojiListener.java | 63 ++++++++ .../logging/listeners/GuildListener.java | 110 +------------ .../logging/listeners/RoleListener.java | 146 ++++++++++++++++++ .../fascinated/bat/service/EventService.java | 44 +++++- 7 files changed, 321 insertions(+), 125 deletions(-) create mode 100644 src/main/java/cc/fascinated/bat/features/logging/listeners/EmojiListener.java create mode 100644 src/main/java/cc/fascinated/bat/features/logging/listeners/RoleListener.java diff --git a/src/main/java/cc/fascinated/bat/common/HexColorUtils.java b/src/main/java/cc/fascinated/bat/common/HexColorUtils.java index edee965..c52f37a 100644 --- a/src/main/java/cc/fascinated/bat/common/HexColorUtils.java +++ b/src/main/java/cc/fascinated/bat/common/HexColorUtils.java @@ -45,4 +45,14 @@ public class HexColorUtils { int rgb = Integer.parseInt(hex, 16); return new Color(rgb); } + + /** + * Converts a Color object to a hex color + * + * @param color the Color object to convert + * @return the hex color + */ + public static String colorToHex(Color color) { + return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue()); + } } diff --git a/src/main/java/cc/fascinated/bat/event/EventListener.java b/src/main/java/cc/fascinated/bat/event/EventListener.java index 04c2f54..0e48d9e 100644 --- a/src/main/java/cc/fascinated/bat/event/EventListener.java +++ b/src/main/java/cc/fascinated/bat/event/EventListener.java @@ -12,10 +12,7 @@ import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateBitrateEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateTopicEvent; -import net.dv8tion.jda.api.events.channel.update.GenericChannelUpdateEvent; +import net.dv8tion.jda.api.events.channel.update.*; import net.dv8tion.jda.api.events.emoji.EmojiAddedEvent; import net.dv8tion.jda.api.events.emoji.EmojiRemovedEvent; import net.dv8tion.jda.api.events.emoji.update.EmojiUpdateNameEvent; @@ -39,6 +36,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import net.dv8tion.jda.api.events.role.RoleCreateEvent; import net.dv8tion.jda.api.events.role.RoleDeleteEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateColorEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateIconEvent; import net.dv8tion.jda.api.events.role.update.RoleUpdateNameEvent; import net.dv8tion.jda.api.events.role.update.RoleUpdatePermissionsEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent; @@ -164,6 +163,18 @@ public interface EventListener { default void onChannelUpdateBitrate(@NonNull BatGuild guild, @NonNull ChannelUpdateBitrateEvent event) { } + default void onRoleUpdateColor(@NonNull BatGuild guild, @NonNull RoleUpdateColorEvent event) { + } + + default void onRoleUpdateIcon(@NonNull BatGuild guild, @NonNull RoleUpdateIconEvent event) { + } + + default void onChannelUpdateNSFW(@NonNull BatGuild guild, @NonNull ChannelUpdateNSFWEvent event) { + } + + default void onChannelUpdateUserLimit(@NonNull BatGuild guild, @NonNull ChannelUpdateUserLimitEvent event) { + } + default void onShutdown() { } } diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/ChannelListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/ChannelListener.java index 3e994a1..77414d1 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/ChannelListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/ChannelListener.java @@ -23,9 +23,7 @@ import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; import net.dv8tion.jda.api.entities.channel.unions.ChannelUnion; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateBitrateEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateTopicEvent; +import net.dv8tion.jda.api.events.channel.update.*; import net.dv8tion.jda.api.events.guild.override.GenericPermissionOverrideEvent; import net.dv8tion.jda.api.events.guild.voice.GenericGuildVoiceEvent; import org.springframework.beans.factory.annotation.Autowired; @@ -70,6 +68,17 @@ public class ChannelListener implements EventListener { log.info("Found {} users in a voice channel", lastVoiceChannel.size()); } + /** + * Formats the channel type + * + * @param channel - the channel + * @return the formatted channel type + */ + public String formatChannelType(ChannelUnion channel) { + return (channel.getType() == ChannelType.TEXT || channel.getType() == ChannelType.VOICE) ? EnumUtils.getEnumName(channel.getType()) + " Channel" + : EnumUtils.getEnumName(channel.getType()); + } + @Override public void onChannelCreate(@NonNull BatGuild guild, @NonNull ChannelCreateEvent event) { ChannelUnion channel = event.getChannel(); @@ -212,14 +221,35 @@ public class ChannelListener implements EventListener { .build()); } - /** - * Formats the channel type - * - * @param channel - the channel - * @return the formatted channel type - */ - public String formatChannelType(ChannelUnion channel) { - return (channel.getType() == ChannelType.TEXT || channel.getType() == ChannelType.VOICE) ? EnumUtils.getEnumName(channel.getType()) + " Channel" - : EnumUtils.getEnumName(channel.getType()); + @Override + public void onChannelUpdateNSFW(@NonNull BatGuild guild, @NonNull ChannelUpdateNSFWEvent event) { + logFeature.sendLog(guild, LogType.CHANNEL_CONFIGURATION, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Channel NSFW Updated") + .appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true) + .appendLine("NSFW: `%s` -> `%s`".formatted( + Boolean.TRUE.equals(event.getOldValue()) ? "Yes" : "No", + Boolean.TRUE.equals(event.getNewValue()) ? "Yes" : "No" + ), true) + .build()) + .build()); + } + + @Override + public void onChannelUpdateUserLimit(@NonNull BatGuild guild, @NonNull ChannelUpdateUserLimitEvent event) { + if (Objects.equals(event.getOldValue(), event.getNewValue()) || event.getOldValue() == null || event.getNewValue() == null) { + return; + } + + VoiceChannel channel = event.getChannel().asVoiceChannel(); + log.info("Voice channel \"{}\" user limit was updated to {} in guild \"{}\"", channel.getName(), event.getNewValue(), guild.getName()); + EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Voice Channel User Limit Updated") + .appendLine("Channel: %s".formatted(channel.getAsMention()), true) + .appendLine("User Limit: `%s` -> `%s`".formatted( + event.getOldValue() == 0 ? "Unlimited" : NumberFormatter.format(event.getOldValue()), + event.getNewValue() == 0 ? "Unlimited" : NumberFormatter.format(event.getNewValue()) + ), true); + logFeature.sendLog(guild, LogType.CHANNEL_CONFIGURATION, EmbedUtils.successEmbed() + .setDescription(description.build()) + .build()); } } diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/EmojiListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/EmojiListener.java new file mode 100644 index 0000000..d292ca0 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/EmojiListener.java @@ -0,0 +1,63 @@ +package cc.fascinated.bat.features.logging.listeners; + +import cc.fascinated.bat.common.EmbedDescriptionBuilder; +import cc.fascinated.bat.common.EmbedUtils; +import cc.fascinated.bat.event.EventListener; +import cc.fascinated.bat.features.logging.LogFeature; +import cc.fascinated.bat.features.logging.LogType; +import cc.fascinated.bat.model.BatGuild; +import lombok.NonNull; +import lombok.extern.log4j.Log4j2; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.events.emoji.EmojiAddedEvent; +import net.dv8tion.jda.api.events.emoji.EmojiRemovedEvent; +import net.dv8tion.jda.api.events.emoji.update.EmojiUpdateNameEvent; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Fascinated (fascinated7) + */ +@Component +@Log4j2(topic = "Logging - Emoji Listener") +public class EmojiListener implements EventListener { + private final LogFeature logFeature; + + @Autowired + public EmojiListener(@NonNull LogFeature logFeature) { + this.logFeature = logFeature; + } + + @Override + public void onEmojiAdd(@NonNull BatGuild guild, @NonNull Emoji emoji, @NonNull EmojiAddedEvent event) { + log.info("Emoji \"{}\" was added in guild \"{}\"", emoji.getName(), guild.getName()); + logFeature.sendLog(guild, LogType.EMOJI_ADD, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Emoji Added") + .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) + .appendLine("Name: `%s`".formatted(emoji.getName()), true) + .build()) + .build()); + } + + @Override + public void onEmojiRemove(@NonNull BatGuild guild, @NonNull Emoji emoji, @NonNull EmojiRemovedEvent event) { + log.info("Emoji \"{}\" was removed in guild \"{}\"", emoji.getName(), guild.getName()); + logFeature.sendLog(guild, LogType.EMOJI_REMOVE, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Emoji Removed") + .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) + .appendLine("Name: `%s`".formatted(emoji.getName()), true) + .build()) + .build()); + } + + @Override + public void onEmojiRename(@NonNull BatGuild guild, @NonNull Emoji emoji, @NonNull String oldName, @NonNull String newName, @NonNull EmojiUpdateNameEvent event) { + log.info("Emoji \"{}\" was renamed to \"{}\" in guild \"{}\"", oldName, newName, guild.getName()); + logFeature.sendLog(guild, LogType.EMOJI_NAME_UPDATED, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Emoji Renamed") + .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) + .appendLine("Name: `%s` -> `%s`".formatted(oldName, newName), true) + .build()) + .build()); + } +} diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java index 6d6809b..a79c59e 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/GuildListener.java @@ -2,6 +2,7 @@ package cc.fascinated.bat.features.logging.listeners; import cc.fascinated.bat.common.EmbedDescriptionBuilder; import cc.fascinated.bat.common.EmbedUtils; +import cc.fascinated.bat.common.HexColorUtils; import cc.fascinated.bat.event.EventListener; import cc.fascinated.bat.features.logging.LogFeature; import cc.fascinated.bat.features.logging.LogType; @@ -11,6 +12,7 @@ import lombok.extern.log4j.Log4j2; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Invite; import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.RoleIcon; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.emoji.EmojiAddedEvent; import net.dv8tion.jda.api.events.emoji.EmojiRemovedEvent; @@ -18,12 +20,15 @@ import net.dv8tion.jda.api.events.emoji.update.EmojiUpdateNameEvent; import net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent; import net.dv8tion.jda.api.events.role.RoleCreateEvent; import net.dv8tion.jda.api.events.role.RoleDeleteEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateColorEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateIconEvent; import net.dv8tion.jda.api.events.role.update.RoleUpdateNameEvent; import net.dv8tion.jda.api.events.role.update.RoleUpdatePermissionsEvent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; +import java.awt.*; import java.util.EnumSet; /** @@ -58,109 +63,4 @@ public class GuildListener implements EventListener { .build())); }); } - - @Override - public void onEmojiAdd(@NonNull BatGuild guild, @NonNull Emoji emoji, @NonNull EmojiAddedEvent event) { - log.info("Emoji \"{}\" was added in guild \"{}\"", emoji.getName(), guild.getName()); - logFeature.sendLog(guild, LogType.EMOJI_ADD, EmbedUtils.successEmbed() - .setDescription(new EmbedDescriptionBuilder("Emoji Added") - .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) - .appendLine("Name: `%s`".formatted(emoji.getName()), true) - .build()) - .build()); - } - - @Override - public void onEmojiRemove(@NonNull BatGuild guild, @NonNull Emoji emoji, @NonNull EmojiRemovedEvent event) { - log.info("Emoji \"{}\" was removed in guild \"{}\"", emoji.getName(), guild.getName()); - logFeature.sendLog(guild, LogType.EMOJI_REMOVE, EmbedUtils.successEmbed() - .setDescription(new EmbedDescriptionBuilder("Emoji Removed") - .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) - .appendLine("Name: `%s`".formatted(emoji.getName()), true) - .build()) - .build()); - } - - @Override - public void onEmojiRename(@NonNull BatGuild guild, @NonNull Emoji emoji, @NonNull String oldName, @NonNull String newName, @NonNull EmojiUpdateNameEvent event) { - log.info("Emoji \"{}\" was renamed to \"{}\" in guild \"{}\"", oldName, newName, guild.getName()); - logFeature.sendLog(guild, LogType.EMOJI_NAME_UPDATED, EmbedUtils.successEmbed() - .setDescription(new EmbedDescriptionBuilder("Emoji Renamed") - .appendLine("Emoji: %s".formatted(emoji.getFormatted()), true) - .appendLine("Name: `%s` -> `%s`".formatted(oldName, newName), true) - .build()) - .build()); - } - - @Override - public void onRoleUpdatePermissions(@NonNull BatGuild guild, @NonNull RoleUpdatePermissionsEvent event) { - log.info("Role \"{}\" permissions were updated in guild \"{}\"", event.getRole().getName(), guild.getName()); - EnumSet oldPermissions = event.getOldValue(); - EnumSet newPermissions = event.getNewValue(); - - StringBuilder allowedPermissions = new StringBuilder(); - for (Permission permission : newPermissions) { - if (!oldPermissions.contains(permission)) { - allowedPermissions.append("`").append(permission.getName()).append("`, "); - } - } - StringBuilder deniedPermissions = new StringBuilder(); - for (Permission permission : oldPermissions) { - if (!newPermissions.contains(permission)) { - deniedPermissions.append("`").append(permission.getName()).append("`, "); - } - } - - EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Role Permissions Updated") - .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true); - if (!allowedPermissions.isEmpty()) { - description.appendLine("Allowed Permissions: %s".formatted(allowedPermissions.substring(0, allowedPermissions.length() - 2)), true); - } - if (!deniedPermissions.isEmpty()) { - description.appendLine("Denied Permissions: %s".formatted(deniedPermissions.substring(0, deniedPermissions.length() - 2)), true); - } - - logFeature.sendLog(guild, LogType.ROLE_PERMISSIONS_UPDATED, EmbedUtils.successEmbed() - .setDescription(description.build()) - .build()); - } - - @Override - public void onRoleCreate(@NonNull BatGuild guild, @NonNull RoleCreateEvent event) { - Role role = event.getRole(); - log.info("Role \"{}\" was created in guild \"{}\"", role.getName(), guild.getName()); - - logFeature.sendLog(guild, LogType.ROLE_CREATE, EmbedUtils.successEmbed() - .setDescription(new EmbedDescriptionBuilder("Role Created") - .appendLine("Role: %s".formatted(role.getAsMention()), true) - .appendLine("Color: %s".formatted(role.getColor() == null ? "Default" : role.getColor()), true) - .appendLine("Position: `%s`".formatted(role.getPosition()), true) - .build()) - .build()); - } - - @Override - public void onRoleDelete(@NonNull BatGuild guild, @NonNull RoleDeleteEvent event) { - log.info("Role \"{}\" was deleted in guild \"{}\"", event.getRole().getName(), guild.getName()); - logFeature.sendLog(guild, LogType.ROLE_DELETE, EmbedUtils.successEmbed() - .setDescription(new EmbedDescriptionBuilder("Role Deleted") - .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true) - .appendLine("Color: %s".formatted(event.getRole().getColor() == null ? "Default" : event.getRole().getColor()), true) - .appendLine("Position: `%s`".formatted(event.getRole().getPosition()), true) - .build()) - .build()); - } - - @Override - public void onRoleUpdateName(@NonNull BatGuild guild, @NonNull RoleUpdateNameEvent event) { - String oldName = event.getOldName(); - String newName = event.getNewName(); - log.info("Role \"{}\" was renamed to \"{}\" in guild \"{}\"", oldName, newName, guild.getName()); - logFeature.sendLog(guild, LogType.ROLE_CONFIGURATION, EmbedUtils.successEmbed() - .setDescription(new EmbedDescriptionBuilder("Role Renamed") - .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true) - .appendLine("Name: `%s` -> `%s`".formatted(oldName, newName), true) - .build()) - .build()); - } } diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/RoleListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/RoleListener.java new file mode 100644 index 0000000..cdf3919 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/RoleListener.java @@ -0,0 +1,146 @@ +package cc.fascinated.bat.features.logging.listeners; + +import cc.fascinated.bat.common.EmbedDescriptionBuilder; +import cc.fascinated.bat.common.EmbedUtils; +import cc.fascinated.bat.common.HexColorUtils; +import cc.fascinated.bat.event.EventListener; +import cc.fascinated.bat.features.logging.LogFeature; +import cc.fascinated.bat.features.logging.LogType; +import cc.fascinated.bat.model.BatGuild; +import lombok.NonNull; +import lombok.extern.log4j.Log4j2; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.RoleIcon; +import net.dv8tion.jda.api.events.role.RoleCreateEvent; +import net.dv8tion.jda.api.events.role.RoleDeleteEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateColorEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateIconEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateNameEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdatePermissionsEvent; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.annotation.AccessType; +import org.springframework.stereotype.Component; + +import java.awt.*; +import java.util.EnumSet; + +/** + * @author Fascinated (fascinated7) + */ +@Component +@Log4j2(topic = "Logging - Role Listener") +public class RoleListener implements EventListener { + private final LogFeature logFeature; + + @Autowired + public RoleListener(@NonNull LogFeature logFeature) { + this.logFeature = logFeature; + } + + @Override + public void onRoleUpdatePermissions(@NonNull BatGuild guild, @NonNull RoleUpdatePermissionsEvent event) { + log.info("Role \"{}\" permissions were updated in guild \"{}\"", event.getRole().getName(), guild.getName()); + EnumSet oldPermissions = event.getOldValue(); + EnumSet newPermissions = event.getNewValue(); + + StringBuilder allowedPermissions = new StringBuilder(); + for (Permission permission : newPermissions) { + if (!oldPermissions.contains(permission)) { + allowedPermissions.append("`").append(permission.getName()).append("`, "); + } + } + StringBuilder deniedPermissions = new StringBuilder(); + for (Permission permission : oldPermissions) { + if (!newPermissions.contains(permission)) { + deniedPermissions.append("`").append(permission.getName()).append("`, "); + } + } + + EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Role Permissions Updated") + .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true); + if (!allowedPermissions.isEmpty()) { + description.appendLine("Allowed Permissions: %s".formatted(allowedPermissions.substring(0, allowedPermissions.length() - 2)), true); + } + if (!deniedPermissions.isEmpty()) { + description.appendLine("Denied Permissions: %s".formatted(deniedPermissions.substring(0, deniedPermissions.length() - 2)), true); + } + + logFeature.sendLog(guild, LogType.ROLE_PERMISSIONS_UPDATED, EmbedUtils.successEmbed() + .setDescription(description.build()) + .build()); + } + + @Override + public void onRoleCreate(@NonNull BatGuild guild, @NonNull RoleCreateEvent event) { + Role role = event.getRole(); + log.info("Role \"{}\" was created in guild \"{}\"", role.getName(), guild.getName()); + + logFeature.sendLog(guild, LogType.ROLE_CREATE, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Role Created") + .appendLine("Role: %s".formatted(role.getAsMention()), true) + .appendLine("Color: %s".formatted(role.getColor() == null ? "Default" : role.getColor()), true) + .appendLine("Position: `%s`".formatted(role.getPosition()), true) + .build()) + .build()); + } + + @Override + public void onRoleDelete(@NonNull BatGuild guild, @NonNull RoleDeleteEvent event) { + log.info("Role \"{}\" was deleted in guild \"{}\"", event.getRole().getName(), guild.getName()); + logFeature.sendLog(guild, LogType.ROLE_DELETE, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Role Deleted") + .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true) + .appendLine("Color: %s".formatted(event.getRole().getColor() == null ? "Default" : event.getRole().getColor()), true) + .appendLine("Position: `%s`".formatted(event.getRole().getPosition()), true) + .build()) + .build()); + } + + @Override + public void onRoleUpdateName(@NonNull BatGuild guild, @NonNull RoleUpdateNameEvent event) { + String oldName = event.getOldName(); + String newName = event.getNewName(); + log.info("Role \"{}\" was renamed to \"{}\" in guild \"{}\"", oldName, newName, guild.getName()); + logFeature.sendLog(guild, LogType.ROLE_CONFIGURATION, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Role Renamed") + .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true) + .appendLine("Name: `%s` -> `%s`".formatted(oldName, newName), true) + .build()) + .build()); + } + + @Override + public void onRoleUpdateColor(@NonNull BatGuild guild, @NonNull RoleUpdateColorEvent event) { + Color oldColor = event.getOldColor(); + Color newColor = event.getNewColor(); + + log.info("Role \"{}\" color was updated in guild \"{}\"", event.getRole().getName(), guild.getName()); + logFeature.sendLog(guild, LogType.ROLE_CONFIGURATION, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Role Color Updated") + .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true) + .appendLine("Color: `%s` -> `%s`".formatted( + oldColor == null ? "Default" : HexColorUtils.colorToHex(oldColor), + newColor == null ? "Default" : HexColorUtils.colorToHex(newColor) + ), true) + .build()) + .build()); + } + + @Override + public void onRoleUpdateIcon(@NonNull BatGuild guild, @NonNull RoleUpdateIconEvent event) { + RoleIcon oldIcon = event.getOldIcon(); + RoleIcon newIcon = event.getNewIcon(); + + log.info("Role \"{}\" icon was updated in guild \"{}\"", event.getRole().getName(), guild.getName()); + logFeature.sendLog(guild, LogType.ROLE_CONFIGURATION, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Role Icon Updated") + .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true) + .appendLine("Icon: `%s` -> `%s`".formatted( + oldIcon == null ? "None" : oldIcon.getEmoji(), + newIcon == null ? "None" : newIcon.getEmoji() + ), true) + .build()) + .build()); + } +} diff --git a/src/main/java/cc/fascinated/bat/service/EventService.java b/src/main/java/cc/fascinated/bat/service/EventService.java index 283b8bf..649a3c5 100644 --- a/src/main/java/cc/fascinated/bat/service/EventService.java +++ b/src/main/java/cc/fascinated/bat/service/EventService.java @@ -10,10 +10,7 @@ import lombok.extern.log4j.Log4j2; import net.dv8tion.jda.api.entities.Invite; import net.dv8tion.jda.api.events.channel.ChannelCreateEvent; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateBitrateEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNSFWEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateNameEvent; -import net.dv8tion.jda.api.events.channel.update.ChannelUpdateTopicEvent; +import net.dv8tion.jda.api.events.channel.update.*; import net.dv8tion.jda.api.events.emoji.EmojiAddedEvent; import net.dv8tion.jda.api.events.emoji.EmojiRemovedEvent; import net.dv8tion.jda.api.events.emoji.update.EmojiUpdateNameEvent; @@ -36,6 +33,8 @@ import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.role.RoleCreateEvent; import net.dv8tion.jda.api.events.role.RoleDeleteEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateColorEvent; +import net.dv8tion.jda.api.events.role.update.RoleUpdateIconEvent; import net.dv8tion.jda.api.events.role.update.RoleUpdateNameEvent; import net.dv8tion.jda.api.events.role.update.RoleUpdatePermissionsEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent; @@ -445,6 +444,25 @@ public class EventService extends ListenerAdapter { } } + @Override + public void onRoleUpdateColor(@NotNull RoleUpdateColorEvent event) { + BatGuild guild = guildService.getGuild(event.getGuild().getId()); + + for (EventListener listener : LISTENERS) { + listener.onRoleUpdateColor(guild, event); + } + } + + + @Override + public void onRoleUpdateIcon(@NotNull RoleUpdateIconEvent event) { + BatGuild guild = guildService.getGuild(event.getGuild().getId()); + + for (EventListener listener : LISTENERS) { + listener.onRoleUpdateIcon(guild, event); + } + } + @Override public void onChannelUpdateTopic(@NotNull ChannelUpdateTopicEvent event) { BatGuild guild = guildService.getGuild(event.getGuild().getId()); @@ -462,4 +480,22 @@ public class EventService extends ListenerAdapter { listener.onChannelUpdateBitrate(guild, event); } } + + @Override + public void onChannelUpdateNSFW(@NotNull ChannelUpdateNSFWEvent event) { + BatGuild guild = guildService.getGuild(event.getGuild().getId()); + + for (EventListener listener : LISTENERS) { + listener.onChannelUpdateNSFW(guild, event); + } + } + + @Override + public void onChannelUpdateUserLimit(@NotNull ChannelUpdateUserLimitEvent event) { + BatGuild guild = guildService.getGuild(event.getGuild().getId()); + + for (EventListener listener : LISTENERS) { + listener.onChannelUpdateUserLimit(guild, event); + } + } }