From 4fdd00453a3736626be2f94cd094fc3577865f72 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Thu, 4 Jul 2024 08:47:32 -0400 Subject: [PATCH] rework command system --- pom.xml | 22 +-- .../cc/fascinated/bat/BatApplication.java | 2 +- .../cc/fascinated/bat/command/BatCommand.java | 133 +++++++++------- .../bat/command/BatCommandExecutor.java | 31 ---- .../fascinated/bat/command/BatSubCommand.java | 45 ------ .../cc/fascinated/bat/command/Category.java | 43 ++---- .../fascinated/bat/command/CommandInfo.java | 3 + .../bat/command/InternalCommandInfo.java | 60 +++++++ .../cc/fascinated/bat/features/Feature.java | 7 +- .../bat/features/afk/command/AfkCommand.java | 12 +- .../autorole/command/AddSubCommand.java | 7 +- .../autorole/command/AutoRoleCommand.java | 10 +- .../autorole/command/ClearSubCommand.java | 4 +- .../autorole/command/ListSubCommand.java | 4 +- .../autorole/command/RemoveSubCommand.java | 7 +- .../botadmin/premium/PremiumAdminCommand.java | 9 +- .../botadmin/premium/RemoveSubCommand.java | 7 +- .../botadmin/premium/SetSubCommand.java | 11 +- .../commands/discord/LookupUserCommand.java | 3 +- .../base/commands/fun/EightBallCommand.java | 3 +- .../commands/fun/image/CatSubCommand.java | 4 +- .../commands/fun/image/DogSubCommand.java | 4 +- .../commands/fun/image/DuckSubCommand.java | 4 +- .../commands/fun/image/FoxSubCommand.java | 4 +- .../base/commands/fun/image/ImageCommand.java | 10 +- .../base/commands/general/HelpCommand.java | 88 ++++++----- .../general/avatar/AvatarCommand.java | 6 +- .../general/avatar/GuildSubCommand.java | 4 +- .../general/avatar/UserSubCommand.java | 7 +- .../general/banner/BannerCommand.java | 6 +- .../general/banner/GuildSubCommand.java | 4 +- .../general/banner/UserSubCommand.java | 7 +- .../server/channel/ChannelCommand.java | 8 +- .../server/channel/RemoveTopicSubCommand.java | 7 +- .../server/channel/SetTopicSubCommand.java | 17 +- .../server/channel/ViewTopicSubCommand.java | 7 +- .../server/feature/DisableSubCommand.java | 7 +- .../server/feature/EnableSubCommand.java | 7 +- .../server/feature/FeatureCommand.java | 8 +- .../server/feature/ListSubCommand.java | 4 +- .../birthday/command/BirthdayCommand.java | 14 +- .../birthday/command/ChannelSubCommand.java | 7 +- .../birthday/command/MessageSubCommand.java | 7 +- .../birthday/command/PrivateSubCommand.java | 7 +- .../birthday/command/RemoveSubCommand.java | 4 +- .../birthday/command/SetSubCommand.java | 7 +- .../birthday/command/ViewSubCommand.java | 7 +- .../features/drag/command/DragCommand.java | 2 +- .../drag/command/RequestSubCommand.java | 7 +- .../logging/command/ListSubCommand.java | 4 +- .../features/logging/command/LogsCommand.java | 8 +- .../logging/command/RemoveSubCommand.java | 7 +- .../logging/command/SetSubCommand.java | 11 +- .../messagesnipe/command/ClearSubCommand.java | 4 +- .../command/DeletedSubCommand.java | 4 +- .../command/MessageSnipeCommand.java | 6 +- .../moderation/command/PurgeCommand.java | 3 +- .../namehistory/command/GuildSubCommand.java | 7 +- .../command/NameHistoryCommand.java | 6 +- .../namehistory/command/UserSubCommand.java | 7 +- .../reminder/command/ClearSubCommand.java | 4 +- .../reminder/command/ListSubCommand.java | 4 +- .../reminder/command/ReminderCommand.java | 8 +- .../reminder/command/SetSubCommand.java | 11 +- .../command/numberone/ChannelSubCommand.java | 7 +- .../numberone/NumberOneFeedCommand.java | 6 +- .../command/numberone/ResetSubCommand.java | 4 +- .../command/scoresaber/LinkSubCommand.java | 7 +- .../command/scoresaber/MeSubCommand.java | 4 +- .../command/scoresaber/ResetSubCommand.java | 4 +- .../command/scoresaber/ScoreSaberCommand.java | 10 +- .../command/scoresaber/UserSubCommand.java | 7 +- .../command/userfeed/ChannelSubCommand.java | 7 +- .../command/userfeed/ResetSubCommand.java | 4 +- .../command/userfeed/UserFeedCommand.java | 8 +- .../command/userfeed/UserSubCommand.java | 7 +- .../spotify/command/CurrentSubCommand.java | 4 +- .../spotify/command/LinkSubCommand.java | 4 +- .../spotify/command/PauseSubCommand.java | 4 +- .../spotify/command/ResumeSubCommand.java | 4 +- .../spotify/command/SkipSubCommand.java | 4 +- .../spotify/command/SpotifyCommand.java | 14 +- .../spotify/command/UnlinkSubCommand.java | 4 +- .../tmdb/command/MovieSubCommand.java | 16 +- .../tmdb/command/SeriesSubCommand.java | 15 +- .../features/tmdb/command/TMDBCommand.java | 9 +- .../welcomer/command/ChannelSubCommand.java | 7 +- .../welcomer/command/CurrentSubCommand.java | 4 +- .../welcomer/command/EmbedSubCommand.java | 15 +- .../welcomer/command/MessageSubCommand.java | 7 +- .../welcomer/command/ResetSubCommand.java | 4 +- .../welcomer/command/WelcomerCommand.java | 12 +- .../bat/service/CommandService.java | 146 +++++++----------- .../bat/service/FeatureService.java | 22 +-- 94 files changed, 603 insertions(+), 559 deletions(-) delete mode 100644 src/main/java/cc/fascinated/bat/command/BatCommandExecutor.java delete mode 100644 src/main/java/cc/fascinated/bat/command/BatSubCommand.java create mode 100644 src/main/java/cc/fascinated/bat/command/InternalCommandInfo.java diff --git a/pom.xml b/pom.xml index 106b6a4..91a1f6b 100644 --- a/pom.xml +++ b/pom.xml @@ -107,11 +107,13 @@ io.mongock mongock-springboot-v3 5.2.4 + compile io.mongock mongodb-springdata-v4-driver 5.2.4 + compile @@ -138,49 +140,41 @@ 1.18.32 provided - - - - - - - io.github.freya022 JDA 2ed819ad15 + compile com.google.code.gson gson 2.10.1 + compile org.apache.httpcomponents.client5 httpclient5 5.3.1 + compile net.jodah expiringmap 0.5.11 + compile se.michaelthelin.spotify spotify-web-api-java 8.4.0 + compile uk.co.conoregan themoviedbapi 2.1.1 - - - - - org.springframework.boot - spring-boot-starter-test - test + compile diff --git a/src/main/java/cc/fascinated/bat/BatApplication.java b/src/main/java/cc/fascinated/bat/BatApplication.java index 90c77cb..da73e4c 100644 --- a/src/main/java/cc/fascinated/bat/BatApplication.java +++ b/src/main/java/cc/fascinated/bat/BatApplication.java @@ -20,7 +20,7 @@ import java.nio.file.StandardCopyOption; import java.util.Objects; @EnableScheduling -@SpringBootApplication(scanBasePackages = "cc.fascinated.bat") +@SpringBootApplication @EnableMongock @Log4j2(topic = "Bat") public class BatApplication { diff --git a/src/main/java/cc/fascinated/bat/command/BatCommand.java b/src/main/java/cc/fascinated/bat/command/BatCommand.java index 165bb40..b801c44 100644 --- a/src/main/java/cc/fascinated/bat/command/BatCommand.java +++ b/src/main/java/cc/fascinated/bat/command/BatCommand.java @@ -1,103 +1,124 @@ package cc.fascinated.bat.command; import cc.fascinated.bat.features.Feature; +import cc.fascinated.bat.model.BatGuild; +import cc.fascinated.bat.model.BatUser; +import lombok.AccessLevel; import lombok.Getter; import lombok.NonNull; import lombok.Setter; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.IntegrationType; import net.dv8tion.jda.api.interactions.InteractionContextType; -import net.dv8tion.jda.api.interactions.commands.OptionMapping; -import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +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 java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** - * @author Fascinated (fascinated7) + * @author Braydon */ @Getter -@Setter -public abstract class BatCommand implements BatCommandExecutor { +public abstract class BatCommand { /** - * The information about the command + * The info of this command. */ - private final CommandInfo commandInfo; + @NonNull private final InternalCommandInfo info; /** - * The command data for the slash command + * The feature this command belongs to. */ - private final CommandDataImpl commandData; + @Setter private Feature feature; /** - * The sub commands of the command + * The snowflake of this command, set when + * this command is registered with Discord. */ - private final Map subCommands = new HashMap<>(); + @Setter private long snowflake; /** - * The category of the command + * The sub commands of this command, if any. */ - private Category category; + private final Map subCommands = Collections.synchronizedMap(new HashMap<>()); /** - * The feature that the command belongs to + * The internal data for this command. */ - private Feature feature; + @Setter(AccessLevel.PRIVATE) private CommandDataImpl commandData; /** - * Whether the command can only be used by the bot owner + * The internal subcommand data for this command. */ - private boolean botOwnerOnly; - - /** - * The command snowflake from Discord - */ - private long commandSnowflake; + @Setter(AccessLevel.PRIVATE) private SubcommandData subcommandData; public BatCommand() { - this.commandInfo = getClass().getAnnotation(CommandInfo.class); - this.category = this.commandInfo.category(); - this.botOwnerOnly = this.commandInfo.botOwnerOnly(); + if (!getClass().isAnnotationPresent(CommandInfo.class)) { + throw new IllegalStateException("Missing @CommandInfo annotation in " + getClass().getSimpleName()); + } + info = new InternalCommandInfo(getClass().getAnnotation(CommandInfo.class)); - List integrationTypes = this.commandInfo.userInstall() ? List.of(IntegrationType.GUILD_INSTALL, IntegrationType.USER_INSTALL) : - List.of(IntegrationType.GUILD_INSTALL); - this.commandData = new CommandDataImpl(this.commandInfo.name(), this.commandInfo.description()) - .setGuildOnly(this.commandInfo.guildOnly()) + List integrationTypes = new ArrayList<>(Collections.singletonList(IntegrationType.GUILD_INSTALL)); + if (info.isUserInstall()) { + integrationTypes.add(IntegrationType.USER_INSTALL); + } + commandData = new CommandDataImpl(info.getName(), info.getDescription()) .setContexts(InteractionContextType.ALL) - .setIntegrationTypes(integrationTypes); + .setIntegrationTypes(integrationTypes) + .setGuildOnly(info.isGuildOnly()); } /** - * Adds a sub command to the command + * Fired when this command is executed. * - * @param subCommand The sub command + * @param guild the guild the command was executed in, if any + * @param user the user who executed the command + * @param channel the channel the command was executed in + * @param member the member who executed the command, null if not a guild + * @param event the event that invoked this command */ - public void addSubCommand(@NonNull BatSubCommand subCommand) { - this.subCommands.put(subCommand.getCommandInfo().name().toLowerCase(), subCommand); - this.commandData.addSubcommands(subCommand.getCommandData()); + public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { } + + /** + * Register the given sub commands. + * + * @param commands the commands to register + */ + protected final void addSubCommands(@NonNull BatCommand... commands) { + for (BatCommand command : commands) { + // Copy info from the parent command + if (command.getInfo().getCategory() != info.getCategory()) { + command.getInfo().setCategory(info.getCategory()); + } + if (command.getInfo().getPermissions().length == 0) { + command.getInfo().setPermissions(info.getPermissions()); + } + if (command.getInfo().isGuildOnly() != info.isGuildOnly()) { + command.getInfo().setGuildOnly(info.isGuildOnly()); + } + if (command.getInfo().isBotOwnerOnly() != info.isBotOwnerOnly()) { + command.getInfo().setBotOwnerOnly(info.isBotOwnerOnly()); + } + + command.setSubcommandData(new SubcommandData(command.getInfo().getName(), command.getInfo().getDescription())); + commandData.addSubcommands(command.getSubcommandData()); + subCommands.put(command.getInfo().getName(), command); + } } /** - * Adds an option to the sub command + * Add the given options + * to this command. * - * @param optionType the type of the option - * @param name the name of the option - * @param description the description of the option - * @param required whether the option is required + * @param options the options to add */ - protected void addOption(OptionType optionType, String name, String description, boolean required) { - this.commandData.addOption(optionType, name, description, required); + protected final void addOptions(OptionData... options) { + if (subcommandData != null) { + subcommandData.addOptions(options); + } else { + commandData.addOptions(options); + } } - - /** - * Gets all the options for the command - * - * @param interaction The slash command interaction - * @return The option strings - */ - public List getOptions(SlashCommandInteraction interaction) { - return interaction.getOptions().stream().map(OptionMapping::getName).toList(); - } -} +} \ No newline at end of file diff --git a/src/main/java/cc/fascinated/bat/command/BatCommandExecutor.java b/src/main/java/cc/fascinated/bat/command/BatCommandExecutor.java deleted file mode 100644 index cac1815..0000000 --- a/src/main/java/cc/fascinated/bat/command/BatCommandExecutor.java +++ /dev/null @@ -1,31 +0,0 @@ -package cc.fascinated.bat.command; - -import cc.fascinated.bat.model.BatGuild; -import cc.fascinated.bat.model.BatUser; -import lombok.NonNull; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; -import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; - -/** - * @author Fascinated (fascinated7) - */ -public interface BatCommandExecutor { - /** - * Executes the command using a slash command event. - * - * @param guild the bat guild the command was executed in (null if the command was executed in a DM) - * @param user the bat user that executed the command - * @param channel the channel the command was executed in - * @param member the member that executed the command - * @param event the slash command event - */ - default void execute( - BatGuild guild, - @NonNull BatUser user, - @NonNull MessageChannel channel, - Member member, - @NonNull SlashCommandInteraction event - ) { - } -} diff --git a/src/main/java/cc/fascinated/bat/command/BatSubCommand.java b/src/main/java/cc/fascinated/bat/command/BatSubCommand.java deleted file mode 100644 index 744a41c..0000000 --- a/src/main/java/cc/fascinated/bat/command/BatSubCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -package cc.fascinated.bat.command; - -import lombok.Getter; -import lombok.Setter; -import net.dv8tion.jda.api.interactions.commands.OptionType; -import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; - -/** - * @author Fascinated (fascinated7) - */ -@Getter -@Setter -public class BatSubCommand implements BatCommandExecutor { - /** - * The information about the sub command - */ - private final CommandInfo commandInfo; - - /** - * The command data for the slash command - */ - private final SubcommandData commandData; - - /** - * The commands snowflake from Discord - */ - private long commandSnowflake; - - public BatSubCommand() { - this.commandInfo = getClass().getAnnotation(CommandInfo.class); - this.commandData = new SubcommandData(this.commandInfo.name(), this.commandInfo.description()); - } - - /** - * Adds an option to the sub command - * - * @param optionType the type of the option - * @param name the name of the option - * @param description the description of the option - * @param required whether the option is required - */ - public void addOption(OptionType optionType, String name, String description, boolean required) { - this.commandData.addOption(optionType, name, description, required); - } -} diff --git a/src/main/java/cc/fascinated/bat/command/Category.java b/src/main/java/cc/fascinated/bat/command/Category.java index 1606400..6f0c279 100644 --- a/src/main/java/cc/fascinated/bat/command/Category.java +++ b/src/main/java/cc/fascinated/bat/command/Category.java @@ -2,43 +2,35 @@ package cc.fascinated.bat.command; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NonNull; import net.dv8tion.jda.api.entities.emoji.Emoji; -import java.util.Arrays; -import java.util.List; - /** * @author Fascinated (fascinated7) */ @AllArgsConstructor @Getter public enum Category { - GENERAL(Emoji.fromUnicode("U+2699"), "General", false), - FUN(Emoji.fromFormatted("U+1F973"), "Fun", false), - SERVER(Emoji.fromFormatted("U+1F5A5"), "Server", false), - MODERATION(Emoji.fromFormatted("U+1F6E0"), "Moderation", false), - UTILITY(Emoji.fromFormatted("U+1F6E0"), "Utility", false), - MUSIC(Emoji.fromFormatted("U+1F3B5"), "Music", false), - MOVIES_TV(Emoji.fromFormatted("U+1F3A5"), "Movies & TV", false), - MESSAGES(Emoji.fromFormatted("U+1F4A3"), "Messages", false), - LOGS(Emoji.fromFormatted("U+1F4D1"), "Logs", false), - BEAT_SABER(Emoji.fromFormatted("U+1FA84"), "Beat Saber", false), - BOT_ADMIN(null, null, true); + GENERAL(Emoji.fromUnicode("U+2699"), "General"), + FUN(Emoji.fromFormatted("U+1F973"), "Fun"), + SERVER(Emoji.fromFormatted("U+1F5A5"), "Server"), + MODERATION(Emoji.fromFormatted("U+1F6E0"), "Moderation"), + UTILITY(Emoji.fromFormatted("U+1F6E0"), "Utility"), + MUSIC(Emoji.fromFormatted("U+1F3B5"), "Music"), + MOVIES_TV(Emoji.fromFormatted("U+1F3A5"), "Movies & TV"), + MESSAGES(Emoji.fromFormatted("U+1F4A3"), "Messages"), + LOGS(Emoji.fromFormatted("U+1F4D1"), "Logs"), + BEAT_SABER(Emoji.fromFormatted("U+1FA84"), "Beat Saber"); /** * The emoji for the category */ - private final Emoji emoji; + @NonNull private final Emoji emoji; /** * The name of the category */ - private final String name; - - /** - * If the category is hidden - */ - private final boolean hidden; + @NonNull private final String name; /** * Gets a category by its name @@ -54,13 +46,4 @@ public enum Category { } return null; } - - /** - * Gets all the visible categories - * - * @return the visible categories - */ - public static List getCategories() { - return Arrays.stream(Category.values()).filter(category -> !category.isHidden()).toList(); - } } diff --git a/src/main/java/cc/fascinated/bat/command/CommandInfo.java b/src/main/java/cc/fascinated/bat/command/CommandInfo.java index 37b87d1..69cfcea 100644 --- a/src/main/java/cc/fascinated/bat/command/CommandInfo.java +++ b/src/main/java/cc/fascinated/bat/command/CommandInfo.java @@ -8,6 +8,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + * Annotated at the top of a class to define + * the default values for a {@link BatCommand}. + * * @author Fascinated (fascinated7) */ @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/cc/fascinated/bat/command/InternalCommandInfo.java b/src/main/java/cc/fascinated/bat/command/InternalCommandInfo.java new file mode 100644 index 0000000..d74f547 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/command/InternalCommandInfo.java @@ -0,0 +1,60 @@ +package cc.fascinated.bat.command; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import net.dv8tion.jda.api.Permission; + +/** + * The internal command info of a {@link BatCommand}. + * + * @author Braydon + */ +@Setter(AccessLevel.PROTECTED) @Getter +public class InternalCommandInfo { + /** + * The name of the command. + */ + @NonNull private final String name; + + /** + * The description of the command. + */ + @NonNull private final String description; + + /** + * The category of the command. + */ + @NonNull private Category category; + + /** + * The permissions required to run this command, if any. + */ + private Permission[] permissions; + + /** + * Whether this command can only be ran within a guild. + */ + private boolean guildOnly; + + /** + * Whether this command can be user installed. + */ + private final boolean userInstall; + + /** + * Whether the command can only be ran by the bot owner. + */ + private boolean botOwnerOnly; + + protected InternalCommandInfo(@NonNull CommandInfo annotation) { + name = annotation.name(); + description = annotation.description(); + category = annotation.category(); + permissions = annotation.requiredPermissions(); + guildOnly = annotation.guildOnly(); + userInstall = annotation.userInstall(); + botOwnerOnly = annotation.botOwnerOnly(); + } +} \ No newline at end of file diff --git a/src/main/java/cc/fascinated/bat/features/Feature.java b/src/main/java/cc/fascinated/bat/features/Feature.java index da20511..8a03737 100644 --- a/src/main/java/cc/fascinated/bat/features/Feature.java +++ b/src/main/java/cc/fascinated/bat/features/Feature.java @@ -37,11 +37,10 @@ public abstract class Feature { * @param command The command to register */ public void registerCommand(@NonNull CommandService commandService, @NonNull BatCommand command) { - // If the command using the default category then set the category to the feature's category - if (command.getCategory() == Category.GENERAL) { - command.setCategory(this.category); - } command.setFeature(this); + for (BatCommand subCommand : command.getSubCommands().values()) { + subCommand.setFeature(this); + } commandService.registerCommand(command); } } diff --git a/src/main/java/cc/fascinated/bat/features/afk/command/AfkCommand.java b/src/main/java/cc/fascinated/bat/features/afk/command/AfkCommand.java index bf52eeb..76d0a2d 100644 --- a/src/main/java/cc/fascinated/bat/features/afk/command/AfkCommand.java +++ b/src/main/java/cc/fascinated/bat/features/afk/command/AfkCommand.java @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.stereotype.Component; /** @@ -21,9 +22,18 @@ import org.springframework.stereotype.Component; @CommandInfo(name = "afk", description = "Sets your AFK status") public class AfkCommand extends BatCommand { public AfkCommand() { - super.addOption(OptionType.STRING, "reason", "The reason for being AFK", false); + super.addOptions(new OptionData(OptionType.STRING, "reason", "The reason for being AFK", false)); } + /** + * Fired when this command is executed. + * + * @param guild the guild the command was executed in, if any + * @param user the user who executed the command + * @param channel the channel the command was executed in + * @param member the member who executed the command, null if not a guild + * @param event the event that invoked this command + */ @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { AfkProfile profile = guild.getProfile(AfkProfile.class); diff --git a/src/main/java/cc/fascinated/bat/features/autorole/command/AddSubCommand.java b/src/main/java/cc/fascinated/bat/features/autorole/command/AddSubCommand.java index 2f3cb7d..5c2da44 100644 --- a/src/main/java/cc/fascinated/bat/features/autorole/command/AddSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/autorole/command/AddSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.autorole.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.RoleUtils; @@ -14,6 +14,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -22,10 +23,10 @@ import org.springframework.stereotype.Component; */ @Component("autoroles:add.sub") @CommandInfo(name = "add", description = "Adds a role to the auto roles list") -public class AddSubCommand extends BatSubCommand { +public class AddSubCommand extends BatCommand { @Autowired public AddSubCommand() { - super.addOption(OptionType.ROLE, "role", "The role to add", true); + super.addOptions(new OptionData(OptionType.ROLE, "role", "The role to add", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/autorole/command/AutoRoleCommand.java b/src/main/java/cc/fascinated/bat/features/autorole/command/AutoRoleCommand.java index 78d1d6a..c225042 100644 --- a/src/main/java/cc/fascinated/bat/features/autorole/command/AutoRoleCommand.java +++ b/src/main/java/cc/fascinated/bat/features/autorole/command/AutoRoleCommand.java @@ -14,9 +14,11 @@ import org.springframework.stereotype.Component; @CommandInfo(name = "autorole", description = "Set up the automatic role system for members on join", requiredPermissions = Permission.MANAGE_SERVER) public class AutoRoleCommand extends BatCommand { public AutoRoleCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(ListSubCommand.class)); - super.addSubCommand(context.getBean(AddSubCommand.class)); - super.addSubCommand(context.getBean(RemoveSubCommand.class)); - super.addSubCommand(context.getBean(ClearSubCommand.class)); + super.addSubCommands( + context.getBean(ListSubCommand.class), + context.getBean(AddSubCommand.class), + context.getBean(RemoveSubCommand.class), + context.getBean(ClearSubCommand.class) + ); } } diff --git a/src/main/java/cc/fascinated/bat/features/autorole/command/ClearSubCommand.java b/src/main/java/cc/fascinated/bat/features/autorole/command/ClearSubCommand.java index cc40347..1a66939 100644 --- a/src/main/java/cc/fascinated/bat/features/autorole/command/ClearSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/autorole/command/ClearSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.autorole.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.autorole.profile.AutoRoleProfile; @@ -17,7 +17,7 @@ import org.springframework.stereotype.Component; */ @Component("autoroles:clear.sub") @CommandInfo(name = "clear", description = "Clears all auto roles") -public class ClearSubCommand extends BatSubCommand { +public class ClearSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { AutoRoleProfile profile = guild.getProfile(AutoRoleProfile.class); diff --git a/src/main/java/cc/fascinated/bat/features/autorole/command/ListSubCommand.java b/src/main/java/cc/fascinated/bat/features/autorole/command/ListSubCommand.java index 69cdd12..599a213 100644 --- a/src/main/java/cc/fascinated/bat/features/autorole/command/ListSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/autorole/command/ListSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.autorole.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.autorole.profile.AutoRoleProfile; @@ -18,7 +18,7 @@ import org.springframework.stereotype.Component; */ @Component("autoroles:list.sub") @CommandInfo(name = "list", description = "Lists all auto roles") -public class ListSubCommand extends BatSubCommand { +public class ListSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { AutoRoleProfile profile = guild.getProfile(AutoRoleProfile.class); diff --git a/src/main/java/cc/fascinated/bat/features/autorole/command/RemoveSubCommand.java b/src/main/java/cc/fascinated/bat/features/autorole/command/RemoveSubCommand.java index 1b82449..ec32401 100644 --- a/src/main/java/cc/fascinated/bat/features/autorole/command/RemoveSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/autorole/command/RemoveSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.autorole.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.autorole.profile.AutoRoleProfile; @@ -13,6 +13,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -21,10 +22,10 @@ import org.springframework.stereotype.Component; */ @Component("autoroles:remove.sub") @CommandInfo(name = "remove", description = "Removes a role from the auto roles list") -public class RemoveSubCommand extends BatSubCommand { +public class RemoveSubCommand extends BatCommand { @Autowired public RemoveSubCommand() { - super.addOption(OptionType.ROLE, "role", "The role to remove", true); + super.addOptions(new OptionData(OptionType.ROLE, "role", "The role to remove", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/PremiumAdminCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/PremiumAdminCommand.java index 07aba0b..8580cc4 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/PremiumAdminCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/PremiumAdminCommand.java @@ -1,7 +1,6 @@ package cc.fascinated.bat.features.base.commands.botadmin.premium; import cc.fascinated.bat.command.BatCommand; -import cc.fascinated.bat.command.Category; import cc.fascinated.bat.command.CommandInfo; import lombok.NonNull; import org.springframework.beans.factory.annotation.Autowired; @@ -12,11 +11,13 @@ import org.springframework.stereotype.Component; * @author Fascinated (fascinated7) */ @Component -@CommandInfo(name = "premiumadmin", description = "Set a guild as premium", botOwnerOnly = true, category = Category.BOT_ADMIN) +@CommandInfo(name = "premiumadmin", description = "Set a guild as premium", botOwnerOnly = true) public class PremiumAdminCommand extends BatCommand { @Autowired public PremiumAdminCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(SetSubCommand.class)); - super.addSubCommand(context.getBean(RemoveSubCommand.class)); + super.addSubCommands( + context.getBean(SetSubCommand.class), + context.getBean(RemoveSubCommand.class) + ); } } diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/RemoveSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/RemoveSubCommand.java index 70dfcb1..92dafd0 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/RemoveSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/RemoveSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.botadmin.premium; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -20,13 +21,13 @@ import org.springframework.stereotype.Component; */ @Component @CommandInfo(name = "remove", description = "Remove premium from a guild") -public class RemoveSubCommand extends BatSubCommand { +public class RemoveSubCommand extends BatCommand { private final GuildService guildService; @Autowired public RemoveSubCommand(GuildService guildService) { this.guildService = guildService; - super.addOption(OptionType.STRING, "guild", "The guild id to set as premium", true); + super.addOptions(new OptionData(OptionType.STRING, "guild", "The guild id to set as premium", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/SetSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/SetSubCommand.java index 917e02a..0ff4c65 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/SetSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/botadmin/premium/SetSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.botadmin.premium; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -20,14 +21,16 @@ import org.springframework.stereotype.Component; */ @Component @CommandInfo(name = "set", description = "Adds premium to a guild") -public class SetSubCommand extends BatSubCommand { +public class SetSubCommand extends BatCommand { private final GuildService guildService; @Autowired public SetSubCommand(@NonNull GuildService guildService) { this.guildService = guildService; - super.addOption(OptionType.STRING, "guild", "The guild id to set as premium", true); - super.addOption(OptionType.BOOLEAN, "infinite", "Whether the premium length should be infinite", true); + super.addOptions( + new OptionData(OptionType.STRING, "guild", "The guild id to set as premium", true), + new OptionData(OptionType.BOOLEAN, "infinite", "Whether the premium length should be infinite", true) + ); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/discord/LookupUserCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/discord/LookupUserCommand.java index 67d17d6..73477a2 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/discord/LookupUserCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/discord/LookupUserCommand.java @@ -15,6 +15,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.stereotype.Component; /** @@ -24,7 +25,7 @@ import org.springframework.stereotype.Component; @CommandInfo(name = "lookupuser", description = "Lookup a user", userInstall = true) public class LookupUserCommand extends BatCommand { public LookupUserCommand() { - super.addOption(OptionType.STRING, "id", "The id of the user", true); + super.addOptions(new OptionData(OptionType.STRING, "id", "The id of the user", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/fun/EightBallCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/fun/EightBallCommand.java index 2cffb37..4c36d12 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/fun/EightBallCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/fun/EightBallCommand.java @@ -11,6 +11,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.stereotype.Component; /** @@ -43,7 +44,7 @@ public class EightBallCommand extends BatCommand { }; public EightBallCommand() { - super.addOption(OptionType.STRING, "question", "The question you want to ask the 8ball", true); + super.addOptions(new OptionData(OptionType.STRING, "question", "The question you want to ask the 8ball", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/CatSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/CatSubCommand.java index b5616e1..35ff9eb 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/CatSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/CatSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.fun.image; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.WebRequest; @@ -18,7 +18,7 @@ import org.springframework.stereotype.Component; */ @Component @CommandInfo(name = "cat", description = "Get a random cat image") -public class CatSubCommand extends BatSubCommand { +public class CatSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { CatImageToken[] responseEntity = WebRequest.getAsEntity("https://api.thecatapi.com/v1/images/search", CatImageToken[].class); diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/DogSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/DogSubCommand.java index 79973d8..754a36c 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/DogSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/DogSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.fun.image; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.WebRequest; @@ -18,7 +18,7 @@ import org.springframework.stereotype.Component; */ @Component @CommandInfo(name = "dog", description = "Get a random dog image") -public class DogSubCommand extends BatSubCommand { +public class DogSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { RandomImage responseEntity = WebRequest.getAsEntity("https://dog.ceo/api/breeds/image/random", RandomImage.class); diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/DuckSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/DuckSubCommand.java index c610d0b..788af42 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/DuckSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/DuckSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.fun.image; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.WebRequest; @@ -18,7 +18,7 @@ import org.springframework.stereotype.Component; */ @Component @CommandInfo(name = "duck", description = "Get a random duck image") -public class DuckSubCommand extends BatSubCommand { +public class DuckSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { RandomDuck responseEntity = WebRequest.getAsEntity("https://random-d.uk/api/v2/random", RandomDuck.class); diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/FoxSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/FoxSubCommand.java index f8f063e..a6c9a7d 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/FoxSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/FoxSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.fun.image; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.WebRequest; @@ -18,7 +18,7 @@ import org.springframework.stereotype.Component; */ @Component @CommandInfo(name = "fox", description = "Get a random fox image") -public class FoxSubCommand extends BatSubCommand { +public class FoxSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { RandomFoxToken responseEntity = WebRequest.getAsEntity("https://randomfox.ca/floof/", RandomFoxToken.class); diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/ImageCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/ImageCommand.java index b5fa921..d554844 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/ImageCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/fun/image/ImageCommand.java @@ -16,9 +16,11 @@ import org.springframework.stereotype.Component; public class ImageCommand extends BatCommand { @Autowired public ImageCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(CatSubCommand.class)); - super.addSubCommand(context.getBean(DogSubCommand.class)); - super.addSubCommand(context.getBean(FoxSubCommand.class)); - super.addSubCommand(context.getBean(DuckSubCommand.class)); + super.addSubCommands( + context.getBean(CatSubCommand.class), + context.getBean(DogSubCommand.class), + context.getBean(FoxSubCommand.class), + context.getBean(DuckSubCommand.class) + ); } } diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/HelpCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/HelpCommand.java index 0367a2e..e8a0bf7 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/HelpCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/HelpCommand.java @@ -2,7 +2,6 @@ package cc.fascinated.bat.features.base.commands.general; 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.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; @@ -17,7 +16,6 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.entities.emoji.Emoji; 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.LayoutComponent; import net.dv8tion.jda.api.interactions.components.buttons.Button; @@ -29,7 +27,6 @@ import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; -import java.util.Map; /** * @author Fascinated (fascinated7) @@ -62,44 +59,45 @@ public class HelpCommand extends BatCommand implements EventListener { event.reply("Invalid category selected.").queue(); return; } + event.reply("hello this doesnt work yet").queue(); - StringBuilder commands = new StringBuilder(); - List categoryCommands = commandService.getCommandsByCategory(category, true); - if (categoryCommands.isEmpty()) { - commands = new StringBuilder("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.append(" - %s\n".formatted( - command.getCommandInfo().name(), - commandData.getName(), - subCommand.getCommandSnowflake(), - commandData.getDescription() - )); - } - continue; - } - commands.append(" - %s\n".formatted( - command.getCommandInfo().name(), - command.getCommandSnowflake(), - command.getCommandInfo().description() - )); - } - } - - int subCommands = categoryCommands.stream().mapToInt(command -> command.getSubCommands().size()).sum(); - event.editMessageEmbeds(EmbedUtils.genericEmbed() - .setAuthor("%s Category".formatted(category.getName())) - .setDescription("%s command%s (with %s sub-command%s)\n\n**Commands:**\n%s".formatted( - categoryCommands.size(), - categoryCommands.size() == 1 ? "" : "s", - subCommands, - subCommands == 1 ? "" : "s", - commands.toString() - )).build()).queue(); +// StringBuilder commands = new StringBuilder(); +// List categoryCommands = commandService.getCommandsByCategory(category, true); +// if (categoryCommands.isEmpty()) { +// commands = new StringBuilder("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.append(" - %s\n".formatted( +// command.getCommandInfo().name(), +// commandData.getName(), +// subCommand.getCommandSnowflake(), +// commandData.getDescription() +// )); +// } +// continue; +// } +// commands.append(" - %s\n".formatted( +// command.getCommandInfo().name(), +// command.getCommandSnowflake(), +// command.getCommandInfo().description() +// )); +// } +// } +// +// int subCommands = categoryCommands.stream().mapToInt(command -> command.getSubCommands().size()).sum(); +// event.editMessageEmbeds(EmbedUtils.genericEmbed() +// .setAuthor("%s Category".formatted(category.getName())) +// .setDescription("%s command%s (with %s sub-command%s)\n\n**Commands:**\n%s".formatted( +// categoryCommands.size(), +// categoryCommands.size() == 1 ? "" : "s", +// subCommands, +// subCommands == 1 ? "" : "s", +// commands.toString() +// )).build()).queue(); } /** @@ -109,8 +107,8 @@ public class HelpCommand extends BatCommand implements EventListener { */ private MessageEmbed createHomeEmbed() { StringBuilder categories = new StringBuilder(); - for (Category category : Category.getCategories()) { - long commandCount = commandService.getCommandsByCategory(category, true).size(); + for (Category category : Category.values()) { + long commandCount = commandService.getCommandsByCategory(category).size(); categories.append("➜ %s - **%s Command%s**\n".formatted( category.getName(), commandCount, @@ -140,9 +138,9 @@ public class HelpCommand extends BatCommand implements EventListener { private LayoutComponent[] createHomeActions() { List options = new ArrayList<>(); options.add(SelectOption.of("Home", "home").withEmoji(Emoji.fromUnicode("U+1F3E0"))); - options.addAll(Category.getCategories().stream().map(category -> - SelectOption.of(category.getName(), category.getName()).withEmoji(category.getEmoji())) - .toList()); + for (Category category : Category.values()) { + options.add(SelectOption.of(category.getName(), category.getName()).withEmoji(category.getEmoji())); + } return new LayoutComponent[]{ ActionRow.of( diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/AvatarCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/AvatarCommand.java index 67f7905..bc1bc79 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/AvatarCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/AvatarCommand.java @@ -15,7 +15,9 @@ import org.springframework.stereotype.Component; public class AvatarCommand extends BatCommand { @Autowired public AvatarCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(GuildSubCommand.class)); - super.addSubCommand(context.getBean(UserSubCommand.class)); + super.addSubCommands( + context.getBean(GuildSubCommand.class), + context.getBean(UserSubCommand.class) + ); } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/GuildSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/GuildSubCommand.java index eaf9952..f636a4e 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/GuildSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/GuildSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.general.avatar; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.model.BatGuild; @@ -17,7 +17,7 @@ import org.springframework.stereotype.Component; */ @Component("avatar:guild.sub") @CommandInfo(name = "guild", description = "View the avatar of the guild") -public class GuildSubCommand extends BatSubCommand { +public class GuildSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { ImageProxy icon = guild.getDiscordGuild().getIcon(); diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/UserSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/UserSubCommand.java index 06c099d..1edbbbc 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/UserSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/avatar/UserSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.general.avatar; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.model.BatGuild; @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.stereotype.Component; /** @@ -19,9 +20,9 @@ import org.springframework.stereotype.Component; */ @Component("avatar:user.sub") @CommandInfo(name = "user", description = "View the avatar of a user", guildOnly = false) -public class UserSubCommand extends BatSubCommand { +public class UserSubCommand extends BatCommand { public UserSubCommand() { - super.addOption(OptionType.USER, "user", "The user to view the avatar of", true); + super.addOptions(new OptionData(OptionType.USER, "user", "The user to view the avatar of", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/BannerCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/BannerCommand.java index cadc23b..f59119b 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/BannerCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/BannerCommand.java @@ -15,7 +15,9 @@ import org.springframework.stereotype.Component; public class BannerCommand extends BatCommand { @Autowired public BannerCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(GuildSubCommand.class)); - super.addSubCommand(context.getBean(UserSubCommand.class)); + super.addSubCommands( + context.getBean(GuildSubCommand.class), + context.getBean(UserSubCommand.class) + ); } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/GuildSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/GuildSubCommand.java index a34c48b..6fed0a2 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/GuildSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/GuildSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.general.banner; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.model.BatGuild; @@ -17,7 +17,7 @@ import org.springframework.stereotype.Component; */ @Component("banner:guild.sub") @CommandInfo(name = "guild", description = "View the banner of the guild") -public class GuildSubCommand extends BatSubCommand { +public class GuildSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { ImageProxy banner = guild.getDiscordGuild().getBanner(); diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/UserSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/UserSubCommand.java index abff18a..82633fd 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/UserSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/general/banner/UserSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.general.banner; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.model.BatGuild; @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.utils.ImageProxy; import org.springframework.stereotype.Component; @@ -20,9 +21,9 @@ import org.springframework.stereotype.Component; */ @Component("banner:user.sub") @CommandInfo(name = "user", description = "View the banner of a user", guildOnly = false) -public class UserSubCommand extends BatSubCommand { +public class UserSubCommand extends BatCommand { public UserSubCommand() { - super.addOption(OptionType.USER, "user", "The user to view the banner of", true); + super.addOptions(new OptionData(OptionType.USER, "user", "The user to view the banner of", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/ChannelCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/ChannelCommand.java index 8c21278..dc44c37 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/ChannelCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/ChannelCommand.java @@ -16,8 +16,10 @@ import org.springframework.stereotype.Component; public class ChannelCommand extends BatCommand { @Autowired public ChannelCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(ViewTopicSubCommand.class)); - super.addSubCommand(context.getBean(SetTopicSubCommand.class)); - super.addSubCommand(context.getBean(RemoveTopicSubCommand.class)); + super.addSubCommands( + context.getBean(ViewTopicSubCommand.class), + context.getBean(SetTopicSubCommand.class), + context.getBean(RemoveTopicSubCommand.class) + ); } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/RemoveTopicSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/RemoveTopicSubCommand.java index ebd54a9..6e4ebb1 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/RemoveTopicSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/RemoveTopicSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.server.channel; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.model.BatGuild; @@ -13,6 +13,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.stereotype.Component; /** @@ -20,9 +21,9 @@ import org.springframework.stereotype.Component; */ @Component @CommandInfo(name = "removetopic", description = "Remove the topic of a channel", requiredPermissions = Permission.MANAGE_CHANNEL) -public class RemoveTopicSubCommand extends BatSubCommand { +public class RemoveTopicSubCommand extends BatCommand { public RemoveTopicSubCommand() { - super.addOption(OptionType.CHANNEL, "channel", "The channel to remove the topic of", false); + super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel to remove the topic of", false)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/SetTopicSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/SetTopicSubCommand.java index 5a510bd..f3e26d4 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/SetTopicSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/SetTopicSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.server.channel; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.model.BatGuild; @@ -13,22 +13,27 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.stereotype.Component; +import java.util.Objects; + /** * @author Nick (okNick) */ @Component @CommandInfo(name = "settopic", description = "Set the topic of a channel", requiredPermissions = Permission.MANAGE_CHANNEL) -public class SetTopicSubCommand extends BatSubCommand { +public class SetTopicSubCommand extends BatCommand { public SetTopicSubCommand() { - super.addOption(OptionType.STRING, "topic", "The topic to set", true); - super.addOption(OptionType.CHANNEL, "channel", "The channel to set the topic of", false); + super.addOptions( + new OptionData(OptionType.STRING, "topic", "The topic to set", true), + new OptionData(OptionType.CHANNEL, "channel", "The channel to set the topic of", false) + ); } @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { - Channel target = event.getOption("channel") == null ? channel : event.getOption("channel").getAsChannel(); + Channel target = event.getOption("channel") == null ? channel : Objects.requireNonNull(event.getOption("channel")).getAsChannel(); if (!(target instanceof TextChannel textChannel)) { event.replyEmbeds(EmbedUtils.errorEmbed() .setDescription("<#%s> is not a text channel!".formatted(target.getId())) @@ -37,7 +42,7 @@ public class SetTopicSubCommand extends BatSubCommand { return; } - String topic = event.getOption("topic").getAsString(); + String topic = Objects.requireNonNull(event.getOption("topic")).getAsString(); if (topic.length() > 1024) { event.replyEmbeds(EmbedUtils.errorEmbed() .setDescription("The topic must be 1024 characters or less!") diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/ViewTopicSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/ViewTopicSubCommand.java index c0ee574..482359e 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/ViewTopicSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/channel/ViewTopicSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.server.channel; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.model.BatGuild; @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.stereotype.Component; /** @@ -19,9 +20,9 @@ import org.springframework.stereotype.Component; */ @Component @CommandInfo(name = "viewtopic", description = "View the topic of a channel") -public class ViewTopicSubCommand extends BatSubCommand { +public class ViewTopicSubCommand extends BatCommand { public ViewTopicSubCommand() { - super.addOption(OptionType.CHANNEL, "channel", "The channel to view the topic of", false); + super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel to view the topic of", false)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/DisableSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/DisableSubCommand.java index aacb790..f1c7410 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/DisableSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/DisableSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.server.feature; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.Feature; @@ -14,6 +14,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -22,10 +23,10 @@ import org.springframework.stereotype.Component; */ @Component("feature:disable.sub") @CommandInfo(name = "disable", description = "Disables a feature") -public class DisableSubCommand extends BatSubCommand { +public class DisableSubCommand extends BatCommand { @Autowired public DisableSubCommand() { - super.addOption(OptionType.STRING, "feature", "The feature to disable", true); + super.addOptions(new OptionData(OptionType.STRING, "feature", "The feature to disable", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/EnableSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/EnableSubCommand.java index 316c05a..ec1fa38 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/EnableSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/EnableSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.server.feature; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.Feature; @@ -14,6 +14,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -22,10 +23,10 @@ import org.springframework.stereotype.Component; */ @Component("feature:enable.sub") @CommandInfo(name = "enable", description = "Enables a feature") -public class EnableSubCommand extends BatSubCommand { +public class EnableSubCommand extends BatCommand { @Autowired public EnableSubCommand() { - super.addOption(OptionType.STRING, "feature", "The feature to enable", true); + super.addOptions(new OptionData(OptionType.STRING, "feature", "The feature to enable", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/FeatureCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/FeatureCommand.java index 7e4dbf0..5e79b3b 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/FeatureCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/FeatureCommand.java @@ -17,8 +17,10 @@ import org.springframework.stereotype.Component; public class FeatureCommand extends BatCommand { @Autowired public FeatureCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(EnableSubCommand.class)); - super.addSubCommand(context.getBean(DisableSubCommand.class)); - super.addSubCommand(context.getBean(ListSubCommand.class)); + super.addSubCommands( + context.getBean(EnableSubCommand.class), + context.getBean(DisableSubCommand.class), + context.getBean(ListSubCommand.class) + ); } } diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/ListSubCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/ListSubCommand.java index f5cbbcb..f9f36aa 100644 --- a/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/ListSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/base/commands/server/feature/ListSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.base.commands.server.feature; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.Feature; @@ -19,7 +19,7 @@ import org.springframework.stereotype.Component; */ @Component("feature:list.sub") @CommandInfo(name = "list", description = "Lists the features and their states") -public class ListSubCommand extends BatSubCommand { +public class ListSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { StringBuilder featureStates = new StringBuilder(); diff --git a/src/main/java/cc/fascinated/bat/features/birthday/command/BirthdayCommand.java b/src/main/java/cc/fascinated/bat/features/birthday/command/BirthdayCommand.java index 8518fa6..ddf09a5 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/command/BirthdayCommand.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/command/BirthdayCommand.java @@ -15,11 +15,13 @@ import org.springframework.stereotype.Component; public class BirthdayCommand extends BatCommand { @Autowired public BirthdayCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(SetSubCommand.class)); - super.addSubCommand(context.getBean(RemoveSubCommand.class)); - super.addSubCommand(context.getBean(ChannelSubCommand.class)); - super.addSubCommand(context.getBean(MessageSubCommand.class)); - super.addSubCommand(context.getBean(ViewSubCommand.class)); - super.addSubCommand(context.getBean(PrivateSubCommand.class)); + super.addSubCommands( + context.getBean(SetSubCommand.class), + context.getBean(RemoveSubCommand.class), + context.getBean(ChannelSubCommand.class), + context.getBean(MessageSubCommand.class), + context.getBean(ViewSubCommand.class), + context.getBean(PrivateSubCommand.class) + ); } } diff --git a/src/main/java/cc/fascinated/bat/features/birthday/command/ChannelSubCommand.java b/src/main/java/cc/fascinated/bat/features/birthday/command/ChannelSubCommand.java index f0eeec9..92b6a46 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/command/ChannelSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/command/ChannelSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.birthday.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.TextChannelUtils; @@ -16,6 +16,7 @@ import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -24,10 +25,10 @@ import org.springframework.stereotype.Component; */ @Component("birthday:channel.sub") @CommandInfo(name = "channel", description = "Sets the birthday notification channel", requiredPermissions = Permission.MANAGE_SERVER) -public class ChannelSubCommand extends BatSubCommand { +public class ChannelSubCommand extends BatCommand { @Autowired public ChannelSubCommand() { - super.addOption(OptionType.CHANNEL, "channel", "The channel birthdays will be sent in", false); + super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel birthdays will be sent in", false)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/birthday/command/MessageSubCommand.java b/src/main/java/cc/fascinated/bat/features/birthday/command/MessageSubCommand.java index 3f4a8f5..d4145ed 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/command/MessageSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/command/MessageSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.birthday.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.birthday.profile.BirthdayProfile; @@ -13,6 +13,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -22,10 +23,10 @@ import org.springframework.stereotype.Component; */ @Component("birthday:message.sub") @CommandInfo(name = "message", description = "Changes the message that is sent when it is a user's birthday", requiredPermissions = Permission.MANAGE_SERVER) -public class MessageSubCommand extends BatSubCommand { +public class MessageSubCommand extends BatCommand { @Autowired public MessageSubCommand() { - super.addOption(OptionType.STRING, "message", "The message that is sent. (Placeholders: {user}, {age})", true); + super.addOptions(new OptionData(OptionType.STRING, "message", "The message that is sent. (Placeholders: {user}, {age})", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/birthday/command/PrivateSubCommand.java b/src/main/java/cc/fascinated/bat/features/birthday/command/PrivateSubCommand.java index abdc3ab..7c07259 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/command/PrivateSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/command/PrivateSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.birthday.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.birthday.UserBirthday; @@ -13,6 +13,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -22,10 +23,10 @@ import org.springframework.stereotype.Component; */ @Component("birthday:private.sub") @CommandInfo(name = "private", description = "Changes whether your birthday is private or not") -public class PrivateSubCommand extends BatSubCommand { +public class PrivateSubCommand extends BatCommand { @Autowired public PrivateSubCommand() { - super.addOption(OptionType.BOOLEAN, "enabled", "Whether your birthday is private or not", true); + super.addOptions(new OptionData(OptionType.BOOLEAN, "enabled", "Whether your birthday is private or not", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/birthday/command/RemoveSubCommand.java b/src/main/java/cc/fascinated/bat/features/birthday/command/RemoveSubCommand.java index fdfd0c8..8fe26d3 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/command/RemoveSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/command/RemoveSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.birthday.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.birthday.profile.BirthdayProfile; @@ -18,7 +18,7 @@ import org.springframework.stereotype.Component; */ @Component("birthday:remove.sub") @CommandInfo(name = "remove", description = "Remove your birthday from this guild") -public class RemoveSubCommand extends BatSubCommand { +public class RemoveSubCommand extends BatCommand { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { BirthdayProfile profile = guild.getBirthdayProfile(); diff --git a/src/main/java/cc/fascinated/bat/features/birthday/command/SetSubCommand.java b/src/main/java/cc/fascinated/bat/features/birthday/command/SetSubCommand.java index 43e91bb..9c335a8 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/command/SetSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/command/SetSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.birthday.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.birthday.UserBirthday; @@ -13,6 +13,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -26,12 +27,12 @@ import java.util.Date; */ @Component("birthday:add.sub") @CommandInfo(name = "set", description = "Add your birthday to this guild") -public class SetSubCommand extends BatSubCommand { +public class SetSubCommand extends BatCommand { private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("dd/MM/yyyy"); @Autowired public SetSubCommand() { - super.addOption(OptionType.STRING, "birthday", "Your birthday (format: DAY/MONTH/YEAR - 01/05/2004)", true); + super.addOptions(new OptionData(OptionType.STRING, "birthday", "Your birthday (format: DAY/MONTH/YEAR - 01/05/2004)", true)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/birthday/command/ViewSubCommand.java b/src/main/java/cc/fascinated/bat/features/birthday/command/ViewSubCommand.java index 45c245c..5c09ad9 100644 --- a/src/main/java/cc/fascinated/bat/features/birthday/command/ViewSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/birthday/command/ViewSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.birthday.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.features.birthday.UserBirthday; @@ -14,6 +14,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -23,13 +24,13 @@ import org.springframework.stereotype.Component; */ @Component("birthday:view.sub") @CommandInfo(name = "view", description = "Add your birthday to this guild") -public class ViewSubCommand extends BatSubCommand { +public class ViewSubCommand extends BatCommand { private final UserService userService; @Autowired public ViewSubCommand(@NonNull UserService userService) { this.userService = userService; - super.addOption(OptionType.USER, "user", "The user to view the birthday of", false); + super.addOptions(new OptionData(OptionType.USER, "user", "The user to view the birthday of", false)); } @Override diff --git a/src/main/java/cc/fascinated/bat/features/drag/command/DragCommand.java b/src/main/java/cc/fascinated/bat/features/drag/command/DragCommand.java index a832c18..c5ac145 100644 --- a/src/main/java/cc/fascinated/bat/features/drag/command/DragCommand.java +++ b/src/main/java/cc/fascinated/bat/features/drag/command/DragCommand.java @@ -15,6 +15,6 @@ import org.springframework.stereotype.Component; public class DragCommand extends BatCommand { @Autowired public DragCommand(@NonNull ApplicationContext context) { - super.addSubCommand(context.getBean(RequestSubCommand.class)); + super.addSubCommands(context.getBean(RequestSubCommand.class)); } } diff --git a/src/main/java/cc/fascinated/bat/features/drag/command/RequestSubCommand.java b/src/main/java/cc/fascinated/bat/features/drag/command/RequestSubCommand.java index 13ecee6..f04caab 100644 --- a/src/main/java/cc/fascinated/bat/features/drag/command/RequestSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/drag/command/RequestSubCommand.java @@ -1,6 +1,6 @@ package cc.fascinated.bat.features.drag.command; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedUtils; import cc.fascinated.bat.common.TimerUtils; @@ -16,6 +16,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.springframework.stereotype.Component; @@ -30,7 +31,7 @@ import java.util.Set; */ @Component @CommandInfo(name = "request", description = "Request to be moved to a voice channel") -public class RequestSubCommand extends BatSubCommand implements EventListener { +public class RequestSubCommand extends BatCommand implements EventListener { /** * A list of join requests */ @@ -40,7 +41,7 @@ public class RequestSubCommand extends BatSubCommand implements EventListener { private final long checkInterval = Duration.ofSeconds(10).toMillis(); public RequestSubCommand() { - super.addOption(OptionType.USER, "user", "The user you want to join", true); + super.addOptions(new OptionData(OptionType.USER, "user", "The user you want to join", true)); TimerUtils.scheduleRepeating(() -> { Set toRemove = new HashSet<>(); diff --git a/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java b/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java index 050050b..6ec94ee 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/logging/command/ListSubCommand.java @@ -1,7 +1,7 @@ package cc.fascinated.bat.features.logging.command; import cc.fascinated.bat.Emojis; -import cc.fascinated.bat.command.BatSubCommand; +import cc.fascinated.bat.command.BatCommand; import cc.fascinated.bat.command.CommandInfo; import cc.fascinated.bat.common.EmbedDescriptionBuilder; import cc.fascinated.bat.common.EmbedUtils; @@ -30,7 +30,7 @@ import java.util.List; */ @Component("logs:list.sub") @CommandInfo(name = "list", description = "See all the log types and their channels") -public class ListSubCommand extends BatSubCommand implements EventListener { +public class ListSubCommand extends BatCommand implements EventListener { @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { List