use pages for the log list command and tell the user about the list command
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s
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);
|
log.error("Failed to find user \"{}\" after {} retries.", id, retries);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (id == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
TextChannel channel = DiscordService.JDA.getTextChannelById(id);
|
TextChannel channel = DiscordService.JDA.getTextChannelById(id);
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
return getTextChannel(id, retries + 1);
|
return getTextChannel(id, retries + 1);
|
||||||
|
@ -12,6 +12,9 @@ public class EmbedDescriptionBuilder {
|
|||||||
private final StringBuilder builder = new StringBuilder();
|
private final StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
public EmbedDescriptionBuilder(String title) {
|
public EmbedDescriptionBuilder(String title) {
|
||||||
|
if (title == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
builder.append("**").append(title).append("**").append("\n");
|
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.command.CommandInfo;
|
||||||
import cc.fascinated.bat.common.EmbedDescriptionBuilder;
|
import cc.fascinated.bat.common.EmbedDescriptionBuilder;
|
||||||
import cc.fascinated.bat.common.EmbedUtils;
|
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.LogCategory;
|
||||||
import cc.fascinated.bat.features.logging.LogProfile;
|
import cc.fascinated.bat.features.logging.LogProfile;
|
||||||
import cc.fascinated.bat.features.logging.LogType;
|
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.Member;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
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.events.interaction.component.ButtonInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fascinated (fascinated7)
|
* @author Fascinated (fascinated7)
|
||||||
*/
|
*/
|
||||||
@Component("logs:list.sub")
|
@Component("logs:list.sub")
|
||||||
@CommandInfo(name = "list", description = "See all the log types and their channels")
|
@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
|
@Override
|
||||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||||
LogProfile profile = guild.getLogProfile();
|
List<Button> buttons = new ArrayList<>();
|
||||||
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channels");
|
for (LogCategory category : LogCategory.values()) {
|
||||||
description.appendLine("""
|
buttons.add(Button.primary("logs:list:%s".formatted(category.name().toLowerCase()), category.getName()));
|
||||||
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();
|
|
||||||
}
|
|
||||||
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.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`
|
||||||
|
|
||||||
|
*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;
|
||||||
|
}
|
||||||
|
TextChannel logChannel = profile.getLogChannel(logType);
|
||||||
|
description.appendLine("%s: %s".formatted(logType.getName(), logChannel == null ? "Not Set" : logChannel.getAsMention()), true);
|
||||||
|
}
|
||||||
|
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
|
// Set the log channel for all log types
|
||||||
if (type.equalsIgnoreCase("all")) {
|
if (type.equalsIgnoreCase("all")) {
|
||||||
|
for (LogType logType : LogType.values()) {
|
||||||
|
profile.setLogChannel(logType, targetChannel);
|
||||||
|
}
|
||||||
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel");
|
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel");
|
||||||
description.appendLine("Successfully set the log channel for all log types to %s".formatted(targetChannel.getAsMention()), false);
|
description.appendLine("Successfully set the log channel for all log types to %s".formatted(targetChannel.getAsMention()), false);
|
||||||
description.emptyLine();
|
description.emptyLine();
|
||||||
for (int i = 0; i < LogCategory.values().length; i++) {
|
description.appendLine("*To view the current log channels, use `/logs list`*", false);
|
||||||
LogCategory category = LogCategory.values()[i];
|
event.replyEmbeds(EmbedUtils.successEmbed().setDescription(description.build()).build()).queue();
|
||||||
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();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,14 +63,12 @@ public class SetSubCommand extends BatSubCommand {
|
|||||||
if (logCategory != null) {
|
if (logCategory != null) {
|
||||||
List<LogType> category = LogType.getLogTypesByCategory(type);
|
List<LogType> category = LogType.getLogTypesByCategory(type);
|
||||||
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel");
|
EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Log Channel");
|
||||||
description.appendLine("Successfully set the log channel for the `%s` category to %s"
|
description.appendLine("Successfully set the log channel for the `%s` category to %s".formatted(
|
||||||
.formatted(logCategory.getName(), targetChannel.getAsMention()), false);
|
logCategory.getName(),
|
||||||
|
targetChannel.getAsMention()
|
||||||
|
), false);
|
||||||
description.emptyLine();
|
description.emptyLine();
|
||||||
for (LogType logType : category) {
|
description.appendLine("*To view the current log channels, use `/logs list`*", false);
|
||||||
description.appendLine(logType.getName(), true);
|
|
||||||
profile.setLogChannel(logType, targetChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
event.replyEmbeds(EmbedUtils.successEmbed()
|
event.replyEmbeds(EmbedUtils.successEmbed()
|
||||||
.setDescription(description.build())
|
.setDescription(description.build())
|
||||||
.build()).queue();
|
.build()).queue();
|
||||||
@ -95,10 +83,14 @@ public class SetSubCommand extends BatSubCommand {
|
|||||||
.build()).queue();
|
.build()).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
profile.setLogChannel(logType, targetChannel);
|
profile.setLogChannel(logType, targetChannel);
|
||||||
event.replyEmbeds(EmbedUtils.successEmbed()
|
event.replyEmbeds(EmbedUtils.successEmbed().setDescription(new EmbedDescriptionBuilder("Log Channel")
|
||||||
.setDescription("Successfully set the log channel for `%s` to %s".formatted(logType.getName(), targetChannel.getAsMention()))
|
.appendLine("Successfully set the log channel for %s to %s".formatted(
|
||||||
.build()).queue();
|
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