diff --git a/src/main/java/cc/fascinated/bat/event/EventListener.java b/src/main/java/cc/fascinated/bat/event/EventListener.java index 6e18023..759cd1d 100644 --- a/src/main/java/cc/fascinated/bat/event/EventListener.java +++ b/src/main/java/cc/fascinated/bat/event/EventListener.java @@ -178,6 +178,9 @@ public interface EventListener { default void onChannelUpdateRegion(@NonNull BatGuild guild, @NonNull ChannelUpdateRegionEvent event) { } + default void onChannelUpdateSlowmode(@NonNull BatGuild guild, @NonNull ChannelUpdateSlowmodeEvent 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 31d67a5..4635dbc 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 @@ -1,9 +1,6 @@ package cc.fascinated.bat.features.logging.listeners; -import cc.fascinated.bat.common.EmbedDescriptionBuilder; -import cc.fascinated.bat.common.EmbedUtils; -import cc.fascinated.bat.common.EnumUtils; -import cc.fascinated.bat.common.NumberFormatter; +import cc.fascinated.bat.common.*; import cc.fascinated.bat.event.EventListener; import cc.fascinated.bat.features.logging.LogFeature; import cc.fascinated.bat.features.logging.LogType; @@ -180,7 +177,10 @@ public class ChannelListener implements EventListener { log.info("{} \"{}\" topic was updated to {} in guild \"{}\"", type, newValue, oldValue, guild.getName()); EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("%s Topic Updated".formatted(type)); description.appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true); - description.appendLine("Topic: `%s` -> `%s`".formatted(oldValue, newValue), true); + description.appendLine("Topic: `%s` -> `%s`".formatted( + oldValue == null ? "No Topic" : oldValue, + newValue == null ? "No Topic" : newValue + ), true); logFeature.sendLog(guild, LogType.CHANNEL_CONFIGURATION, EmbedUtils.successEmbed() .setDescription(description.build()) .build()); @@ -272,4 +272,21 @@ public class ChannelListener implements EventListener { .build()) .build()); } + + @Override + public void onChannelUpdateSlowmode(@NonNull BatGuild guild, @NonNull ChannelUpdateSlowmodeEvent event) { + if (Objects.equals(event.getOldValue(), event.getNewValue()) || event.getOldValue() == null || event.getNewValue() == null) { + return; + } + String oldSlowmode = event.getOldValue() == 0 ? "Disabled" : TimeUtils.format(event.getOldValue() * 1000); + String newSlowmode = event.getNewValue() == 0 ? "Disabled" : TimeUtils.format(event.getNewValue() * 1000); + + log.info("Text channel \"{}\" slowmode was updated to {} in guild \"{}\"", event.getChannel().getName(), newSlowmode, guild.getName()); + logFeature.sendLog(guild, LogType.CHANNEL_CONFIGURATION, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Channel Slowmode Updated") + .appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true) + .appendLine("Slowmode: `%s` -> `%s`".formatted(oldSlowmode, newSlowmode), 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 02b66b6..335dfab 100644 --- a/src/main/java/cc/fascinated/bat/service/EventService.java +++ b/src/main/java/cc/fascinated/bat/service/EventService.java @@ -507,4 +507,13 @@ public class EventService extends ListenerAdapter { listener.onChannelUpdateRegion(guild, event); } } + + @Override + public void onChannelUpdateSlowmode(@NotNull ChannelUpdateSlowmodeEvent event) { + BatGuild guild = guildService.getGuild(event.getGuild().getId()); + + for (EventListener listener : LISTENERS) { + listener.onChannelUpdateSlowmode(guild, event); + } + } }