From a7af4108c68d9c89e1ff6a5a0abbeb375fc61a52 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 5 Jul 2024 21:38:21 +0100 Subject: [PATCH] switch voice channel log --- .../fascinated/bat/features/logging/LogFeature.java | 2 +- .../cc/fascinated/bat/features/logging/LogType.java | 1 + .../features/logging/listeners/ChannelListener.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/cc/fascinated/bat/features/logging/LogFeature.java b/src/main/java/cc/fascinated/bat/features/logging/LogFeature.java index 6f22bc7..bf77163 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/LogFeature.java +++ b/src/main/java/cc/fascinated/bat/features/logging/LogFeature.java @@ -58,7 +58,7 @@ public class LogFeature extends Feature { if (content == null) { return "No content"; } - if (content.contains("`")) { // Workaround for markdown formatting + if (content.contains("`")) { // Workaround for Markdown formatting content = content.replace("`", "'"); } // More than 512 characters or is more than 4 lines 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 bdca383..d50fd7e 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/LogType.java +++ b/src/main/java/cc/fascinated/bat/features/logging/LogType.java @@ -42,6 +42,7 @@ public enum LogType { CHANNEL_DELETE(LogCategory.CHANNEL), VOICE_CHANNEL_JOIN(LogCategory.CHANNEL), VOICE_CHANNEL_LEAVE(LogCategory.CHANNEL), + VOICE_CHANNEL_SWITCH(LogCategory.CHANNEL), CHANNEL_CONFIGURATION(LogCategory.CHANNEL), THREAD_ARCHIVE(LogCategory.CHANNEL), 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 dc03a80..0635947 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 @@ -108,6 +108,7 @@ public class ChannelListener implements EventListener { @Override public void onGuildVoiceUpdate(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GenericGuildVoiceEvent event) { AudioChannelUnion channel = event.getVoiceState().getChannel(); + VoiceChannel oldChannel = lastVoiceChannel.get(user); if (channel != null) { VoiceChannel voiceChannel = channel.asVoiceChannel(); lastVoiceChannel.put(user, voiceChannel); @@ -120,6 +121,18 @@ public class ChannelListener implements EventListener { if (!joined) { lastVoiceChannel.remove(user); } + + // User switched channels + if (oldChannel != null && !oldChannel.equals(voiceChannel)) { + log.info("User \"{}\" switched from voice channel \"{}\" to \"{}\" in guild \"{}\"", user.getName(), oldChannel.getName(), voiceChannel.getName(), guild.getName()); + String switchDescription = new EmbedDescriptionBuilder("Member Switched Voice Channel") + .appendLine("User: %s".formatted(user.getDiscordUser().getAsMention()), true) + .appendLine("Channel: %s -> %s".formatted(oldChannel.getAsMention(), voiceChannel.getAsMention()), true) + .build(); + logFeature.sendLog(guild, LogType.VOICE_CHANNEL_SWITCH, EmbedUtils.successEmbed().setDescription(switchDescription).build()); + return; + } + log.info("User \"{}\" {} voice channel \"{}\" in guild \"{}\"", user.getName(), joined ? "joined" : "left", voiceChannel.getName(), guild.getName()); String description = new EmbedDescriptionBuilder("Member %s Voice Channel".formatted(joined ? "Joined" : "Left")) .appendLine("User: %s".formatted(user.getDiscordUser().getAsMention()), true)