forked from Fascinated/Bat
use pages for the log list command and tell the user about the list command
This commit is contained in:
parent
79d20672c5
commit
e873988c47
@ -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);
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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("""
|
||||
List<Button> buttons = new ArrayList<>();
|
||||
for (LogCategory category : LogCategory.values()) {
|
||||
buttons.add(Button.primary("logs:list:%s".formatted(category.name().toLowerCase()), category.getName()));
|
||||
}
|
||||
|
||||
event.replyEmbeds(EmbedUtils.genericEmbed().setDescription(new EmbedDescriptionBuilder("Log Channels")
|
||||
.appendLine("""
|
||||
Set the log channel for:
|
||||
- A specific event, use `/logs set <event> <channel>`
|
||||
- A specific category by using `/logs set <category> <channel>`
|
||||
- All log events by using `/logs set all <channel>`
|
||||
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();
|
||||
but with `/logs remove` instead of `/logs set`
|
||||
|
||||
*Use the buttons below to see the log channels for each category*
|
||||
""", false).build()).build())
|
||||
.addComponents(ActionRow.of(buttons))
|
||||
.queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onButtonInteraction(BatGuild guild, @NonNull BatUser user, @NonNull ButtonInteractionEvent event) {
|
||||
if (guild == null || !event.getComponentId().startsWith("logs:list:")) { // Invalid button
|
||||
return;
|
||||
}
|
||||
if (!event.getInteraction().getUser().getId().equals(user.getId())) {
|
||||
event.replyEmbeds(EmbedUtils.errorEmbed().setDescription("You cannot interact with this button").build()).setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
String[] split = event.getComponentId().split(":");
|
||||
if (split.length != 3) {
|
||||
return;
|
||||
}
|
||||
LogProfile profile = guild.getLogProfile();
|
||||
LogCategory category = LogCategory.getLogCategory(split[2].toUpperCase());
|
||||
if (category == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<LogType> logEvents = LogType.getLogTypesByCategory(category.getName());
|
||||
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder(null);
|
||||
description.appendLine("Log channels for the `%s` category".formatted(category.getName()), false);
|
||||
description.emptyLine();
|
||||
for (LogType logType : logEvents) {
|
||||
if (logType.getCategory() != category) {
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
event.replyEmbeds(EmbedUtils.genericEmbed().setDescription(description.build()).build()).queue();
|
||||
event.editMessageEmbeds(EmbedUtils.genericEmbed().setDescription(description.build()).build()).queue();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,24 +47,14 @@ public class SetSubCommand extends BatSubCommand {
|
||||
|
||||
// Set the log channel for all log types
|
||||
if (type.equalsIgnoreCase("all")) {
|
||||
for (LogType logType : LogType.values()) {
|
||||
profile.setLogChannel(logType, targetChannel);
|
||||
}
|
||||
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 (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()
|
||||
.setDescription(description.build())
|
||||
.build()).queue();
|
||||
description.appendLine("*To view the current log channels, use `/logs list`*", false);
|
||||
event.replyEmbeds(EmbedUtils.successEmbed().setDescription(description.build()).build()).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -73,14 +63,12 @@ public class SetSubCommand extends BatSubCommand {
|
||||
if (logCategory != null) {
|
||||
List<LogType> category = LogType.getLogTypesByCategory(type);
|
||||
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel");
|
||||
description.appendLine("Successfully set the log channel for the `%s` category to %s"
|
||||
.formatted(logCategory.getName(), targetChannel.getAsMention()), false);
|
||||
description.appendLine("Successfully set the log channel for the `%s` category to %s".formatted(
|
||||
logCategory.getName(),
|
||||
targetChannel.getAsMention()
|
||||
), false);
|
||||
description.emptyLine();
|
||||
for (LogType logType : category) {
|
||||
description.appendLine(logType.getName(), true);
|
||||
profile.setLogChannel(logType, targetChannel);
|
||||
}
|
||||
|
||||
description.appendLine("*To view the current log channels, use `/logs list`*", false);
|
||||
event.replyEmbeds(EmbedUtils.successEmbed()
|
||||
.setDescription(description.build())
|
||||
.build()).queue();
|
||||
@ -95,10 +83,14 @@ public class SetSubCommand extends BatSubCommand {
|
||||
.build()).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
profile.setLogChannel(logType, targetChannel);
|
||||
event.replyEmbeds(EmbedUtils.successEmbed()
|
||||
.setDescription("Successfully set the log channel for `%s` to %s".formatted(logType.getName(), targetChannel.getAsMention()))
|
||||
.build()).queue();
|
||||
event.replyEmbeds(EmbedUtils.successEmbed().setDescription(new EmbedDescriptionBuilder("Log Channel")
|
||||
.appendLine("Successfully set the log channel for %s to %s".formatted(
|
||||
logType.getName(),
|
||||
targetChannel.getAsMention()
|
||||
), false)
|
||||
.emptyLine()
|
||||
.appendLine("*To view the current log channels, use `/logs list`*", false)
|
||||
.build()).build()).queue();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user