diff --git a/src/main/java/cc/fascinated/bat/event/EventListener.java b/src/main/java/cc/fascinated/bat/event/EventListener.java index 0e48d9e..6e18023 100644 --- a/src/main/java/cc/fascinated/bat/event/EventListener.java +++ b/src/main/java/cc/fascinated/bat/event/EventListener.java @@ -175,6 +175,9 @@ public interface EventListener { default void onChannelUpdateUserLimit(@NonNull BatGuild guild, @NonNull ChannelUpdateUserLimitEvent event) { } + default void onChannelUpdateRegion(@NonNull BatGuild guild, @NonNull ChannelUpdateRegionEvent 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 77414d1..31d67a5 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 @@ -15,6 +15,7 @@ import jakarta.annotation.PostConstruct; import lombok.NonNull; import lombok.extern.log4j.Log4j2; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.Region; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; @@ -252,4 +253,23 @@ public class ChannelListener implements EventListener { .setDescription(description.build()) .build()); } + + @Override + public void onChannelUpdateRegion(@NonNull BatGuild guild, @NonNull ChannelUpdateRegionEvent event) { + if (Objects.equals(event.getOldValue(), event.getNewValue()) || event.getOldValue() == null || event.getNewValue() == null) { + return; + } + + String newRegion = event.getNewValue() == Region.UNKNOWN ? "Automatic" : event.getNewValue().getName(); + log.info("Channel \"{}\" region was updated to \"{}\" in guild \"{}\"", event.getChannel().getName(), newRegion, guild.getName()); + logFeature.sendLog(guild, LogType.CHANNEL_CONFIGURATION, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Channel Region Updated") + .appendLine("Channel: %s".formatted(event.getChannel().getAsMention()), true) + .appendLine("Region: `%s` -> `%s`".formatted( + event.getOldValue() == Region.UNKNOWN ? "Automatic" : event.getOldValue().getName(), + newRegion + ), 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 649a3c5..02b66b6 100644 --- a/src/main/java/cc/fascinated/bat/service/EventService.java +++ b/src/main/java/cc/fascinated/bat/service/EventService.java @@ -498,4 +498,13 @@ public class EventService extends ListenerAdapter { listener.onChannelUpdateUserLimit(guild, event); } } + + @Override + public void onChannelUpdateRegion(@NotNull ChannelUpdateRegionEvent event) { + BatGuild guild = guildService.getGuild(event.getGuild().getId()); + + for (EventListener listener : LISTENERS) { + listener.onChannelUpdateRegion(guild, event); + } + } }