2022-03-28 15:23:10 +00:00
|
|
|
package moe.oko.Kiafumi.command;
|
|
|
|
|
2022-03-28 15:56:45 +00:00
|
|
|
import moe.oko.Kiafumi.Kiafumi;
|
|
|
|
import moe.oko.Kiafumi.model.Server;
|
2022-03-28 15:23:10 +00:00
|
|
|
import moe.oko.Kiafumi.util.CommandInfo;
|
2022-03-29 11:52:52 +00:00
|
|
|
import moe.oko.Kiafumi.util.EmbedUI;
|
2022-03-28 15:56:45 +00:00
|
|
|
import net.dv8tion.jda.api.EmbedBuilder;
|
2022-03-28 15:23:10 +00:00
|
|
|
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;
|
|
|
|
|
2022-03-28 15:56:45 +00:00
|
|
|
import java.time.ZonedDateTime;
|
2022-03-28 15:23:10 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
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) {
|
2022-03-28 16:41:43 +00:00
|
|
|
if(e.getGuild() != null) {
|
2022-03-28 15:56:45 +00:00
|
|
|
Server server = Kiafumi.instance.getServerManager().getOrCreateServer(e.getGuild());
|
|
|
|
switch (name) {
|
|
|
|
case "settings":
|
|
|
|
e.deferReply().queue();
|
|
|
|
//No options, just fire an embed off...
|
|
|
|
EmbedBuilder eb = new EmbedBuilder()
|
2022-03-29 11:52:52 +00:00
|
|
|
.setColor(EmbedUI.INFO)
|
|
|
|
.setTitle("Kiafumi Settings")
|
|
|
|
.setDescription(server.getOpts())
|
|
|
|
.setFooter(EmbedUI.BRAND)
|
|
|
|
.setTimestamp(ZonedDateTime.now());
|
2022-03-28 15:56:45 +00:00
|
|
|
e.getHook().sendMessageEmbeds(eb.build()).queue();
|
|
|
|
return;
|
|
|
|
case "setting":
|
|
|
|
e.deferReply().queue();
|
2022-03-28 17:25:03 +00:00
|
|
|
String opt = e.getOption("setting_name").getAsString();
|
2022-03-28 15:56:45 +00:00
|
|
|
EmbedBuilder eb1 = new EmbedBuilder()
|
2022-03-29 11:52:52 +00:00
|
|
|
.setColor(EmbedUI.INFO)
|
|
|
|
.setTitle(opt)
|
|
|
|
.setDescription("Value: `" + server.getOptionByString(opt) + '`')
|
|
|
|
.setFooter(EmbedUI.BRAND)
|
|
|
|
.setTimestamp(ZonedDateTime.now());
|
2022-03-28 15:56:45 +00:00
|
|
|
e.getHook().sendMessageEmbeds(eb1.build()).queue();
|
|
|
|
return;
|
2022-03-28 17:25:03 +00:00
|
|
|
case "setting_set":
|
2022-03-28 15:56:45 +00:00
|
|
|
e.deferReply().queue();
|
2022-03-28 17:25:03 +00:00
|
|
|
String opt1 = e.getOption("setting_name").getAsString();
|
|
|
|
String opt2 = e.getOption("setting_value").getAsString();
|
2022-03-28 15:56:45 +00:00
|
|
|
String response = server.setOptionByString(opt1, opt2);
|
|
|
|
EmbedBuilder eb2 = new EmbedBuilder()
|
2022-03-29 11:52:52 +00:00
|
|
|
.setColor(EmbedUI.SUCCESS)
|
|
|
|
.setTitle(opt1)
|
|
|
|
.setDescription(response)
|
|
|
|
.setFooter(EmbedUI.BRAND)
|
|
|
|
.setTimestamp(ZonedDateTime.now());
|
2022-03-28 15:56:45 +00:00
|
|
|
e.getHook().sendMessageEmbeds(eb2.build()).queue();
|
|
|
|
return;
|
2022-03-28 17:25:03 +00:00
|
|
|
case "setting_clear":
|
2022-03-28 15:56:45 +00:00
|
|
|
e.deferReply().queue();
|
2022-03-28 17:25:03 +00:00
|
|
|
String opt3 = e.getOption("setting_name").getAsString();
|
2022-03-28 15:56:45 +00:00
|
|
|
String response1 = server.resetOptionByString(opt3);
|
|
|
|
EmbedBuilder eb3 = new EmbedBuilder()
|
2022-03-29 11:52:52 +00:00
|
|
|
.setColor(EmbedUI.SUCCESS)
|
|
|
|
.setTitle(opt3)
|
|
|
|
.setDescription(response1)
|
|
|
|
.setFooter(EmbedUI.BRAND)
|
|
|
|
.setTimestamp(ZonedDateTime.now());
|
2022-03-28 15:56:45 +00:00
|
|
|
e.getHook().sendMessageEmbeds(eb3.build()).queue();
|
|
|
|
return;
|
|
|
|
}
|
2022-03-28 15:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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<>();
|
2022-03-28 19:38:25 +00:00
|
|
|
CommandInfo ci = new CommandInfo("setting", "displays a specific setting for the current guild");
|
2022-03-28 15:23:10 +00:00
|
|
|
si.add(ci);
|
|
|
|
|
|
|
|
CommandInfo ci2 = new CommandInfo("setting", "views the current value for the setting");
|
2022-03-28 17:25:03 +00:00
|
|
|
ci2.addOption("setting_name", "The name of the setting to view", OptionType.STRING, true);
|
2022-03-28 15:23:10 +00:00
|
|
|
si.add(ci2);
|
|
|
|
|
2022-03-28 17:25:03 +00:00
|
|
|
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);
|
2022-03-28 15:23:10 +00:00
|
|
|
si.add(ci3);
|
|
|
|
|
2022-03-28 17:25:03 +00:00
|
|
|
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);
|
2022-03-28 15:23:10 +00:00
|
|
|
si.add(ci4);
|
2022-03-28 19:38:25 +00:00
|
|
|
|
|
|
|
CommandInfo ci5 = new CommandInfo("settings", "displays all settings available for the guild.");
|
|
|
|
si.add(ci5);
|
2022-03-28 15:23:10 +00:00
|
|
|
return si;
|
|
|
|
}
|
|
|
|
}
|