2022-03-28 15:23:10 +00:00
|
|
|
package moe.oko.Kiafumi.util;
|
|
|
|
|
|
|
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2022-03-29 15:35:38 +00:00
|
|
|
import static moe.oko.Kiafumi.Kiafumi.error;
|
|
|
|
|
2022-03-28 20:43:04 +00:00
|
|
|
/**
|
|
|
|
* Helpful CommandInfo class to easily make slash commands.
|
|
|
|
*/
|
2022-03-28 15:23:10 +00:00
|
|
|
public class CommandInfo {
|
|
|
|
private String name;
|
|
|
|
private String description;
|
2022-03-29 15:35:38 +00:00
|
|
|
private CommandType type;
|
2022-03-28 15:23:10 +00:00
|
|
|
private HashMap<String, OptionType> options;
|
|
|
|
private HashMap<String, String> optionDescriptions;
|
|
|
|
private HashMap<String, Boolean> optionRequirements;
|
2022-03-29 15:35:38 +00:00
|
|
|
private HashMap<String, CommandInfo> subCommands;
|
2022-03-28 15:23:10 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2022-03-29 15:35:38 +00:00
|
|
|
public CommandInfo(String name, String description, CommandType type) {
|
2022-03-28 15:23:10 +00:00
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
2022-03-29 15:35:38 +00:00
|
|
|
this.type = type;
|
2022-03-28 15:23:10 +00:00
|
|
|
this.options = new HashMap<>();
|
|
|
|
this.optionDescriptions = new HashMap<>();
|
|
|
|
this.optionRequirements = new HashMap<>();
|
2022-03-29 16:08:51 +00:00
|
|
|
this.subCommands = new HashMap<>();
|
2022-03-28 15:23:10 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 20:43:04 +00:00
|
|
|
/**
|
|
|
|
* Returns whether the command has options/input.
|
|
|
|
* @return - boolean
|
|
|
|
*/
|
2022-03-28 15:23:10 +00:00
|
|
|
public boolean hasOptions() {
|
2022-03-30 20:58:01 +00:00
|
|
|
return options.size() != 0;
|
2022-03-28 15:23:10 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 20:58:01 +00:00
|
|
|
public boolean hasSubCommands() { return subCommands.size() != 0; }
|
2022-03-29 16:08:51 +00:00
|
|
|
|
2022-03-28 15:23:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-03-29 15:35:38 +00:00
|
|
|
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.
|
|
|
|
*/
|
2022-03-28 15:23:10 +00:00
|
|
|
public void addOption(String name, String description, OptionType type, boolean required) {
|
|
|
|
options.put(name, type);
|
|
|
|
optionDescriptions.put(name, description);
|
|
|
|
optionRequirements.put(name, required);
|
|
|
|
}
|
2022-03-29 15:35:38 +00:00
|
|
|
|
2022-03-29 19:59:26 +00:00
|
|
|
/**
|
|
|
|
* The way you add subcommands to a command. NOTE you cannot have options for the command if you use this.
|
|
|
|
* @param cmdInfo - The CommandInfo for the subcommand (including options).
|
|
|
|
*/
|
2022-03-29 15:35:38 +00:00
|
|
|
public void addSubcommand(CommandInfo cmdInfo) {
|
|
|
|
subCommands.put(cmdInfo.name, cmdInfo);
|
|
|
|
}
|
2022-03-28 15:23:10 +00:00
|
|
|
}
|