Setting Subcommand Addition, Subcommands finally fixed
This commit is contained in:
parent
3061c08774
commit
894d02424c
2
pom.xml
2
pom.xml
|
@ -12,7 +12,7 @@
|
|||
<url>https://oko.moe/kiafumi.htm</url>
|
||||
|
||||
<properties>
|
||||
<project.jdk.version>17</project.jdk.version>
|
||||
<project.jdk.version>16</project.jdk.version>
|
||||
<mainclass>moe.oko.Kiafumi.Kiafumi</mainclass>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ import net.dv8tion.jda.api.JDABuilder;
|
|||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.requests.restaction.CommandCreateAction;
|
||||
|
@ -204,26 +206,26 @@ public class Kiafumi {
|
|||
int i = 0;
|
||||
for(CommandClass cmd : activeCommands) {
|
||||
for(CommandInfo ci : cmd.getSlashCommandInfo()) {
|
||||
CommandCreateAction cca = guild.upsertCommand(ci.getName(), ci.getDescription());
|
||||
i++;
|
||||
if(ci.hasSubCommands()) {
|
||||
for (String name : ci.getSubCommands().keySet()) {
|
||||
CommandInfo si = ci.getSubCommands().get(name);
|
||||
SubcommandData sd = new SubcommandData(si.getName(), si.getDescription());
|
||||
for (String option : si.getOptions().keySet()) {
|
||||
sd.addOption(si.getOptions().get(option), option, si.getOptionDescriptions().get(option), si.getOptionRequirements().get(option));
|
||||
}
|
||||
cca.addSubcommands(sd);
|
||||
}
|
||||
}
|
||||
if(ci.hasOptions()) {
|
||||
CommandCreateAction cca = guild.upsertCommand(ci.getName(), ci.getDescription());
|
||||
for(String name : ci.getOptions().keySet()) {
|
||||
//Any intelligent IDE will rage about the option not being used, it's added to the action then executed later, DO not edit this (please).
|
||||
cca.addOption(ci.getOptions().get(name), name, ci.getOptionDescriptions().get(name), ci.getOptionRequirements().get(name));
|
||||
}
|
||||
for(String name : ci.getSubCommands().keySet()) {
|
||||
CommandInfo si = ci.getSubCommands().get(name);
|
||||
SubcommandData sd = new SubcommandData(si.getName(), si.getDescription());
|
||||
for(String option : si.getOptions().keySet()) {
|
||||
sd.addOption(si.getOptions().get(option), option, si.getOptionDescriptions().get(option), si.getOptionRequirements().get(option));
|
||||
}
|
||||
}
|
||||
//Done
|
||||
cca.queue();
|
||||
continue;
|
||||
}
|
||||
//no options, just push direct cmd
|
||||
guild.upsertCommand(ci.getName(), ci.getDescription()).queue();
|
||||
//Push w/ modifications.
|
||||
cca.queue();
|
||||
}
|
||||
}
|
||||
info("Registered " + i + " commands.");
|
||||
|
|
|
@ -104,7 +104,7 @@ public class SettingCommand extends CommandClass {
|
|||
List<CommandInfo> si = new ArrayList<>();
|
||||
|
||||
CommandInfo ci2 = new CommandInfo("setting", "Permits modification, viewing, and clearing of settings.", CommandType.COMMAND);
|
||||
ci2.addOption("setting_modify", "The type of modification you would like to make.", OptionType.SUB_COMMAND, true);
|
||||
//For those looking here for inspiration, you CANNOT mix options and subcommands. You can only have one or the other.
|
||||
|
||||
CommandInfo ci = new CommandInfo("view", "Shows the current value for the setting provided.", CommandType.SUBCOMMAND);
|
||||
ci.addOption("name", "The name of the setting to display", OptionType.STRING, true);
|
||||
|
|
|
@ -30,6 +30,7 @@ public class CommandInfo {
|
|||
this.options = new HashMap<>();
|
||||
this.optionDescriptions = new HashMap<>();
|
||||
this.optionRequirements = new HashMap<>();
|
||||
this.subCommands = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,6 +41,8 @@ public class CommandInfo {
|
|||
return options != null;
|
||||
}
|
||||
|
||||
public boolean hasSubCommands() { return subCommands != null; }
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
@ -70,10 +73,6 @@ public class CommandInfo {
|
|||
* @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);
|
||||
|
|
Loading…
Reference in a new issue