From e873988c47a633109c5d86b5f6b6c53f89f1eda6 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 05:48:20 +0100 Subject: [PATCH] use pages for the log list command and tell the user about the list command --- .../fascinated/bat/common/ChannelUtils.java | 3 + .../bat/common/EmbedDescriptionBuilder.java | 3 + .../logging/command/ListSubCommand.java | 82 +++++++++++++------ .../logging/command/SetSubCommand.java | 44 ++++------ 4 files changed, 82 insertions(+), 50 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/common/ChannelUtils.java b/src/main/java/cc/fascinated/bat/common/ChannelUtils.java index 9e9f2b1..af8ad23 100644 --- a/src/main/java/cc/fascinated/bat/common/ChannelUtils.java +++ b/src/main/java/cc/fascinated/bat/common/ChannelUtils.java @@ -21,6 +21,9 @@ public class ChannelUtils { log.error("Failed to find user \"{}\" after {} retries.", id, retries); return null; } + if (id == null) { + return null; + } TextChannel channel = DiscordService.JDA.getTextChannelById(id); if (channel == null) { return getTextChannel(id, retries + 1); diff --git a/src/main/java/cc/fascinated/bat/common/EmbedDescriptionBuilder.java b/src/main/java/cc/fascinated/bat/common/EmbedDescriptionBuilder.java index b0f2e6b..77d8c91 100644 --- a/src/main/java/cc/fascinated/bat/common/EmbedDescriptionBuilder.java +++ b/src/main/java/cc/fascinated/bat/common/EmbedDescriptionBuilder.java @@ -12,6 +12,9 @@ public class EmbedDescriptionBuilder { private final StringBuilder builder = new StringBuilder(); public EmbedDescriptionBuilder(String title) { + if (title == null) { + return; + } builder.append("**").append(title).append("**").append("\n"); } diff --git a/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java b/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java index 8edc789..6ec1fcd 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java @@ -4,6 +4,7 @@ import cc.fascinated.bat.command.BatSubCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedDescriptionBuilder; import cc.fascinated.bat.common.EmbedUtils; +import cc.fascinated.bat.event.EventListener; import cc.fascinated.bat.features.logging.LogCategory; import cc.fascinated.bat.features.logging.LogProfile; import cc.fascinated.bat.features.logging.LogType; @@ -13,41 +14,74 @@ 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.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.components.ActionRow; +import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.List; + /** * @author Fascinated (fascinated7) */ @Component("logs:list.sub") @CommandInfo(name = "list", description = "See all the log types and their channels") -public class ListSubCommand extends BatSubCommand { +public class ListSubCommand extends BatSubCommand implements EventListener { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { - LogProfile profile = guild.getLogProfile(); - EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channels"); - description.appendLine(""" - Set the log channel for: - - A specific event, use `/logs set ` - - A specific category by using `/logs set ` - - All log events by using `/logs set all ` - To remove a log channel, it's the same as setting it, - but with `/logs remove` instead of `/logs set`""", false); - description.emptyLine(); - 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.values()) { - if (logType.getCategory() == category) { - TextChannel logChannel = profile.getLogChannel(logType); - description.appendLine("%s: %s".formatted(logType.getName(), logChannel == null ? "Not Set" : logChannel.getAsMention()), true); - } - } + List