forked from Fascinated/Bat
make the help command better
This commit is contained in:
parent
a7c3e2d745
commit
50b921c66d
@ -1,6 +1,7 @@
|
|||||||
package cc.fascinated.bat.command;
|
package cc.fascinated.bat.command;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
@ -10,7 +11,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author Fascinated (fascinated7)
|
* @author Fascinated (fascinated7)
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter @Setter
|
||||||
public class BatSubCommand implements BatCommandExecutor {
|
public class BatSubCommand implements BatCommandExecutor {
|
||||||
/**
|
/**
|
||||||
* The command data for the slash command
|
* The command data for the slash command
|
||||||
@ -22,6 +23,11 @@ public class BatSubCommand implements BatCommandExecutor {
|
|||||||
*/
|
*/
|
||||||
private final List<Permission> requiredPermissions;
|
private final List<Permission> requiredPermissions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The commands snowflake from Discord
|
||||||
|
*/
|
||||||
|
private long commandSnowflake;
|
||||||
|
|
||||||
public BatSubCommand(String name, String description, Permission... permissions) {
|
public BatSubCommand(String name, String description, Permission... permissions) {
|
||||||
this.commandData = new SubcommandData(name, description);
|
this.commandData = new SubcommandData(name, description);
|
||||||
this.requiredPermissions = List.of(permissions);
|
this.requiredPermissions = List.of(permissions);
|
||||||
|
@ -16,6 +16,7 @@ public enum Category {
|
|||||||
GENERAL(Emoji.fromUnicode("U+2699"), "General"),
|
GENERAL(Emoji.fromUnicode("U+2699"), "General"),
|
||||||
FUN(Emoji.fromFormatted("U+1F973"), "Fun"),
|
FUN(Emoji.fromFormatted("U+1F973"), "Fun"),
|
||||||
SERVER(Emoji.fromFormatted("U+1F5A5"), "Server"),
|
SERVER(Emoji.fromFormatted("U+1F5A5"), "Server"),
|
||||||
|
UTILITY(Emoji.fromFormatted("U+1F6E0"), "Utility"),
|
||||||
BEAT_SABER(Emoji.fromFormatted("U+1FA84"), "Beat Saber");
|
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.Consts;
|
||||||
import cc.fascinated.bat.command.BatCommand;
|
import cc.fascinated.bat.command.BatCommand;
|
||||||
|
import cc.fascinated.bat.command.BatSubCommand;
|
||||||
import cc.fascinated.bat.command.Category;
|
import cc.fascinated.bat.command.Category;
|
||||||
import cc.fascinated.bat.common.EmbedUtils;
|
import cc.fascinated.bat.common.EmbedUtils;
|
||||||
import cc.fascinated.bat.event.EventListener;
|
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.entities.channel.middleman.MessageChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
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.ActionRow;
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||||
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
|
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fascinated (fascinated7)
|
* @author Fascinated (fascinated7)
|
||||||
@ -72,8 +76,26 @@ public class HelpCommand extends BatCommand implements EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String commands = "";
|
String commands = "";
|
||||||
for (BatCommand command : commandService.getCommands().values()) {
|
List<BatCommand> categoryCommands = commandService.getCommands().values().stream()
|
||||||
if (command.getCategory() == category) {
|
.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(
|
commands += "</%s:%s> - %s\n".formatted(
|
||||||
command.getName(),
|
command.getName(),
|
||||||
command.getCommandSnowflake(),
|
command.getCommandSnowflake(),
|
||||||
|
@ -18,6 +18,6 @@ public class AutoRoleFeature extends Feature {
|
|||||||
public AutoRoleFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
public AutoRoleFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
|
||||||
super("AutoRole", Category.SERVER);
|
super("AutoRole", Category.SERVER);
|
||||||
|
|
||||||
commandService.registerCommand(context.getBean(AutoRoleCommand.class));
|
registerCommand(commandService, context.getBean(AutoRoleCommand.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class BirthdayFeature extends Feature {
|
|||||||
private final GuildService guildService;
|
private final GuildService guildService;
|
||||||
|
|
||||||
public BirthdayFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
|
public BirthdayFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
|
||||||
super("Birthday", Category.GENERAL);
|
super("Birthday", Category.UTILITY);
|
||||||
this.guildService = guildService;
|
this.guildService = guildService;
|
||||||
|
|
||||||
registerCommand(commandService, context.getBean(BirthdayCommand.class));
|
registerCommand(commandService, context.getBean(BirthdayCommand.class));
|
||||||
|
@ -89,6 +89,11 @@ public class CommandService extends ListenerAdapter {
|
|||||||
List<Command> discordCommands = jda.updateCommands().addCommands(commands.values().stream().map(BatCommand::getCommandData).toList()).complete();
|
List<Command> discordCommands = jda.updateCommands().addCommands(commands.values().stream().map(BatCommand::getCommandData).toList()).complete();
|
||||||
for (Command discordCommand : discordCommands) {
|
for (Command discordCommand : discordCommands) {
|
||||||
commands.get(discordCommand.getName()).setCommandSnowflake(discordCommand.getIdLong());
|
commands.get(discordCommand.getName()).setCommandSnowflake(discordCommand.getIdLong());
|
||||||
|
if (!discordCommand.getSubcommands().isEmpty()) {
|
||||||
|
for (Command.Subcommand subCommand : discordCommand.getSubcommands()) {
|
||||||
|
commands.get(discordCommand.getName()).getSubCommands().get(subCommand.getName()).setCommandSnowflake(subCommand.getIdLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.info("Registered all slash commands in {}ms", System.currentTimeMillis() - before);
|
log.info("Registered all slash commands in {}ms", System.currentTimeMillis() - before);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,8 @@ public class DiscordService {
|
|||||||
"over {guilds} guilds",
|
"over {guilds} guilds",
|
||||||
"over {users} users",
|
"over {users} users",
|
||||||
"over ScoreSaber scores",
|
"over ScoreSaber scores",
|
||||||
"your messages"
|
"your messages",
|
||||||
|
"/help for help"
|
||||||
);
|
);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
Loading…
Reference in New Issue
Block a user