diff --git a/src/main/java/xyz/dynxsty/dih4jda/DIH4JDA.java b/src/main/java/xyz/dynxsty/dih4jda/DIH4JDA.java index 4dd908f3..02a9245f 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/DIH4JDA.java +++ b/src/main/java/xyz/dynxsty/dih4jda/DIH4JDA.java @@ -6,9 +6,10 @@ import xyz.dynxsty.dih4jda.config.DIH4JDAConfig; import xyz.dynxsty.dih4jda.events.DIH4JDAEventListener; import xyz.dynxsty.dih4jda.exceptions.DIH4JDAException; -import xyz.dynxsty.dih4jda.interactions.commands.ContextCommand; -import xyz.dynxsty.dih4jda.interactions.commands.RegistrationType; -import xyz.dynxsty.dih4jda.interactions.commands.SlashCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.BaseApplicationCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.ContextCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.RegistrationType; +import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import xyz.dynxsty.dih4jda.interactions.components.ButtonHandler; import xyz.dynxsty.dih4jda.interactions.components.EntitySelectMenuHandler; import xyz.dynxsty.dih4jda.interactions.components.ModalHandler; @@ -38,9 +39,9 @@ public class DIH4JDA extends ListenerAdapter { /** * The default {@link RegistrationType} which is used for queuing new commands. - * This can be overridden using {@link xyz.dynxsty.dih4jda.interactions.commands.AbstractCommand#setRegistrationType(RegistrationType)} + * This can be overridden using {@link BaseApplicationCommand#setRegistrationType(RegistrationType)} */ - public static RegistrationType defaultCommandType; + private static RegistrationType defaultRegistrationType = RegistrationType.GLOBAL; // Component Handler private static final Map, ButtonHandler> buttonHandlers; @@ -64,8 +65,7 @@ public class DIH4JDA extends ListenerAdapter { * * @param config The instance's configuration. */ - protected DIH4JDA(DIH4JDAConfig config) throws DIH4JDAException { - if (defaultCommandType == null) defaultCommandType = RegistrationType.GUILD; + protected DIH4JDA(@Nonnull DIH4JDAConfig config) throws DIH4JDAException { this.config = config; listeners = new HashSet<>(); DIH4JDALogger.blockedLogTypes = config.getBlockedLogTypes(); @@ -91,6 +91,20 @@ public void onReady(@Nonnull ReadyEvent event) { } } + /** + * Sets the default {@link RegistrationType} for all Commands. + * This is set to {@link RegistrationType#GLOBAL} if not set otherwise. + * + * @param type The {@link RegistrationType}. + */ + public static void setDefaultRegistrationType(RegistrationType type) { + DIH4JDA.defaultRegistrationType = type; + } + + public static RegistrationType getDefaultRegistrationType() { + return defaultRegistrationType; + } + /** * Registers all Interactions and replaces the old ones. * Please note that global commands may need up to an hour before they're fully registered. @@ -157,7 +171,7 @@ public void addSlashCommands(SlashCommand... commands) { * * @param commands An array of commands to register. */ - public void addContextCommands(ContextCommand... commands) { + public void addContextCommands(ContextCommand... commands) { handler.contextCommands.addAll(List.of(commands)); } diff --git a/src/main/java/xyz/dynxsty/dih4jda/DIH4JDABuilder.java b/src/main/java/xyz/dynxsty/dih4jda/DIH4JDABuilder.java index 6e8e1fa3..10f17ae7 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/DIH4JDABuilder.java +++ b/src/main/java/xyz/dynxsty/dih4jda/DIH4JDABuilder.java @@ -1,11 +1,12 @@ package xyz.dynxsty.dih4jda; +import net.dv8tion.jda.annotations.ReplaceWith; import net.dv8tion.jda.api.JDA; import xyz.dynxsty.dih4jda.config.DIH4JDAConfig; import xyz.dynxsty.dih4jda.exceptions.CommandNotRegisteredException; import xyz.dynxsty.dih4jda.exceptions.DIH4JDAException; import xyz.dynxsty.dih4jda.exceptions.InvalidPackageException; -import xyz.dynxsty.dih4jda.interactions.commands.RegistrationType; +import xyz.dynxsty.dih4jda.interactions.commands.application.RegistrationType; import xyz.dynxsty.dih4jda.util.ClassWalker; import xyz.dynxsty.dih4jda.util.ClasspathHelper; @@ -111,16 +112,6 @@ private DIH4JDABuilder(@Nonnull JDA jda) { return this; } - /** - * Sets the default {@link RegistrationType} for all Commands. - * - * @param type The {@link RegistrationType}. - */ - public @Nonnull DIH4JDABuilder setDefaultCommandType(@Nonnull RegistrationType type) { - DIH4JDA.defaultCommandType = type; - return this; - } - /** * Disables deletion of unknown/unused commands when using SmartQueue. */ diff --git a/src/main/java/xyz/dynxsty/dih4jda/InteractionHandler.java b/src/main/java/xyz/dynxsty/dih4jda/InteractionHandler.java index 0984be17..595d4ae0 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/InteractionHandler.java +++ b/src/main/java/xyz/dynxsty/dih4jda/InteractionHandler.java @@ -31,11 +31,12 @@ import xyz.dynxsty.dih4jda.events.ModalExceptionEvent; import xyz.dynxsty.dih4jda.exceptions.CommandNotRegisteredException; import xyz.dynxsty.dih4jda.exceptions.DIH4JDAException; -import xyz.dynxsty.dih4jda.interactions.commands.AbstractCommand; -import xyz.dynxsty.dih4jda.interactions.commands.AutoCompletable; -import xyz.dynxsty.dih4jda.interactions.commands.ContextCommand; -import xyz.dynxsty.dih4jda.interactions.commands.RegistrationType; -import xyz.dynxsty.dih4jda.interactions.commands.SlashCommand; +import xyz.dynxsty.dih4jda.interactions.AutoCompletable; +import xyz.dynxsty.dih4jda.interactions.commands.application.ContextCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.ApplicationCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.RegistrationType; +import xyz.dynxsty.dih4jda.interactions.commands.RestrictedCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import xyz.dynxsty.dih4jda.interactions.components.ButtonHandler; import xyz.dynxsty.dih4jda.interactions.components.EntitySelectMenuHandler; import xyz.dynxsty.dih4jda.interactions.components.ModalHandler; @@ -77,7 +78,7 @@ public class InteractionHandler extends ListenerAdapter { } protected final Set slashCommands; - protected final Set contextCommands; + protected final Set> contextCommands; /** * The main {@link DIH4JDA} instance. */ @@ -166,10 +167,10 @@ public static Map getRetrievedCommands() { */ public void registerInteractions() throws ReflectiveOperationException { // retrieve (and smartqueue) guild commands - Pair, Set> data = new Pair<>(getSlashCommands(), getContextCommandData()); + Pair, Set>> data = new Pair<>(getSlashCommands(), getContextCommandData()); for (Guild guild : config.getJDA().getGuilds()) { guild.retrieveCommands().queue(existing -> { - Pair, Set> guildData = CommandUtils.filterByType(data, RegistrationType.GUILD); + Pair, Set>> guildData = CommandUtils.filterByType(data, RegistrationType.GUILD); existing.forEach(this::cacheCommand); // check if smart queuing is enabled if (config.isGuildSmartQueue()) { @@ -184,7 +185,7 @@ public void registerInteractions() throws ReflectiveOperationException { } // retrieve (and smartqueue) global commands config.getJDA().retrieveCommands().queue(existing -> { - Pair, Set> globalData = CommandUtils.filterByType(data, RegistrationType.GLOBAL); + Pair, Set>> globalData = CommandUtils.filterByType(data, RegistrationType.GLOBAL); existing.forEach(this::cacheCommand); // check if smart queuing is enabled if (config.isGlobalSmartQueue()) { @@ -212,8 +213,8 @@ public void registerInteractions() throws ReflectiveOperationException { * @param slashCommand A set of {@link SlashCommandData}. * @param contextCommands A set of {@link CommandData}, */ - private void upsert(@Nonnull JDA jda, @Nonnull Set slashCommand, @Nonnull Set contextCommands) { - slashCommand.forEach(data -> jda.upsertCommand(data.getSlashCommandData()).queue(this::cacheCommand)); + private void upsert(@Nonnull JDA jda, @Nonnull Set slashCommand, @Nonnull Set> contextCommands) { + slashCommand.forEach(data -> jda.upsertCommand(data.getCommandData()).queue(this::cacheCommand)); contextCommands.forEach(data -> jda.upsertCommand(data.getCommandData()).queue(this::cacheCommand)); } @@ -224,20 +225,20 @@ private void upsert(@Nonnull JDA jda, @Nonnull Set slashCommand, @ * @param slashCommands A set of {@link SlashCommandData}. * @param contextCommands A set of {@link CommandData}, */ - private void upsert(@Nonnull Guild guild, @Nonnull Set slashCommands, @Nonnull Set contextCommands) { + private void upsert(@Nonnull Guild guild, @Nonnull Set slashCommands, @Nonnull Set> contextCommands) { StringBuilder commandNames = new StringBuilder(); slashCommands.forEach(data -> { Pair pair = data.getRequiredGuilds(); if (pair.getFirst() == null) { - guild.upsertCommand(data.getSlashCommandData()).queue(this::cacheCommand); - commandNames.append(", /").append(data.getSlashCommandData().getName()); + guild.upsertCommand(data.getCommandData()).queue(this::cacheCommand); + commandNames.append(", /").append(data.getCommandData().getName()); } else { if (pair.getFirst()) { if (Arrays.asList(pair.getSecond()).contains(guild.getIdLong())) { - guild.upsertCommand(data.getSlashCommandData()).queue(this::cacheCommand); - commandNames.append(", /").append(data.getSlashCommandData().getName()); + guild.upsertCommand(data.getCommandData()).queue(this::cacheCommand); + commandNames.append(", /").append(data.getCommandData().getName()); } else { - DIH4JDALogger.info(DIH4JDALogger.Type.SLASH_COMMAND_SKIPPED, "Skipping Registration of /%s for Guild: %s", data.getSlashCommandData().getName(), guild.getName()); + DIH4JDALogger.info(DIH4JDALogger.Type.SLASH_COMMAND_SKIPPED, "Skipping Registration of /%s for Guild: %s", data.getCommandData().getName(), guild.getName()); } } } @@ -290,7 +291,7 @@ private void findContextCommands(String pkg) throws ReflectiveOperationException Set> subTypes = classes.getSubTypesOf(ContextCommand.class); for (Class subType : subTypes) { if (Checks.checkEmptyConstructor(subType)) { - contextCommands.add((ContextCommand) ClassUtils.getInstance(subType)); + contextCommands.add((ContextCommand) ClassUtils.getInstance(subType)); } else { DIH4JDALogger.error("Could not initialize %s! The class MUST contain a empty public constructor.", subType.getName()); } @@ -307,7 +308,7 @@ private void findContextCommands(String pkg) throws ReflectiveOperationException if (command != null) { SlashCommandData data = getBaseCommandData(command, command.getClass()); if (data != null) { - command.setSlashCommandData(data); + command.setCommandData(data); } if (command.getRegistrationType() != RegistrationType.GUILD && command.getRequiredGuilds().getFirst() != null && command.getRequiredGuilds().getSecond() != null && @@ -329,14 +330,14 @@ private void findContextCommands(String pkg) throws ReflectiveOperationException */ private void searchForAutoCompletable(@Nonnull SlashCommand command, @Nonnull Class clazz) { // check base command - String baseName = command.getSlashCommandData().getName(); + String baseName = command.getCommandData().getName(); if (Checks.checkImplementation(clazz, AutoCompletable.class)) { autoCompleteIndex.put(baseName, (AutoCompletable) command); } // check subcommands for (SlashCommand.Subcommand child : command.getSubcommands()) { if (Checks.checkImplementation(child.getClass(), AutoCompletable.class)) { - autoCompleteIndex.put(CommandUtils.buildCommandPath(baseName, child.getSubcommandData().getName()), (AutoCompletable) child); + autoCompleteIndex.put(CommandUtils.buildCommandPath(baseName, child.getCommandData().getName()), (AutoCompletable) child); } } // check subcommand groups @@ -345,7 +346,7 @@ private void searchForAutoCompletable(@Nonnull SlashCommand command, @Nonnull Cl // check subcommands for (SlashCommand.Subcommand child : childGroup.getSubcommands()) { if (Checks.checkImplementation(child.getClass(), AutoCompletable.class)) { - autoCompleteIndex.put(CommandUtils.buildCommandPath(baseName, groupName, child.getSubcommandData().getName()), (AutoCompletable) child); + autoCompleteIndex.put(CommandUtils.buildCommandPath(baseName, groupName, child.getCommandData().getName()), (AutoCompletable) child); } } } @@ -360,11 +361,11 @@ private void searchForAutoCompletable(@Nonnull SlashCommand command, @Nonnull Cl */ private @Nullable SlashCommandData getBaseCommandData(@Nonnull SlashCommand command, @Nonnull Class commandClass) { // find component (and modal) handlers - if (command.getSlashCommandData() == null) { + if (command.getCommandData() == null) { DIH4JDALogger.warn("Class %s is missing CommandData. It will be ignored.", commandClass.getName()); return null; } - SlashCommandData commandData = command.getSlashCommandData(); + SlashCommandData commandData = command.getCommandData(); if (command.getSubcommandGroups() != null && command.getSubcommandGroups().length != 0) { commandData.addSubcommandGroups(getSubcommandGroupData(command)); } @@ -374,7 +375,7 @@ private void searchForAutoCompletable(@Nonnull SlashCommand command, @Nonnull Cl if (command.getSubcommandGroups() != null && command.getSubcommandGroups().length == 0 && command.getSubcommands() != null && command.getSubcommands().length == 0) { slashCommandIndex.put(CommandUtils.buildCommandPath(commandData.getName()), command); - DIH4JDALogger.info(DIH4JDALogger.Type.SLASH_COMMAND_REGISTERED, "\t[*] Registered command: /%s (%s)", command.getSlashCommandData().getName(), command.getRegistrationType().name()); + DIH4JDALogger.info(DIH4JDALogger.Type.SLASH_COMMAND_REGISTERED, "\t[*] Registered command: /%s (%s)", command.getCommandData().getName(), command.getRegistrationType().name()); } return commandData; } @@ -417,19 +418,19 @@ private void searchForAutoCompletable(@Nonnull SlashCommand command, @Nonnull Cl Set subDataList = new HashSet<>(); for (SlashCommand.Subcommand subcommand : subcommands) { if (subcommand != null) { - if (subcommand.getSubcommandData() == null) { + if (subcommand.getCommandData() == null) { DIH4JDALogger.warn("Class %s is missing SubcommandData. It will be ignored.", subcommand.getClass().getSimpleName()); continue; } String commandPath; if (subGroupName == null) { - commandPath = CommandUtils.buildCommandPath(command.getSlashCommandData().getName(), subcommand.getSubcommandData().getName()); + commandPath = CommandUtils.buildCommandPath(command.getCommandData().getName(), subcommand.getCommandData().getName()); } else { - commandPath = CommandUtils.buildCommandPath(command.getSlashCommandData().getName(), subGroupName, subcommand.getSubcommandData().getName()); + commandPath = CommandUtils.buildCommandPath(command.getCommandData().getName(), subGroupName, subcommand.getCommandData().getName()); } subcommandIndex.put(commandPath, subcommand); DIH4JDALogger.info(DIH4JDALogger.Type.SLASH_COMMAND_REGISTERED, "\t[*] Registered command: /%s (%s)", commandPath, command.getRegistrationType().name()); - subDataList.add(subcommand.getSubcommandData()); + subDataList.add(subcommand.getCommandData()); } } return subDataList; @@ -439,9 +440,9 @@ private void searchForAutoCompletable(@Nonnull SlashCommand command, @Nonnull Cl * Gets all Guild Context commands registered in {@link InteractionHandler#findContextCommands(String)} and * returns their {@link CommandData} as a List. */ - private @Nonnull Set getContextCommandData() { - Set commands = new HashSet<>(); - for (ContextCommand context : contextCommands) { + private @Nonnull Set> getContextCommandData() { + Set> commands = new HashSet<>(); + for (ContextCommand context : contextCommands) { if (context != null) { CommandData data = getContextCommandData(context, context.getClass()); if (data != null) { @@ -465,22 +466,22 @@ private void searchForAutoCompletable(@Nonnull SlashCommand command, @Nonnull Cl * @param commandClass The base context command's class. * @return The new {@link CommandListUpdateAction}. */ - private @Nullable CommandData getContextCommandData(@Nonnull ContextCommand command, @Nonnull Class commandClass) { - if (command.getCommandData() == null) { + private @Nullable CommandData getContextCommandData(@Nonnull ContextCommand command, @Nonnull Class commandClass) { + CommandData data = command.getCommandData(); + if (data == null) { DIH4JDALogger.warn("Class %s is missing CommandData. It will be ignored.", commandClass.getName()); return null; } - CommandData commandData = command.getCommandData(); - if (commandData.getType() == Command.Type.MESSAGE) { - messageContextIndex.put(commandData.getName(), (ContextCommand.Message) command); - } else if (commandData.getType() == Command.Type.USER) { - userContextIndex.put(commandData.getName(), (ContextCommand.User) command); + if (data.getType() == Command.Type.MESSAGE) { + messageContextIndex.put(data.getName(), (ContextCommand.Message) command); + } else if (command.getCommandData().getType() == Command.Type.USER) { + userContextIndex.put(data.getName(), (ContextCommand.User) command); } else { - DIH4JDALogger.error("Invalid Command Type \"%s\" for Context Command! This command will be ignored.", commandData.getType()); + DIH4JDALogger.error("Invalid Command Type \"%s\" for Context Command! This command will be ignored.", data.getType()); return null; } - DIH4JDALogger.info(DIH4JDALogger.Type.CONTEXT_COMMAND_REGISTERED, "\t[*] Registered context command: %s (%s)", command.getCommandData().getName(), command.getRegistrationType().name()); - return commandData; + DIH4JDALogger.info(DIH4JDALogger.Type.CONTEXT_COMMAND_REGISTERED, "\t[*] Registered context command: %s (%s)", data.getName(), command.getRegistrationType().name()); + return data; } /** @@ -490,17 +491,15 @@ private void searchForAutoCompletable(@Nonnull SlashCommand command, @Nonnull Cl * @param event The {@link SlashCommandInteractionEvent} that was fired. */ private void handleSlashCommand(@Nonnull SlashCommandInteractionEvent event) throws CommandNotRegisteredException { - String path = event.getFullCommandName(); - SlashCommand command = slashCommandIndex.get(path); - SlashCommand.Subcommand subcommand = subcommandIndex.get(path); - if (command == null && subcommand == null) { + ApplicationCommand command = slashCommandIndex.containsKey(event.getFullCommandName()) ? + slashCommandIndex.get(event.getFullCommandName()) : subcommandIndex.get(event.getFullCommandName()); + if (command == null) { if (config.isThrowUnregisteredException()) { - throw new CommandNotRegisteredException(String.format("Slash Command \"%s\" is not registered.", path)); + throw new CommandNotRegisteredException(String.format("Slash Command \"%s\" is not registered.", event.getFullCommandName())); } } else { - AbstractCommand req = command != null ? command : subcommand.getParent(); - if (passesRequirements(event, req.getRequiredPermissions(), req.getRequiredUsers(), req.getRequiredRoles())) { - (command != null ? command : subcommand).execute(event); + if (passesRequirements(event, command.getRequiredPermissions(), command.getRequiredUsers(), command.getRequiredRoles())) { + command.execute(event); } } } @@ -545,7 +544,7 @@ private void handleMessageContextCommand(@Nonnull MessageContextInteractionEvent /** * Checks if the given {@link CommandInteraction} passes the - * {@link xyz.dynxsty.dih4jda.interactions.commands.AbstractCommand} requirements. + * {@link RestrictedCommand} requirements. * If not, this will then fire the corresponding event using {@link GenericDIH4JDAEvent#fire(GenericDIH4JDAEvent)} * * @param interaction The {@link CommandInteraction}. diff --git a/src/main/java/xyz/dynxsty/dih4jda/SmartQueue.java b/src/main/java/xyz/dynxsty/dih4jda/SmartQueue.java index 1b9e6147..f2191032 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/SmartQueue.java +++ b/src/main/java/xyz/dynxsty/dih4jda/SmartQueue.java @@ -5,8 +5,8 @@ import net.dv8tion.jda.api.interactions.commands.Command; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; -import xyz.dynxsty.dih4jda.interactions.commands.ContextCommand; -import xyz.dynxsty.dih4jda.interactions.commands.SlashCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.ContextCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import xyz.dynxsty.dih4jda.util.CommandUtils; import xyz.dynxsty.dih4jda.util.Pair; @@ -35,10 +35,10 @@ */ public class SmartQueue { private final Set slashCommands; - private final Set contextCommands; + private final Set> contextCommands; private final boolean deleteUnknown; - protected SmartQueue(@Nonnull Set slashCommands, @Nonnull Set contextCommands, boolean deleteUnknown) { + protected SmartQueue(@Nonnull Set slashCommands, @Nonnull Set> contextCommands, boolean deleteUnknown) { this.slashCommands = slashCommands; this.contextCommands = contextCommands; this.deleteUnknown = deleteUnknown; @@ -51,7 +51,7 @@ protected SmartQueue(@Nonnull Set slashCommands, @Nonnull Set, Set> checkGlobal(@Nonnull JDA jda, @Nonnull List existing) { + protected @Nonnull Pair, Set>> checkGlobal(@Nonnull JDA jda, @Nonnull List existing) { if (!existing.isEmpty()) { return removeDuplicates(jda, existing, null); } @@ -65,7 +65,7 @@ protected SmartQueue(@Nonnull Set slashCommands, @Nonnull Set, Set> checkGuild(@Nonnull Guild guild, @Nonnull List existing) { + protected @Nonnull Pair, Set>> checkGuild(@Nonnull Guild guild, @Nonnull List existing) { if (!existing.isEmpty()) { return removeDuplicates(guild.getJDA(), existing, guild); } @@ -81,7 +81,7 @@ protected SmartQueue(@Nonnull Set slashCommands, @Nonnull Set, Set> removeDuplicates(@Nonnull JDA jda, @Nonnull final List existing, @Nullable Guild guild) { + private @Nonnull Pair, Set>> removeDuplicates(@Nonnull JDA jda, @Nonnull final List existing, @Nullable Guild guild) { List commands = new ArrayList<>(existing); boolean global = guild == null; String prefix = String.format("[%s] ", global ? "Global" : guild.getName()); @@ -89,12 +89,12 @@ protected SmartQueue(@Nonnull Set slashCommands, @Nonnull Set { if (contextCommands.stream().anyMatch(data -> CommandUtils.equals(cmd, data.getCommandData(), global)) || - slashCommands.stream().anyMatch(data -> CommandUtils.equals(cmd, data.getSlashCommandData(), global))) { + slashCommands.stream().anyMatch(data -> CommandUtils.equals(cmd, data.getCommandData(), global))) { // check for command in blacklisted guilds // this may be refactored soonTM, as its kinda clunky if (!global) { for (SlashCommand d : slashCommands) { - if (CommandUtils.equals(cmd, d.getSlashCommandData(), false)) { + if (CommandUtils.equals(cmd, d.getCommandData(), false)) { if (d.getRequiredGuilds().getFirst() == null) { return true; } else { @@ -121,7 +121,7 @@ protected SmartQueue(@Nonnull Set slashCommands, @Nonnull Set existing.stream().anyMatch(p -> CommandUtils.equals(p, data.getCommandData(), global))); - slashCommands.removeIf(data -> existing.stream().anyMatch(p -> CommandUtils.equals(p, data.getSlashCommandData(), global))); + slashCommands.removeIf(data -> existing.stream().anyMatch(p -> CommandUtils.equals(p, data.getCommandData(), global))); // remove unknown commands, if enabled if (!commands.isEmpty()) { for (Command command : commands) { diff --git a/src/main/java/xyz/dynxsty/dih4jda/events/AutoCompleteExceptionEvent.java b/src/main/java/xyz/dynxsty/dih4jda/events/AutoCompleteExceptionEvent.java index 7eb6809c..1219ae41 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/events/AutoCompleteExceptionEvent.java +++ b/src/main/java/xyz/dynxsty/dih4jda/events/AutoCompleteExceptionEvent.java @@ -4,7 +4,7 @@ import net.dv8tion.jda.api.interactions.AutoCompleteQuery; import net.dv8tion.jda.api.interactions.commands.CommandAutoCompleteInteraction; import xyz.dynxsty.dih4jda.DIH4JDA; -import xyz.dynxsty.dih4jda.interactions.commands.AutoCompletable; +import xyz.dynxsty.dih4jda.interactions.AutoCompletable; /** * An event that gets fired when an exception gets raised while handling an autocomplete interaction. diff --git a/src/main/java/xyz/dynxsty/dih4jda/events/CommandExceptionEvent.java b/src/main/java/xyz/dynxsty/dih4jda/events/CommandExceptionEvent.java index d14da680..51fd6fe5 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/events/CommandExceptionEvent.java +++ b/src/main/java/xyz/dynxsty/dih4jda/events/CommandExceptionEvent.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import xyz.dynxsty.dih4jda.DIH4JDA; -import xyz.dynxsty.dih4jda.interactions.commands.ContextCommand; -import xyz.dynxsty.dih4jda.interactions.commands.SlashCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.ContextCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; /** * An event that gets fired when an exception gets raised while executing any command. diff --git a/src/main/java/xyz/dynxsty/dih4jda/events/DIH4JDAEventListener.java b/src/main/java/xyz/dynxsty/dih4jda/events/DIH4JDAEventListener.java index 3bdafb18..87b15f41 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/events/DIH4JDAEventListener.java +++ b/src/main/java/xyz/dynxsty/dih4jda/events/DIH4JDAEventListener.java @@ -4,10 +4,10 @@ import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.AutoCompleteQuery; -import xyz.dynxsty.dih4jda.interactions.commands.AbstractCommand; -import xyz.dynxsty.dih4jda.interactions.commands.AutoCompletable; -import xyz.dynxsty.dih4jda.interactions.commands.ContextCommand; -import xyz.dynxsty.dih4jda.interactions.commands.SlashCommand; +import xyz.dynxsty.dih4jda.interactions.AutoCompletable; +import xyz.dynxsty.dih4jda.interactions.commands.application.ContextCommand; +import xyz.dynxsty.dih4jda.interactions.commands.RestrictedCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; /** * An interface containing all events and their method that DIH4JDA can fire. @@ -51,7 +51,7 @@ default void onModalException(ModalExceptionEvent event) {} * An event that gets fired when the user, which invoked the command, does NOT have one of the required permissions. * * @param event The {@link InsufficientPermissionsEvent} that was fired. - * @see AbstractCommand#setRequiredPermissions(Permission...) + * @see RestrictedCommand#setRequiredPermissions(Permission...) */ default void onInsufficientPermissions(InsufficientPermissionsEvent event) {} @@ -59,7 +59,7 @@ default void onInsufficientPermissions(InsufficientPermissionsEvent event) {} * An event that gets fired when the user, which invoked the command, is NOT allowed to use this command. * * @param event The {@link InvalidUserEvent} that was fired. - * @see AbstractCommand#setRequiredUsers(Long...) + * @see RestrictedCommand#setRequiredUsers(Long...) */ default void onInvalidUser(InvalidUserEvent event) {} @@ -67,7 +67,7 @@ default void onInvalidUser(InvalidUserEvent event) {} * An event that gets fired when the user, which invoked the command, does NOT have the required roles to use this command. * * @param event The {@link InvalidRoleEvent} that was fired. - * @see AbstractCommand#setRequiredRoles(Long...) + * @see RestrictedCommand#setRequiredRoles(Long...) */ default void onInvalidRole(InvalidRoleEvent event) {} } diff --git a/src/main/java/xyz/dynxsty/dih4jda/events/InsufficientPermissionsEvent.java b/src/main/java/xyz/dynxsty/dih4jda/events/InsufficientPermissionsEvent.java index a422ee6e..2357e692 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/events/InsufficientPermissionsEvent.java +++ b/src/main/java/xyz/dynxsty/dih4jda/events/InsufficientPermissionsEvent.java @@ -3,14 +3,14 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import xyz.dynxsty.dih4jda.DIH4JDA; -import xyz.dynxsty.dih4jda.interactions.commands.AbstractCommand; +import xyz.dynxsty.dih4jda.interactions.commands.RestrictedCommand; import java.util.Set; /** * An event that gets fired when the user, which invoked the command, does NOT have one of the required permissions. * - * @see AbstractCommand#setRequiredPermissions(Permission...) + * @see RestrictedCommand#setRequiredPermissions(Permission...) */ public class InsufficientPermissionsEvent extends GenericDIH4JDAEvent { @@ -23,7 +23,7 @@ public InsufficientPermissionsEvent(DIH4JDA dih4jda, CommandInteraction interact /** * @return An immutable {@link Set} of all "required" permissions for the executed command. - * @see AbstractCommand#setRequiredPermissions(Permission...) + * @see RestrictedCommand#setRequiredPermissions(Permission...) */ public Set getPermissions() { return permissions; diff --git a/src/main/java/xyz/dynxsty/dih4jda/events/InvalidRoleEvent.java b/src/main/java/xyz/dynxsty/dih4jda/events/InvalidRoleEvent.java index 23eaae5c..c07a8428 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/events/InvalidRoleEvent.java +++ b/src/main/java/xyz/dynxsty/dih4jda/events/InvalidRoleEvent.java @@ -2,14 +2,14 @@ import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import xyz.dynxsty.dih4jda.DIH4JDA; -import xyz.dynxsty.dih4jda.interactions.commands.AbstractCommand; +import xyz.dynxsty.dih4jda.interactions.commands.RestrictedCommand; import java.util.Set; /** * An event that gets fired when the user, which invoked the command, does NOT have the required roles to use this command. * - * @see AbstractCommand#setRequiredRoles(Long...) + * @see RestrictedCommand#setRequiredRoles(Long...) */ public class InvalidRoleEvent extends GenericDIH4JDAEvent { @@ -22,7 +22,7 @@ public InvalidRoleEvent(DIH4JDA dih4jda, CommandInteraction interaction, Set getRoleIds() { return roleIds; diff --git a/src/main/java/xyz/dynxsty/dih4jda/events/InvalidUserEvent.java b/src/main/java/xyz/dynxsty/dih4jda/events/InvalidUserEvent.java index 9fff9360..295873b4 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/events/InvalidUserEvent.java +++ b/src/main/java/xyz/dynxsty/dih4jda/events/InvalidUserEvent.java @@ -2,14 +2,14 @@ import net.dv8tion.jda.api.interactions.commands.CommandInteraction; import xyz.dynxsty.dih4jda.DIH4JDA; -import xyz.dynxsty.dih4jda.interactions.commands.AbstractCommand; +import xyz.dynxsty.dih4jda.interactions.commands.RestrictedCommand; import java.util.Set; /** * An event that gets fired when the user, which invoked the command, is NOT allowed to use this command. * - * @see AbstractCommand#setRequiredUsers(Long...) + * @see RestrictedCommand#setRequiredUsers(Long...) */ public class InvalidUserEvent extends GenericDIH4JDAEvent { @@ -22,7 +22,7 @@ public InvalidUserEvent(DIH4JDA dih4jda, CommandInteraction interaction, Set getUserIds() { return userIds; diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/AutoCompletable.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/AutoCompletable.java similarity index 89% rename from src/main/java/xyz/dynxsty/dih4jda/interactions/commands/AutoCompletable.java rename to src/main/java/xyz/dynxsty/dih4jda/interactions/AutoCompletable.java index 2f798093..72a877c4 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/AutoCompletable.java +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/AutoCompletable.java @@ -1,4 +1,4 @@ -package xyz.dynxsty.dih4jda.interactions.commands; +package xyz.dynxsty.dih4jda.interactions; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.interactions.AutoCompleteQuery; @@ -13,7 +13,7 @@ * public class PingCommand extends SlashCommand implements AutoCompletable { * * public PingCommand() { - * setSlashCommandData(Commands.slash("ping", "Ping someone").addOption(OptionType.STRING, "user-id", "The user's id", true, true)); + * setCommandData(Commands.slash("ping", "Ping someone").addOption(OptionType.STRING, "user-id", "The user's id", true, true)); * } * * @Override diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/ContextCommand.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/ContextCommand.java deleted file mode 100644 index 7fd41471..00000000 --- a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/ContextCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -package xyz.dynxsty.dih4jda.interactions.commands; - -import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; -import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; -import net.dv8tion.jda.api.interactions.commands.build.CommandData; -import xyz.dynxsty.dih4jda.DIH4JDALogger; - -import javax.annotation.Nonnull; - -/** - * Model class which represents a single Context Command. - * - * @see ContextCommand.User#execute - * @see ContextCommand.Message#execute - * @since v1.5 - */ -public class ContextCommand extends AbstractCommand { - private CommandData commandData = null; - - private ContextCommand() {} - - public CommandData getCommandData() { - return commandData; - } - - /** - * Sets this commands' {@link CommandData}. - * - * @param commandData The corresponding {@link CommandData} which should be used for this context command. - * @see net.dv8tion.jda.api.interactions.commands.build.Commands#user(String) - * @see net.dv8tion.jda.api.interactions.commands.build.Commands#message(String) - */ - public void setCommandData(@Nonnull CommandData commandData) { - if (commandData.getType() == net.dv8tion.jda.api.interactions.commands.Command.Type.MESSAGE || - commandData.getType() == net.dv8tion.jda.api.interactions.commands.Command.Type.USER) { - this.commandData = commandData; - } else { - DIH4JDALogger.error(String.format("Invalid Command Type \"%s\" for Context Command! This command will be ignored.", commandData.getType())); - } - } - - public abstract static class User extends ContextCommand implements ExecutableCommand {} - - public abstract static class Message extends ContextCommand implements ExecutableCommand {} -} diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/AbstractCommand.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/RestrictedCommand.java similarity index 83% rename from src/main/java/xyz/dynxsty/dih4jda/interactions/commands/AbstractCommand.java rename to src/main/java/xyz/dynxsty/dih4jda/interactions/commands/RestrictedCommand.java index 611bb4b4..dc8205b0 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/AbstractCommand.java +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/RestrictedCommand.java @@ -2,8 +2,9 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; -import xyz.dynxsty.dih4jda.DIH4JDA; import xyz.dynxsty.dih4jda.DIH4JDABuilder; +import xyz.dynxsty.dih4jda.interactions.commands.application.RegistrationType; +import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import xyz.dynxsty.dih4jda.util.Pair; import javax.annotation.Nonnull; @@ -13,8 +14,7 @@ * * @since v1.6 */ -public abstract class AbstractCommand { - private RegistrationType type = DIH4JDA.defaultCommandType; +public abstract class RestrictedCommand { //The command requirements private Pair requiredGuilds = new Pair<>(null, null); @@ -22,24 +22,6 @@ public abstract class AbstractCommand { private Long[] requiredUsers = new Long[]{}; private Long[] requiredRoles = new Long[]{}; - /** - * The {@link RegistrationType} the command got assigned. - * - * @return the {@link RegistrationType}. - */ - public final RegistrationType getRegistrationType() { - return type; - } - - /** - * How the command should be queued. This DOES NOT work with {@link SlashCommand.Subcommand}! - * - * @param type the {@link RegistrationType} to set. - */ - public final void setRegistrationType(RegistrationType type) { - this.type = type; - } - /** * Allows a set of {@link Guild}s to update their Slash Commands. * @@ -50,9 +32,6 @@ public final void setRegistrationType(RegistrationType type) { * @param guilds An array of {@link Long}s. */ public final void setRequiredGuilds(boolean restrictQueue, Long... guilds) { - if (restrictQueue && type != RegistrationType.GUILD) { - throw new UnsupportedOperationException("Cannot restrict queue for Global Commands!"); - } requiredGuilds = new Pair<>(restrictQueue, guilds); } diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/ApplicationCommand.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/ApplicationCommand.java new file mode 100644 index 00000000..1012450b --- /dev/null +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/ApplicationCommand.java @@ -0,0 +1,29 @@ +package xyz.dynxsty.dih4jda.interactions.commands.application; + +import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; +import xyz.dynxsty.dih4jda.interactions.commands.ExecutableCommand; +import xyz.dynxsty.dih4jda.interactions.commands.RestrictedCommand; + +/** + * Model class for all Application Commands. + * For top-level commands, see {@link BaseApplicationCommand} which features an additional {@link RegistrationType}. + * + * @param The event this class uses. + * @param The type of {@link net.dv8tion.jda.api.interactions.commands.build.CommandData} this class uses. + */ +public abstract class ApplicationCommand extends RestrictedCommand implements ExecutableCommand { + private T data; + + /** + * Sets this commands' {@link E CommandData}. + * + * @param data The {@link E CommandData} which should be used for this application command. + */ + public final void setCommandData(T data) { + this.data = data; + } + + public final T getCommandData() { + return data; + } +} diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/BaseApplicationCommand.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/BaseApplicationCommand.java new file mode 100644 index 00000000..29a08552 --- /dev/null +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/BaseApplicationCommand.java @@ -0,0 +1,34 @@ +package xyz.dynxsty.dih4jda.interactions.commands.application; + +import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; +import xyz.dynxsty.dih4jda.DIH4JDA; + +/** + * An extension of {@link ApplicationCommand} which contains a {@link RegistrationType}. + * This abstract class is meant for top-level commands, which can be queued either per-guild or globally. + * + * @param The event this class uses. + * @param The type of {@link net.dv8tion.jda.api.interactions.commands.build.CommandData} this class uses. + */ +public abstract class BaseApplicationCommand extends ApplicationCommand { + + private RegistrationType registrationType = DIH4JDA.getDefaultRegistrationType(); + + /** + * The {@link RegistrationType} the command got assigned. + * + * @return the {@link RegistrationType}. + */ + public final RegistrationType getRegistrationType() { + return registrationType; + } + + /** + * How the command should be queued. This DOES NOT work with {@link SlashCommand.Subcommand}! + * + * @param type the {@link RegistrationType} to set. + */ + public final void setRegistrationType(RegistrationType type) { + this.registrationType = type; + } +} diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/ContextCommand.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/ContextCommand.java new file mode 100644 index 00000000..19708e4b --- /dev/null +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/ContextCommand.java @@ -0,0 +1,23 @@ +package xyz.dynxsty.dih4jda.interactions.commands.application; + +import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; +import net.dv8tion.jda.api.events.interaction.command.GenericContextInteractionEvent; +import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent; +import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent; +import net.dv8tion.jda.api.interactions.commands.build.CommandData; + +/** + * Model class which represents a single Context Command. + * + * @see ContextCommand.User#execute + * @see ContextCommand.Message#execute + * @since v1.5 + */ +public abstract class ContextCommand extends BaseApplicationCommand { + + private ContextCommand() {} + + public abstract static class User extends ContextCommand {} + + public abstract static class Message extends ContextCommand {} +} diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/RegistrationType.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/RegistrationType.java similarity index 78% rename from src/main/java/xyz/dynxsty/dih4jda/interactions/commands/RegistrationType.java rename to src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/RegistrationType.java index 8a302399..1a62c0fa 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/RegistrationType.java +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/RegistrationType.java @@ -1,4 +1,4 @@ -package xyz.dynxsty.dih4jda.interactions.commands; +package xyz.dynxsty.dih4jda.interactions.commands.application; /** * Whether the command should be queued as a global- or as a guild command. diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/SlashCommand.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/SlashCommand.java similarity index 78% rename from src/main/java/xyz/dynxsty/dih4jda/interactions/commands/SlashCommand.java rename to src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/SlashCommand.java index c1dd9a33..8c72d08b 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/SlashCommand.java +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/commands/application/SlashCommand.java @@ -1,4 +1,4 @@ -package xyz.dynxsty.dih4jda.interactions.commands; +package xyz.dynxsty.dih4jda.interactions.commands.application; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.Command; @@ -17,28 +17,13 @@ * * @since v1.5 */ -public abstract class SlashCommand extends AbstractCommand implements ExecutableCommand { - - private SlashCommandData data = null; +public abstract class SlashCommand extends BaseApplicationCommand { private Subcommand[] subcommands = new Subcommand[]{}; private SubcommandGroup[] subcommandGroups = new SubcommandGroup[]{}; protected SlashCommand() { } - public final SlashCommandData getSlashCommandData() { - return data; - } - - /** - * Sets this commands' {@link SlashCommandData}. - * - * @param commandData The {@link SlashCommandData} which should be used for this command. - */ - public final void setSlashCommandData(SlashCommandData commandData) { - this.data = commandData; - } - public final Subcommand[] getSubcommands() { return subcommands; } @@ -83,31 +68,16 @@ public void execute(SlashCommandInteractionEvent event) {} * @return The {@link Command} corresponding to this class. */ public @Nullable Command asCommand() { - if (data == null) return null; - return InteractionHandler.getRetrievedCommands().get(data.getName()); + if (getCommandData() == null) return null; + return InteractionHandler.getRetrievedCommands().get(getCommandData().getName()); } /** * Model class which represents a single Subcommand. */ - public abstract static class Subcommand implements ExecutableCommand { - private SubcommandData data = null; + public abstract static class Subcommand extends ApplicationCommand { private SlashCommand parent = null; - public final SubcommandData getSubcommandData() { - return data; - } - - /** - * Sets this subcommands' {@link SubcommandData}. - * - * @param data The {@link SubcommandData} which should be used for this subcommand. - * @see SubcommandData - */ - public final void setSubcommandData(SubcommandData data) { - this.data = data; - } - /** * Gets the {@link SlashCommand parent} for this subcommand. * @@ -124,13 +94,13 @@ public SlashCommand getParent() { * @return The {@link Command.Subcommand} corresponding to this class. */ public @Nullable Command.Subcommand asSubcommand() { - if (data == null) return null; + if (getCommandData() == null) return null; Command cmd = parent.asCommand(); if (cmd == null) return null; List subcommands = new ArrayList<>(cmd.getSubcommands()); cmd.getSubcommandGroups().forEach(g -> subcommands.addAll(g.getSubcommands())); return subcommands.stream() - .filter(c -> c.getName().equals(data.getName())) + .filter(c -> c.getName().equals(getCommandData().getName())) .findFirst() .orElse(null); } diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/components/EntitySelectMenuHandler.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/components/EntitySelectMenuHandler.java index 31d82c6a..000aeb54 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/interactions/components/EntitySelectMenuHandler.java +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/components/EntitySelectMenuHandler.java @@ -25,7 +25,7 @@ public interface EntitySelectMenuHandler { * public class TestCommand extends SlashCommand implements EntitySelectMenuHandler { * * public TestCommand() { - * setSlashCommandData(Commands.slash("test", "test description")); + * setCommandData(Commands.slash("test", "test description")); * } * * @Override diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/components/ModalHandler.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/components/ModalHandler.java index 77e6cf9b..7f41e803 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/interactions/components/ModalHandler.java +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/components/ModalHandler.java @@ -19,7 +19,7 @@ public interface ModalHandler { * public class TestCommand extends SlashCommand implements ModalHandler { * * public TestCommand() { - * setSlashCommandData(Commands.slash("test", "test description")); + * setCommandData(Commands.slash("test", "test description")); * } * * @Override diff --git a/src/main/java/xyz/dynxsty/dih4jda/interactions/components/StringSelectMenuHandler.java b/src/main/java/xyz/dynxsty/dih4jda/interactions/components/StringSelectMenuHandler.java index c1533da5..24bbed2e 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/interactions/components/StringSelectMenuHandler.java +++ b/src/main/java/xyz/dynxsty/dih4jda/interactions/components/StringSelectMenuHandler.java @@ -26,7 +26,7 @@ public interface StringSelectMenuHandler { * public class TestCommand extends SlashCommand implements StringSelectMenuHandler { * * public TestCommand() { - * setSlashCommandData(Commands.slash("test", "test description")); + * setCommandData(Commands.slash("test", "test description")); * } * * @Override diff --git a/src/main/java/xyz/dynxsty/dih4jda/util/CommandUtils.java b/src/main/java/xyz/dynxsty/dih4jda/util/CommandUtils.java index 9142a337..901411a6 100644 --- a/src/main/java/xyz/dynxsty/dih4jda/util/CommandUtils.java +++ b/src/main/java/xyz/dynxsty/dih4jda/util/CommandUtils.java @@ -7,9 +7,9 @@ import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; -import xyz.dynxsty.dih4jda.interactions.commands.ContextCommand; -import xyz.dynxsty.dih4jda.interactions.commands.RegistrationType; -import xyz.dynxsty.dih4jda.interactions.commands.SlashCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.ContextCommand; +import xyz.dynxsty.dih4jda.interactions.commands.application.RegistrationType; +import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -159,10 +159,10 @@ public static boolean equals(@Nonnull Command command, Object data, boolean isGl * @return The formatted String. * @since v1.5 */ - public static @Nonnull String getNames(@Nonnull Set command, @Nonnull Set slash) { + public static @Nonnull String getNames(@Nonnull Set> command, @Nonnull Set slash) { StringBuilder names = new StringBuilder(); command.forEach(c -> names.append(", ").append(c.getCommandData().getName())); - slash.forEach(c -> names.append(", /").append(c.getSlashCommandData().getName())); + slash.forEach(c -> names.append(", /").append(c.getCommandData().getName())); return names.substring(2); } @@ -174,8 +174,8 @@ public static boolean equals(@Nonnull Command command, Object data, boolean isGl * @return The modified {@link Pair}. * @since v1.5.2 */ - public static @Nonnull Pair, Set> filterByType(@Nonnull Pair, - Set> pair, RegistrationType type) { + public static @Nonnull Pair, Set>> filterByType(@Nonnull Pair, + Set>> pair, RegistrationType type) { return new Pair<>( pair.getFirst().stream().filter(c -> c.getRegistrationType() == type).collect(Collectors.toSet()), pair.getSecond().stream().filter(c -> c.getRegistrationType() == type).collect(Collectors.toSet())); diff --git a/src/test/java/com/dynxsty/tests/ComponentIdTest.java b/src/test/java/com/dynxsty/tests/ComponentIdTest.java index d44088f4..ddb8f8ce 100644 --- a/src/test/java/com/dynxsty/tests/ComponentIdTest.java +++ b/src/test/java/com/dynxsty/tests/ComponentIdTest.java @@ -1,7 +1,7 @@ package com.dynxsty.tests; -import xyz.dynxsty.dih4jda.util.ComponentIdBuilder; import org.junit.jupiter.api.Test; +import xyz.dynxsty.dih4jda.util.ComponentIdBuilder; public class ComponentIdTest { @Test