More hellish slash command handling. You can NOW actually work on commands.
This commit is contained in:
parent
8e128979fc
commit
21586e8713
|
@ -5,13 +5,16 @@ import moe.oko.Kiafumi.command.PingCommand;
|
|||
import moe.oko.Kiafumi.listener.MainListener;
|
||||
import moe.oko.Kiafumi.model.KiafumiDB;
|
||||
import moe.oko.Kiafumi.model.ServerManager;
|
||||
import moe.oko.Kiafumi.util.CommandInfo;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
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.Command;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.requests.restaction.CommandCreateAction;
|
||||
import net.dv8tion.jda.api.utils.ChunkingFilter;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
import org.simpleyaml.configuration.file.YamlConfiguration;
|
||||
|
@ -185,11 +188,25 @@ public class Kiafumi {
|
|||
*/
|
||||
public void registerForGuild(Guild guild) {
|
||||
info("Registering commands for " + guild.getId());
|
||||
int i = 0;
|
||||
for(CommandClass cmd : activeCommands) {
|
||||
for(String name : cmd.getSlashCommandInfo().keySet()) {
|
||||
guild.upsertCommand(name, cmd.getSlashCommandInfo().get(name)).queue();
|
||||
for(CommandInfo ci : cmd.getSlashCommandInfo()) {
|
||||
i++;
|
||||
if(ci.hasOptions()) {
|
||||
CommandCreateAction cca = guild.upsertCommand(ci.getName(), ci.getDescription());
|
||||
for(String name : ci.getOptions().keySet()) {
|
||||
//Any intelligent id 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));
|
||||
}
|
||||
//Done
|
||||
cca.queue();
|
||||
continue;
|
||||
}
|
||||
//no options, just push direct cmd
|
||||
guild.upsertCommand(ci.getName(), ci.getDescription()).queue();
|
||||
}
|
||||
}
|
||||
info("Registered " + i + " commands.");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package moe.oko.Kiafumi.command;
|
||||
|
||||
import moe.oko.Kiafumi.Kiafumi;
|
||||
import moe.oko.Kiafumi.util.CommandInfo;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
@ -70,5 +71,5 @@ public abstract class CommandClass extends ListenerAdapter {
|
|||
* Follow as name, description. (for upsertCommand(name, description);
|
||||
* @return - The name and description for the commands contained within the class.
|
||||
*/
|
||||
public abstract HashMap<String, String> getSlashCommandInfo();
|
||||
public abstract List<CommandInfo> getSlashCommandInfo();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package moe.oko.Kiafumi.command;
|
||||
|
||||
import moe.oko.Kiafumi.Kiafumi;
|
||||
import moe.oko.Kiafumi.util.CommandInfo;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
@ -66,9 +67,10 @@ public class PingCommand extends CommandClass{
|
|||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, String> getSlashCommandInfo() {
|
||||
HashMap<String, String> si = new HashMap<>();
|
||||
si.put("ping", "Bounces back a funny response :)");
|
||||
public List<CommandInfo> getSlashCommandInfo() {
|
||||
List<CommandInfo> si = new ArrayList<>();
|
||||
CommandInfo ci = new CommandInfo("ping", "pings the server with a comedic message :)");
|
||||
si.add(ci);
|
||||
return si;
|
||||
}
|
||||
}
|
||||
|
|
68
src/main/java/moe/oko/Kiafumi/command/SettingCommand.java
Normal file
68
src/main/java/moe/oko/Kiafumi/command/SettingCommand.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
package moe.oko.Kiafumi.command;
|
||||
|
||||
import moe.oko.Kiafumi.util.CommandInfo;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class SettingCommand extends CommandClass {
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true; //Another non-disable command
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void legacyCommand(String[] args, MessageReceivedEvent e, boolean prefix) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newCommand(String name, SlashCommandInteractionEvent e) {
|
||||
switch (name) {
|
||||
case "settings":
|
||||
case "setting":
|
||||
case "setting set":
|
||||
case "setting clear":
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCommandsAsList() {
|
||||
List<String> cmds = new ArrayList<>();
|
||||
cmds.add("settings - displays all available settings for the current guild.");
|
||||
cmds.add("setting - views the current value for the setting.");
|
||||
cmds.add("setting set - sets a setting for the guild you are in.");
|
||||
cmds.add("setting clear - reverts a setting back to its default value.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommandInfo> getSlashCommandInfo() {
|
||||
List<CommandInfo> si = new ArrayList<>();
|
||||
CommandInfo ci = new CommandInfo("setting", "displays all available settings for the current guild");
|
||||
si.add(ci);
|
||||
|
||||
CommandInfo ci2 = new CommandInfo("setting", "views the current value for the setting");
|
||||
ci2.addOption("Setting Name", "The name of the setting to view", OptionType.STRING, true);
|
||||
si.add(ci2);
|
||||
|
||||
CommandInfo ci3 = new CommandInfo("setting set", "sets a setting for the guild you are in");
|
||||
ci3.addOption("Setting Name", "The name of the setting to modify", OptionType.STRING, true);
|
||||
ci3.addOption("Setting Value", "The value to set the setting to", OptionType.STRING, true);
|
||||
si.add(ci3);
|
||||
|
||||
CommandInfo ci4 = new CommandInfo("setting clear", "reverts a setting back to its default value");
|
||||
ci4.addOption("Setting Name", "Name of the setting to clear", OptionType.STRING, true);
|
||||
si.add(ci4);
|
||||
return si;
|
||||
}
|
||||
}
|
|
@ -64,6 +64,21 @@ public class Server {
|
|||
return welcomeChannel;
|
||||
}
|
||||
|
||||
public void setJoinRole(String joinRole) {
|
||||
this.modified = true;
|
||||
this.joinRole = joinRole;
|
||||
}
|
||||
|
||||
public void setWelcomeEnabled(boolean welcomeEnabled) {
|
||||
this.modified = true;
|
||||
this.welcomeEnabled = welcomeEnabled;
|
||||
}
|
||||
|
||||
public void setWelcomeChannel(String welcomeChannel) {
|
||||
this.modified = true;
|
||||
this.welcomeChannel = welcomeChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the modification of the server file in memory
|
||||
* @return - whether the server settings have been modified
|
||||
|
|
52
src/main/java/moe/oko/Kiafumi/util/CommandInfo.java
Normal file
52
src/main/java/moe/oko/Kiafumi/util/CommandInfo.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package moe.oko.Kiafumi.util;
|
||||
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class CommandInfo {
|
||||
private String name;
|
||||
private String description;
|
||||
private HashMap<String, OptionType> options;
|
||||
private HashMap<String, String> optionDescriptions;
|
||||
private HashMap<String, Boolean> optionRequirements;
|
||||
|
||||
public CommandInfo(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.options = new HashMap<>();
|
||||
this.optionDescriptions = new HashMap<>();
|
||||
this.optionRequirements = new HashMap<>();
|
||||
}
|
||||
|
||||
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 void addOption(String name, String description, OptionType type, boolean required) {
|
||||
options.put(name, type);
|
||||
optionDescriptions.put(name, description);
|
||||
optionRequirements.put(name, required);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue