From 3995bf9992cb690923dc2bd8168b037eb128261f Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 17:50:56 +0100 Subject: [PATCH] add thread archive event --- .../java/cc/fascinated/bat/event/EventListener.java | 4 ++++ .../cc/fascinated/bat/features/logging/LogType.java | 1 + .../features/logging/listeners/ChannelListener.java | 11 +++++++++++ .../java/cc/fascinated/bat/service/EventService.java | 9 +++++++++ 4 files changed, 25 insertions(+) diff --git a/src/main/java/cc/fascinated/bat/event/EventListener.java b/src/main/java/cc/fascinated/bat/event/EventListener.java index 43c68d5..ef1adbf 100644 --- a/src/main/java/cc/fascinated/bat/event/EventListener.java +++ b/src/main/java/cc/fascinated/bat/event/EventListener.java @@ -10,6 +10,7 @@ import lombok.NonNull; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Invite; import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.channel.Channel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; @@ -264,6 +265,9 @@ public interface EventListener { default void onGuildUpdateSplash(@NonNull BatGuild guild, String oldSplashUrl, String newSplashUrl, @NonNull GuildUpdateSplashEvent event) { } + default void onChannelUpdateArchived(@NonNull BatGuild guild, @NonNull Channel channel, boolean isArchived, @NonNull ChannelUpdateArchivedEvent event) { + } + default void onShutdown() { } } diff --git a/src/main/java/cc/fascinated/bat/features/logging/LogType.java b/src/main/java/cc/fascinated/bat/features/logging/LogType.java index f6fdab4..bdca383 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/LogType.java +++ b/src/main/java/cc/fascinated/bat/features/logging/LogType.java @@ -43,6 +43,7 @@ public enum LogType { VOICE_CHANNEL_JOIN(LogCategory.CHANNEL), VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL), CHANNEL_CONFIGURATION(LogCategory.CHANNEL), + THREAD_ARCHIVE(LogCategory.CHANNEL), /** * Guild Events 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 0a8811d..dc03a80 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 @@ -14,6 +14,7 @@ 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.Channel; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; @@ -289,4 +290,14 @@ public class ChannelListener implements EventListener { .build()) .build()); } + + @Override + public void onChannelUpdateArchived(@NonNull BatGuild guild, @NonNull Channel channel, boolean isArchived, @NonNull ChannelUpdateArchivedEvent event) { + log.info("Thread \"{}\" was {} in guild \"{}\"", channel.getName(), isArchived ? "archived" : "unarchived", guild.getName()); + logFeature.sendLog(guild, LogType.THREAD_ARCHIVE, EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("Thread %s".formatted(isArchived ? "Archived" : "Unarchived")) + .appendLine("Channel: %s".formatted(channel.getAsMention()), 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 9514aaf..b2d92e2 100644 --- a/src/main/java/cc/fascinated/bat/service/EventService.java +++ b/src/main/java/cc/fascinated/bat/service/EventService.java @@ -732,4 +732,13 @@ public class EventService extends ListenerAdapter { listener.onGuildUpdateSplash(guild, event.getOldSplashUrl(), event.getNewSplashUrl(), event); } } + + @Override + public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { + BatGuild guild = guildService.getGuild(event.getGuild().getId()); + + for (EventListener listener : LISTENERS) { + listener.onChannelUpdateArchived(guild, event.getEntity(), event.getNewValue(), event); + } + } }