update the log remove command to be the same design as the set one

This commit is contained in:
Lee 2024-07-04 09:41:21 +01:00
parent dbe6fb4762
commit c284bb8a7f
2 changed files with 28 additions and 30 deletions

@ -12,6 +12,7 @@ import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.BatUser;
import lombok.NonNull; import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member; 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.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
@ -44,10 +45,14 @@ public class RemoveSubCommand extends BatSubCommand {
for (LogType logType : LogType.values()) { for (LogType logType : LogType.values()) {
profile.removeLogChannel(logType); profile.removeLogChannel(logType);
} }
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null);
event.replyEmbeds(EmbedUtils.successEmbed() description.appendLine("%s Successfully removed the log channel from `%s` log events".formatted(
.setDescription("%s Successfully removed the log channel for all log types".formatted(Emojis.CHECK_MARK_EMOJI)) Emojis.CHECK_MARK_EMOJI,
.build()).queue(); 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; return;
} }
@ -55,25 +60,19 @@ public class RemoveSubCommand extends BatSubCommand {
LogCategory logCategory = LogCategory.getLogCategory(type); LogCategory logCategory = LogCategory.getLogCategory(type);
if (logCategory != null) { if (logCategory != null) {
List<LogType> category = LogType.getLogTypesByCategory(type); List<LogType> category = LogType.getLogTypesByCategory(type);
for (LogType logType : category) {
profile.removeLogChannel(logType);
}
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null); 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, Emojis.CHECK_MARK_EMOJI,
category.size(),
logCategory.getName() logCategory.getName()
), false); ), false);
description.emptyLine(); description.emptyLine();
description.appendLine("*To view the current log channels, use `/logs list`*", false);
int removed = 0;
for (LogType logType : category) {
if (!profile.hasLogChannel(logType)) {
continue;
}
description.appendLine(logType.getName(), true);
profile.removeLogChannel(logType);
removed++;
}
event.replyEmbeds(EmbedUtils.successEmbed() 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(); .build()).queue();
return; return;
} }
@ -86,18 +85,14 @@ public class RemoveSubCommand extends BatSubCommand {
.build()).queue(); .build()).queue();
return; 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); profile.removeLogChannel(logType);
event.replyEmbeds(EmbedUtils.successEmbed() event.replyEmbeds(EmbedUtils.successEmbed().setDescription(new EmbedDescriptionBuilder(null)
.setDescription("%s Successfully removed the log channel for `%s`".formatted( .appendLine("%s Successfully removed the log channel from `%s`".formatted(
Emojis.CHECK_MARK_EMOJI, Emojis.CHECK_MARK_EMOJI,
logType.getName() logType.getName()
)).build()).queue(); ), false)
.emptyLine()
.appendLine("*To view the current log channels, use `/logs list`*", false)
.build()).build()).queue();
} }
} }

@ -52,7 +52,7 @@ public class SetSubCommand extends BatSubCommand {
profile.setLogChannel(logType, targetChannel); profile.setLogChannel(logType, targetChannel);
} }
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null); 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, Emojis.CHECK_MARK_EMOJI,
LogType.values().length, LogType.values().length,
targetChannel.getAsMention() targetChannel.getAsMention()
@ -67,8 +67,11 @@ public class SetSubCommand extends BatSubCommand {
LogCategory logCategory = LogCategory.getLogCategory(type); LogCategory logCategory = LogCategory.getLogCategory(type);
if (logCategory != null) { if (logCategory != null) {
List<LogType> category = LogType.getLogTypesByCategory(type); List<LogType> category = LogType.getLogTypesByCategory(type);
for (LogType logType : category) {
profile.setLogChannel(logType, targetChannel);
}
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null); 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, Emojis.CHECK_MARK_EMOJI,
category.size(), category.size(),
logCategory.getName(), logCategory.getName(),
@ -92,7 +95,7 @@ public class SetSubCommand extends BatSubCommand {
} }
profile.setLogChannel(logType, targetChannel); profile.setLogChannel(logType, targetChannel);
event.replyEmbeds(EmbedUtils.successEmbed().setDescription(new EmbedDescriptionBuilder(null) 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, Emojis.CHECK_MARK_EMOJI,
logType.getName(), logType.getName(),
targetChannel.getAsMention() targetChannel.getAsMention()