From b37a30b0a3bd659c26e6afbc18033ab1d5056ee5 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 25 Jun 2024 11:19:51 +0100 Subject: [PATCH] cleanup how i add sub commands to the commands --- .../command/scoresaber/ScoreSaberCommand.java | 7 ++++++- .../command/userfeed/UserFeedCommand.java | 8 +++++++- .../cc/fascinated/bat/service/CommandService.java | 13 ++----------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/command/scoresaber/ScoreSaberCommand.java b/src/main/java/cc/fascinated/bat/features/scoresaber/command/scoresaber/ScoreSaberCommand.java index 46fa476..e0f1bab 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/command/scoresaber/ScoreSaberCommand.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/command/scoresaber/ScoreSaberCommand.java @@ -20,6 +20,7 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; import net.dv8tion.jda.internal.interactions.CommandDataImpl; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import java.time.LocalDateTime; @@ -32,11 +33,15 @@ public class ScoreSaberCommand extends BatCommand { private final ScoreSaberService scoreSaberService; @Autowired - public ScoreSaberCommand(@NonNull ScoreSaberService scoreSaberService) { + public ScoreSaberCommand(@NonNull ScoreSaberService scoreSaberService, @NonNull ApplicationContext context) { super("scoresaber"); super.setCategory(Category.BEAT_SABER); this.scoreSaberService = scoreSaberService; + super.addSubCommand("link", context.getBean(LinkSubCommand.class)); + super.addSubCommand("user", context.getBean(UserSubCommand.class)); + super.addSubCommand("me", context.getBean(MeSubCommand.class)); + super.setDescription("General ScoreSaber commands"); super.setCommandData(new CommandDataImpl(this.getName(), this.getDescription()) .addSubcommands(new SubcommandData("link", "Link your ScoreSaber profile") diff --git a/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserFeedCommand.java b/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserFeedCommand.java index 85970d8..a99a188 100644 --- a/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserFeedCommand.java +++ b/src/main/java/cc/fascinated/bat/features/scoresaber/command/userfeed/UserFeedCommand.java @@ -1,12 +1,14 @@ package cc.fascinated.bat.features.scoresaber.command.userfeed; import cc.fascinated.bat.command.BatCommand; +import lombok.NonNull; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; import net.dv8tion.jda.internal.interactions.CommandDataImpl; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; /** @@ -14,10 +16,14 @@ import org.springframework.stereotype.Component; */ @Component("scoresaber-userfeed:feed.sub") public class UserFeedCommand extends BatCommand { - public UserFeedCommand() { + public UserFeedCommand(@NonNull ApplicationContext context) { super("scoresaber-userfeed"); super.setCategory(Category.BEAT_SABER); + super.addSubCommand("user", context.getBean(UserSubCommand.class)); + super.addSubCommand("channel", context.getBean(ChannelSubCommand.class)); + super.addSubCommand("clear-users", context.getBean(ClearUsersSubCommand.class)); + super.setDescription("ScoreSaber user score feed commands"); super.setCommandData(new CommandDataImpl(this.getName(), this.getDescription()) .addSubcommands(new SubcommandData("user", "Edit your ScoreSaber score feed settings") diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index c11674d..edd6611 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -55,19 +55,10 @@ public class CommandService extends ListenerAdapter { DiscordService.JDA.addEventListener(this); // Guild commands - // todo: add some, duh + registerCommand(context.getBean(UserFeedCommand.class)); // Global commands - registerCommand(context.getBean(ScoreSaberCommand.class) - .addSubCommand("link", context.getBean(LinkSubCommand.class)) - .addSubCommand("user", context.getBean(cc.fascinated.bat.features.scoresaber.command.scoresaber.UserSubCommand.class)) - .addSubCommand("me", context.getBean(MeSubCommand.class)) - ); - registerCommand(context.getBean(UserFeedCommand.class) - .addSubCommand("user", context.getBean(UserSubCommand.class)) - .addSubCommand("channel", context.getBean(ChannelSubCommand.class)) - .addSubCommand("clear-users", context.getBean(ClearUsersSubCommand.class)) - ); + registerCommand(context.getBean(ScoreSaberCommand.class)); registerSlashCommands(); // Register all slash commands }