kiafumi/src/main/java/moe/oko/Kiafumi/util/CommandInfo.java

86 lines
2.8 KiB
Java
Raw Normal View History

package moe.oko.Kiafumi.util;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.util.HashMap;
import static moe.oko.Kiafumi.Kiafumi.error;
2022-03-28 20:43:04 +00:00
/**
* Helpful CommandInfo class to easily make slash commands.
*/
public class CommandInfo {
private String name;
private String description;
private CommandType type;
private HashMap<String, OptionType> options;
private HashMap<String, String> optionDescriptions;
private HashMap<String, Boolean> optionRequirements;
private HashMap<String, CommandInfo> subCommands;
2022-03-28 20:43:04 +00:00
/**
* Constructor to build CommandInfo with.
* @param name - Name of the slash command (MUST BE ALL LOWERCASE)
* @param description - Description of the slash command
*/
public CommandInfo(String name, String description, CommandType type) {
this.name = name;
this.description = description;
this.type = type;
this.options = new HashMap<>();
this.optionDescriptions = new HashMap<>();
this.optionRequirements = new HashMap<>();
}
2022-03-28 20:43:04 +00:00
/**
* Returns whether the command has options/input.
* @return - boolean
*/
public boolean hasOptions() {
return options != null;
}
public String getDescription() {
return description;
}
public String getName() {
return name;
}
public HashMap<String, OptionType> getOptions() {
return options;
}
public HashMap<String, Boolean> getOptionRequirements() {
return optionRequirements;
}
public HashMap<String, String> getOptionDescriptions() {
return optionDescriptions;
}
public HashMap<String, CommandInfo> getSubCommands() { return subCommands; }
2022-03-28 20:43:04 +00:00
/**
* The way you add options to a command. Use this function for EACH argument.
* @param name - name of the field
* @param description - description for the field
* @param type - the OptionType of the field (e.x. OptionType.STRING, OptionType.CHANNEL, etc.)
* @param required - whether the command can be run without the field or not.
*/
public void addOption(String name, String description, OptionType type, boolean required) {
if(this.type.equals(CommandType.SUBCOMMAND) && (type.equals(OptionType.SUB_COMMAND) || type.equals(OptionType.SUB_COMMAND_GROUP))) {
error("Command " + this.name + " attempted to assign a SUB_COMMAND option despite it being a subcommand itself. Check code for this command.");
return; //You cannot add a subcommand option to a subcommand.
}
options.put(name, type);
optionDescriptions.put(name, description);
optionRequirements.put(name, required);
}
public void addSubcommand(CommandInfo cmdInfo) {
subCommands.put(cmdInfo.name, cmdInfo);
}
}