forked from Fascinated/Bat
make the help command better
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package cc.fascinated.bat.command;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
@ -10,7 +11,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Getter
|
||||
@Getter @Setter
|
||||
public class BatSubCommand implements BatCommandExecutor {
|
||||
/**
|
||||
* The command data for the slash command
|
||||
@ -22,6 +23,11 @@ public class BatSubCommand implements BatCommandExecutor {
|
||||
*/
|
||||
private final List<Permission> requiredPermissions;
|
||||
|
||||
/**
|
||||
* The commands snowflake from Discord
|
||||
*/
|
||||
private long commandSnowflake;
|
||||
|
||||
public BatSubCommand(String name, String description, Permission... permissions) {
|
||||
this.commandData = new SubcommandData(name, description);
|
||||
this.requiredPermissions = List.of(permissions);
|
||||
|
@ -16,6 +16,7 @@ public enum Category {
|
||||
GENERAL(Emoji.fromUnicode("U+2699"), "General"),
|
||||
FUN(Emoji.fromFormatted("U+1F973"), "Fun"),
|
||||
SERVER(Emoji.fromFormatted("U+1F5A5"), "Server"),
|
||||
UTILITY(Emoji.fromFormatted("U+1F6E0"), "Utility"),
|
||||
BEAT_SABER(Emoji.fromFormatted("U+1FA84"), "Beat Saber");
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package cc.fascinated.bat.command.impl;
|
||||
|
||||
import cc.fascinated.bat.Consts;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.event.EventListener;
|
||||
@ -13,6 +14,7 @@ import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
|
||||
@ -22,6 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
@ -72,8 +76,26 @@ public class HelpCommand extends BatCommand implements EventListener {
|
||||
}
|
||||
|
||||
String commands = "";
|
||||
for (BatCommand command : commandService.getCommands().values()) {
|
||||
if (command.getCategory() == category) {
|
||||
List<BatCommand> categoryCommands = commandService.getCommands().values().stream()
|
||||
.filter(command -> command.getCategory() == category)
|
||||
.toList();
|
||||
if (categoryCommands.isEmpty()) {
|
||||
commands = "No commands available in this category.";
|
||||
} else {
|
||||
for (BatCommand command : categoryCommands) {
|
||||
if (!command.getSubCommands().isEmpty()) {
|
||||
for (Map.Entry<String, BatSubCommand> entry : command.getSubCommands().entrySet()) {
|
||||
BatSubCommand subCommand = entry.getValue();
|
||||
SubcommandData commandData = subCommand.getCommandData();
|
||||
commands += "</%s %s:%s> - %s\n".formatted(
|
||||
command.getName(),
|
||||
commandData.getName(),
|
||||
subCommand.getCommandSnowflake(),
|
||||
commandData.getDescription()
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
commands += "</%s:%s> - %s\n".formatted(
|
||||
command.getName(),
|
||||
command.getCommandSnowflake(),
|
||||
|
Reference in New Issue
Block a user