diff --git a/src/main/java/cc/fascinated/bat/command/BatSubCommand.java b/src/main/java/cc/fascinated/bat/command/BatSubCommand.java index 793c086..2dd49bd 100644 --- a/src/main/java/cc/fascinated/bat/command/BatSubCommand.java +++ b/src/main/java/cc/fascinated/bat/command/BatSubCommand.java @@ -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 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); diff --git a/src/main/java/cc/fascinated/bat/command/Category.java b/src/main/java/cc/fascinated/bat/command/Category.java index d4545df..8924f16 100644 --- a/src/main/java/cc/fascinated/bat/command/Category.java +++ b/src/main/java/cc/fascinated/bat/command/Category.java @@ -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"); /** diff --git a/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java b/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java index 187095c..8524317 100644 --- a/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java +++ b/src/main/java/cc/fascinated/bat/command/impl/HelpCommand.java @@ -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 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 entry : command.getSubCommands().entrySet()) { + BatSubCommand subCommand = entry.getValue(); + SubcommandData commandData = subCommand.getCommandData(); + commands += " - %s\n".formatted( + command.getName(), + commandData.getName(), + subCommand.getCommandSnowflake(), + commandData.getDescription() + ); + } + continue; + } commands += " - %s\n".formatted( command.getName(), command.getCommandSnowflake(), diff --git a/src/main/java/cc/fascinated/bat/features/autorole/AutoRoleFeature.java b/src/main/java/cc/fascinated/bat/features/autorole/AutoRoleFeature.java index 078919f..a33b3e0 100644 --- a/src/main/java/cc/fascinated/bat/features/autorole/AutoRoleFeature.java +++ b/src/main/java/cc/fascinated/bat/features/autorole/AutoRoleFeature.java @@ -18,6 +18,6 @@ public class AutoRoleFeature extends Feature { public AutoRoleFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) { super("AutoRole", Category.SERVER); - commandService.registerCommand(context.getBean(AutoRoleCommand.class)); + registerCommand(commandService, context.getBean(AutoRoleCommand.class)); } } diff --git a/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java b/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java index 0f1befd..2210fe9 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/BirthdayFeature.java @@ -20,7 +20,7 @@ public class BirthdayFeature extends Feature { private final GuildService guildService; public BirthdayFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) { - super("Birthday", Category.GENERAL); + super("Birthday", Category.UTILITY); this.guildService = guildService; registerCommand(commandService, context.getBean(BirthdayCommand.class)); diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index 5667b9e..f4e0683 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -89,6 +89,11 @@ public class CommandService extends ListenerAdapter { List discordCommands = jda.updateCommands().addCommands(commands.values().stream().map(BatCommand::getCommandData).toList()).complete(); for (Command discordCommand : discordCommands) { 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); } diff --git a/src/main/java/cc/fascinated/bat/service/DiscordService.java b/src/main/java/cc/fascinated/bat/service/DiscordService.java index f801f15..58b2871 100644 --- a/src/main/java/cc/fascinated/bat/service/DiscordService.java +++ b/src/main/java/cc/fascinated/bat/service/DiscordService.java @@ -28,7 +28,8 @@ public class DiscordService { "over {guilds} guilds", "over {users} users", "over ScoreSaber scores", - "your messages" + "your messages", + "/help for help" ); @Autowired