Setting Command Functional?
This commit is contained in:
parent
21586e8713
commit
56d6f3c959
|
@ -2,6 +2,7 @@ package moe.oko.Kiafumi;
|
|||
|
||||
import moe.oko.Kiafumi.command.CommandClass;
|
||||
import moe.oko.Kiafumi.command.PingCommand;
|
||||
import moe.oko.Kiafumi.command.SettingCommand;
|
||||
import moe.oko.Kiafumi.listener.MainListener;
|
||||
import moe.oko.Kiafumi.model.KiafumiDB;
|
||||
import moe.oko.Kiafumi.model.ServerManager;
|
||||
|
@ -78,6 +79,7 @@ public class Kiafumi {
|
|||
//All commands to be loaded on startup!
|
||||
activeCommands = new ArrayList<>();
|
||||
activeCommands.add(new PingCommand());
|
||||
activeCommands.add(new SettingCommand());
|
||||
|
||||
instance = this;
|
||||
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package moe.oko.Kiafumi.command;
|
||||
|
||||
import moe.oko.Kiafumi.Kiafumi;
|
||||
import moe.oko.Kiafumi.model.Server;
|
||||
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;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -27,11 +32,58 @@ public class SettingCommand extends CommandClass {
|
|||
|
||||
@Override
|
||||
public void newCommand(String name, SlashCommandInteractionEvent e) {
|
||||
if(e.getGuild() == null) {
|
||||
e.getChannel().sendMessage("This is a guild only command.").queue();
|
||||
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()
|
||||
.setColor(Color.PINK)
|
||||
.setTitle("Server Settings")
|
||||
.setFooter("Kiafumi - Maintained by oko.moe")
|
||||
.setTimestamp(ZonedDateTime.now())
|
||||
.setDescription(server.getOpts());
|
||||
e.getHook().sendMessageEmbeds(eb.build()).queue();
|
||||
return;
|
||||
case "setting":
|
||||
e.deferReply().queue();
|
||||
String opt = e.getOption("Setting Name").getAsString();
|
||||
EmbedBuilder eb1 = new EmbedBuilder()
|
||||
.setColor(Color.PINK)
|
||||
.setTitle(opt + " Value")
|
||||
.setFooter("Kiafumi - Maintained by oko.moe")
|
||||
.setTimestamp(ZonedDateTime.now())
|
||||
.setDescription(server.getOptionByString(opt));
|
||||
e.getHook().sendMessageEmbeds(eb1.build()).queue();
|
||||
return;
|
||||
case "setting set":
|
||||
e.deferReply().queue();
|
||||
String opt1 = e.getOption("Setting Name").getAsString();
|
||||
String opt2 = e.getOption("Setting Value").getAsString();
|
||||
String response = server.setOptionByString(opt1, opt2);
|
||||
EmbedBuilder eb2 = new EmbedBuilder()
|
||||
.setColor(Color.PINK)
|
||||
.setTitle("Setting Modification - " + opt1)
|
||||
.setFooter("Kiafumi - Maintained by oko.moe")
|
||||
.setTimestamp(ZonedDateTime.now())
|
||||
.setDescription(response);
|
||||
e.getHook().sendMessageEmbeds(eb2.build()).queue();
|
||||
return;
|
||||
case "setting clear":
|
||||
e.deferReply().queue();
|
||||
String opt3 = e.getOption("Setting Name").getAsString();
|
||||
String response1 = server.resetOptionByString(opt3);
|
||||
EmbedBuilder eb3 = new EmbedBuilder()
|
||||
.setColor(Color.PINK)
|
||||
.setTitle("Setting Reset - " + opt3)
|
||||
.setFooter("Kiafumi - Maintained by oko.moe")
|
||||
.setTimestamp(ZonedDateTime.now())
|
||||
.setDescription(response1);
|
||||
e.getHook().sendMessageEmbeds(eb3.build()).queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package moe.oko.Kiafumi.model;
|
||||
|
||||
import moe.oko.Kiafumi.Kiafumi;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
|
@ -87,6 +89,96 @@ public class Server {
|
|||
return modified;
|
||||
}
|
||||
|
||||
public String getOpts() {
|
||||
return "welcomeEnabled - whether or not join/leave logs are enabled" +
|
||||
"\nwelcomeChannel - the channel to send welcome messages to" +
|
||||
"\njoinRole - the role to apply to new members who join this guild" +
|
||||
"\nserverProtected - Determines whether or not server protections are enabled.";
|
||||
}
|
||||
|
||||
public String getOptionByString(String string) {
|
||||
switch(string.toLowerCase()) {
|
||||
case "welcomeenabled":
|
||||
if(!welcomeEnabled) {
|
||||
return "False";
|
||||
} else {
|
||||
return "True";
|
||||
}
|
||||
case "joinrole":
|
||||
return joinRole;
|
||||
case "welcomechannel":
|
||||
return welcomeChannel;
|
||||
case "serverprotected":
|
||||
if(!serverProtected) {
|
||||
return "False";
|
||||
} else {
|
||||
return "True";
|
||||
}
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
public String resetOptionByString(String name) {
|
||||
switch(name.toLowerCase()) {
|
||||
case "welcomeenabled":
|
||||
welcomeEnabled = false;
|
||||
return "Reset Join/Leave logs to default.";
|
||||
case "joinrole":
|
||||
joinRole = null;
|
||||
return "Auto-role on join is now set to disabled (Default).";
|
||||
case "welcomechannel":
|
||||
welcomeChannel = null;
|
||||
return "Welcome channel is now unset.";
|
||||
case "serverprotected":
|
||||
serverProtected = true;
|
||||
return "Server protection set to default.";
|
||||
default:
|
||||
return "INVALID SETTING";
|
||||
}
|
||||
}
|
||||
|
||||
public String setOptionByString(String name, String value) {
|
||||
switch (name.toLowerCase()) {
|
||||
case "welcomeenabled":
|
||||
if(value.equalsIgnoreCase("false")) {
|
||||
welcomeEnabled = false;
|
||||
return "Join/Leave logs are now disabled.";
|
||||
} else if(value.equalsIgnoreCase("true")) {
|
||||
welcomeEnabled = true;
|
||||
return "Join/Leave logs are now enabled. Make sure you set the `welcomeChannel` setting.";
|
||||
} else {
|
||||
return "Bad Value, use either true or false";
|
||||
}
|
||||
case "joinrole":
|
||||
if(Kiafumi.JDA.getRoleById(value) == null) {
|
||||
return "That role ID is invalid.";
|
||||
} else {
|
||||
joinRole = value;
|
||||
return "Successfully set joinRole ID to " + value;
|
||||
}
|
||||
case "welcomechannel":
|
||||
if(Kiafumi.JDA.getTextChannelById(value) == null) {
|
||||
return "That channel ID is invalid.";
|
||||
} else {
|
||||
welcomeChannel = value;
|
||||
return "Successfully set welcomeChannel ID to " + value;
|
||||
}
|
||||
case "serverprotected":
|
||||
if(value.equalsIgnoreCase("false")) {
|
||||
serverProtected = false;
|
||||
return "Server protection is now disabled.";
|
||||
} else if(value.equalsIgnoreCase("true")) {
|
||||
serverProtected = true;
|
||||
return "Server protection is now enabled.";
|
||||
} else {
|
||||
return "Bad Value, use either true or false";
|
||||
}
|
||||
default:
|
||||
return "INVALID setting name.";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Server{id=" + this.id + ",welcomeEnabled=" + welcomeEnabled + ",welcomeChannel="+welcomeChannel+
|
||||
|
|
Loading…
Reference in a new issue