diff --git a/src/main/java/moe/oko/Kiafumi/Kiafumi.java b/src/main/java/moe/oko/Kiafumi/Kiafumi.java index 6c6bda5..87b17a6 100644 --- a/src/main/java/moe/oko/Kiafumi/Kiafumi.java +++ b/src/main/java/moe/oko/Kiafumi/Kiafumi.java @@ -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."); } /* diff --git a/src/main/java/moe/oko/Kiafumi/command/CommandClass.java b/src/main/java/moe/oko/Kiafumi/command/CommandClass.java index 1ffa5f0..07c5491 100644 --- a/src/main/java/moe/oko/Kiafumi/command/CommandClass.java +++ b/src/main/java/moe/oko/Kiafumi/command/CommandClass.java @@ -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 getSlashCommandInfo(); + public abstract List getSlashCommandInfo(); } diff --git a/src/main/java/moe/oko/Kiafumi/command/PingCommand.java b/src/main/java/moe/oko/Kiafumi/command/PingCommand.java index 384b210..f3fe2c3 100644 --- a/src/main/java/moe/oko/Kiafumi/command/PingCommand.java +++ b/src/main/java/moe/oko/Kiafumi/command/PingCommand.java @@ -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 getSlashCommandInfo() { - HashMap si = new HashMap<>(); - si.put("ping", "Bounces back a funny response :)"); + public List getSlashCommandInfo() { + List si = new ArrayList<>(); + CommandInfo ci = new CommandInfo("ping", "pings the server with a comedic message :)"); + si.add(ci); return si; } } diff --git a/src/main/java/moe/oko/Kiafumi/command/SettingCommand.java b/src/main/java/moe/oko/Kiafumi/command/SettingCommand.java new file mode 100644 index 0000000..53e07a7 --- /dev/null +++ b/src/main/java/moe/oko/Kiafumi/command/SettingCommand.java @@ -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 getCommandsAsList() { + List 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 getSlashCommandInfo() { + List 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; + } +} diff --git a/src/main/java/moe/oko/Kiafumi/model/Server.java b/src/main/java/moe/oko/Kiafumi/model/Server.java index 6767dfa..a0eec8b 100644 --- a/src/main/java/moe/oko/Kiafumi/model/Server.java +++ b/src/main/java/moe/oko/Kiafumi/model/Server.java @@ -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 diff --git a/src/main/java/moe/oko/Kiafumi/util/CommandInfo.java b/src/main/java/moe/oko/Kiafumi/util/CommandInfo.java new file mode 100644 index 0000000..8b6f010 --- /dev/null +++ b/src/main/java/moe/oko/Kiafumi/util/CommandInfo.java @@ -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 options; + private HashMap optionDescriptions; + private HashMap 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 getOptions() { + return options; + } + + public HashMap getOptionRequirements() { + return optionRequirements; + } + + public HashMap 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); + } +}