package cc.fascinated.bat.command; import lombok.Getter; import lombok.NonNull; import lombok.Setter; 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.internal.interactions.CommandDataImpl; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author Fascinated (fascinated7) */ @Getter @Setter public abstract class BatCommand implements BatCommandExecutor { /** * The information about the command */ private final CommandInfo commandInfo; /** * The command data for the slash command */ private final CommandDataImpl commandData; /** * The sub commands of the command */ private final Map subCommands = new HashMap<>(); /** * The category of the command */ private Category category; /** * The command snowflake from Discord */ private long commandSnowflake; public BatCommand() { this.commandInfo = getClass().getAnnotation(CommandInfo.class); this.category = this.commandInfo.category(); this.commandData = new CommandDataImpl(this.commandInfo.name(), this.commandInfo.description()) .setGuildOnly(this.commandInfo.guildOnly()); } /** * Adds a sub command to the command * * @param subCommand The sub command */ public void addSubCommand(@NonNull BatSubCommand subCommand) { this.subCommands.put(subCommand.getCommandInfo().name().toLowerCase(), subCommand); this.commandData.addSubcommands(subCommand.getCommandData()); } /** * 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 */ protected void addOption(OptionType optionType, String name, String description, boolean required) { this.commandData.addOption(optionType, name, description, required); } /** * 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(); } }