From 6eca92b4cfb043506634bdac910e2e7a9ea2478e Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 2 Jul 2024 18:58:50 +0100 Subject: [PATCH] add member nickname update log --- .../fascinated/bat/features/logging/LogType.java | 3 ++- .../features/logging/command/SetSubCommand.java | 13 ++++++++++--- .../features/logging/listeners/MemberListener.java | 14 ++++++++++++++ .../logging/listeners/MessageListener.java | 1 - 4 files changed, 26 insertions(+), 5 deletions(-) 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 7b4e7d0..78555f2 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/LogType.java +++ b/src/main/java/cc/fascinated/bat/features/logging/LogType.java @@ -21,7 +21,8 @@ public enum LogType { * Member Events */ MEMBER_JOIN(LogCategory.MEMBER, "Member Join"), - MEMBER_LEAVE(LogCategory.MEMBER, "Member Leave"); + MEMBER_LEAVE(LogCategory.MEMBER, "Member Leave"), + MEMBER_NICKNAME_CHANGE(LogCategory.MEMBER, "Member Nickname Change"); /** * The category of the log type diff --git a/src/main/java/cc/fascinated/bat/features/logging/command/SetSubCommand.java b/src/main/java/cc/fascinated/bat/features/logging/command/SetSubCommand.java index 478e3d7..8965591 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/command/SetSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/logging/command/SetSubCommand.java @@ -50,9 +50,16 @@ public class SetSubCommand extends BatSubCommand { EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel"); description.appendLine("Successfully set the log channel for all log types to %s".formatted(targetChannel.getAsMention()), false); description.emptyLine(); - for (LogType logType : LogType.values()) { - description.appendLine(logType.getName(), true); - profile.setLogChannel(logType, targetChannel); + for (int i = 0; i < LogCategory.values().length; i++) { + LogCategory category = LogCategory.values()[i]; + if (i != 0) { + description.emptyLine(); + } + description.appendLine("**__%s__**".formatted(category.getName()), false); + for (LogType logType : LogType.getLogTypesByCategory(category.getName())) { + description.appendLine(logType.getName(), true); + profile.setLogChannel(logType, targetChannel); + } } event.replyEmbeds(EmbedUtils.successEmbed() diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/MemberListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/MemberListener.java index edb7b80..d0da725 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/MemberListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/MemberListener.java @@ -10,6 +10,7 @@ import cc.fascinated.bat.model.BatUser; import lombok.NonNull; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent; +import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; @@ -51,4 +52,17 @@ public class MemberListener implements EventListener { .build()) .build()); } + + @Override + public void onGuildMemberUpdateNickname(@NonNull BatGuild guild, @NonNull BatUser user, String oldName, String newName, @NonNull GuildMemberUpdateNicknameEvent event) { + if (user.getDiscordUser().isBot()) return; + + logFeature.sendLog(guild, LogType.MEMBER_NICKNAME_CHANGE, EmbedUtils.genericEmbed() + .setDescription(new EmbedDescriptionBuilder("Member Nickname Changed") + .appendLine("Member: %s".formatted(user.getDiscordUser().getAsMention()), true) + .appendLine("Old Nickname: `%s`".formatted(oldName == null ? user.getName() : oldName), true) + .appendLine("New Nickname: `%s`".formatted(newName == null ? "Removed Nickname" : newName), true) + .build()) + .build()); + } } diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/MessageListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/MessageListener.java index b8ec729..abd83c5 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/MessageListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/MessageListener.java @@ -9,7 +9,6 @@ import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.DiscordMessage; import lombok.NonNull; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import org.springframework.beans.factory.annotation.Autowired;