From c284bb8a7ffdc4c27282578f1112334c7848d0a8 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 09:41:21 +0100 Subject: [PATCH] update the log remove command to be the same design as the set one --- .../logging/command/RemoveSubCommand.java | 49 +++++++++---------- .../logging/command/SetSubCommand.java | 9 ++-- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/features/logging/command/RemoveSubCommand.java b/src/main/java/cc/fascinated/bat/features/logging/command/RemoveSubCommand.java index a28033d..c159c54 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/command/RemoveSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/logging/command/RemoveSubCommand.java @@ -12,6 +12,7 @@ import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; import lombok.NonNull; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -44,10 +45,14 @@ public class RemoveSubCommand extends BatSubCommand { for (LogType logType : LogType.values()) { profile.removeLogChannel(logType); } - - event.replyEmbeds(EmbedUtils.successEmbed() - .setDescription("%s Successfully removed the log channel for all log types".formatted(Emojis.CHECK_MARK_EMOJI)) - .build()).queue(); + EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null); + description.appendLine("%s Successfully removed the log channel from `%s` log events".formatted( + Emojis.CHECK_MARK_EMOJI, + LogType.values().length + ), false); + description.emptyLine(); + description.appendLine("*To view the current log channels, use `/logs list`*", false); + event.replyEmbeds(EmbedUtils.successEmbed().setDescription(description.build()).build()).queue(); return; } @@ -55,25 +60,19 @@ public class RemoveSubCommand extends BatSubCommand { LogCategory logCategory = LogCategory.getLogCategory(type); if (logCategory != null) { List category = LogType.getLogTypesByCategory(type); + for (LogType logType : category) { + profile.removeLogChannel(logType); + } EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null); - description.appendLine("%s Successfully removed the log channel for the `%s` category".formatted( + description.appendLine("%s Successfully removed the log channel from `%s` `%s` log events".formatted( Emojis.CHECK_MARK_EMOJI, + category.size(), logCategory.getName() ), false); description.emptyLine(); - - int removed = 0; - for (LogType logType : category) { - if (!profile.hasLogChannel(logType)) { - continue; - } - description.appendLine(logType.getName(), true); - profile.removeLogChannel(logType); - removed++; - } - + description.appendLine("*To view the current log channels, use `/logs list`*", false); event.replyEmbeds(EmbedUtils.successEmbed() - .setDescription(removed == 0 ? "No log channels were removed for the `%s` category".formatted(logCategory.getName()) : description.build()) + .setDescription(description.build()) .build()).queue(); return; } @@ -86,18 +85,14 @@ public class RemoveSubCommand extends BatSubCommand { .build()).queue(); return; } - - if (!profile.hasLogChannel(logType)) { - event.replyEmbeds(EmbedUtils.errorEmbed() - .setDescription("The log channel for `%s` is not set".formatted(logType.getName())) - .build()).queue(); - return; - } profile.removeLogChannel(logType); - event.replyEmbeds(EmbedUtils.successEmbed() - .setDescription("%s Successfully removed the log channel for `%s`".formatted( + event.replyEmbeds(EmbedUtils.successEmbed().setDescription(new EmbedDescriptionBuilder(null) + .appendLine("%s Successfully removed the log channel from `%s`".formatted( Emojis.CHECK_MARK_EMOJI, logType.getName() - )).build()).queue(); + ), false) + .emptyLine() + .appendLine("*To view the current log channels, use `/logs list`*", false) + .build()).build()).queue(); } } 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 76f8316..560b41d 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 @@ -52,7 +52,7 @@ public class SetSubCommand extends BatSubCommand { profile.setLogChannel(logType, targetChannel); } EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null); - description.appendLine("%s Successfully set the log channel for %s log events to %s".formatted( + description.appendLine("%s Successfully set the log channel for `%s` log events to %s".formatted( Emojis.CHECK_MARK_EMOJI, LogType.values().length, targetChannel.getAsMention() @@ -67,8 +67,11 @@ public class SetSubCommand extends BatSubCommand { LogCategory logCategory = LogCategory.getLogCategory(type); if (logCategory != null) { List category = LogType.getLogTypesByCategory(type); + for (LogType logType : category) { + profile.setLogChannel(logType, targetChannel); + } EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null); - description.appendLine("%s Successfully set the log channel for %s %s log events to %s".formatted( + description.appendLine("%s Successfully set the log channel for `%s` `%s` log events to %s".formatted( Emojis.CHECK_MARK_EMOJI, category.size(), logCategory.getName(), @@ -92,7 +95,7 @@ public class SetSubCommand extends BatSubCommand { } profile.setLogChannel(logType, targetChannel); event.replyEmbeds(EmbedUtils.successEmbed().setDescription(new EmbedDescriptionBuilder(null) - .appendLine("%s Successfully set the log channel for %s to %s".formatted( + .appendLine("%s Successfully set the log channel for `%s` to %s".formatted( Emojis.CHECK_MARK_EMOJI, logType.getName(), targetChannel.getAsMention()