add channel region changing logging
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 41s

This commit is contained in:
Lee 2024-07-04 10:49:21 +01:00
parent 26b7b7158a
commit 14ff692b87
3 changed files with 32 additions and 0 deletions

View File

@ -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() {
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}
}