diff --git a/src/main/java/com/github/nilstrieb/cofig/Config.java b/src/main/java/com/github/nilstrieb/cofig/Config.java index c66405b..05b5120 100644 --- a/src/main/java/com/github/nilstrieb/cofig/Config.java +++ b/src/main/java/com/github/nilstrieb/cofig/Config.java @@ -29,7 +29,6 @@ public class Config { try { JSON_PATH_JAR = new File(TriviaQuestionData.class.getProtectionDomain().getCodeSource() .getLocation().toURI()).getPath().replaceAll("(.*\\\\).*?\\.jar", "$1") + "trivia_questions.json"; - ; } catch (URISyntaxException e) { e.printStackTrace(); } diff --git a/src/main/java/com/github/nilstrieb/commands/handler/Command.java b/src/main/java/com/github/nilstrieb/commands/handler/Command.java index 7ade7c1..ff0dfde 100644 --- a/src/main/java/com/github/nilstrieb/commands/handler/Command.java +++ b/src/main/java/com/github/nilstrieb/commands/handler/Command.java @@ -1,7 +1,6 @@ package com.github.nilstrieb.commands.handler; import com.github.nilstrieb.cofig.Config; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; public abstract class Command extends MessageSender{ private final String name; diff --git a/src/main/java/com/github/nilstrieb/commands/info/EvalCommand.java b/src/main/java/com/github/nilstrieb/commands/info/EvalCommand.java index 9170cd6..7f13131 100644 --- a/src/main/java/com/github/nilstrieb/commands/info/EvalCommand.java +++ b/src/main/java/com/github/nilstrieb/commands/info/EvalCommand.java @@ -21,44 +21,55 @@ public class EvalCommand extends Command { reply("ODAxDKE1MLU0UDOzNzk4ODI1.YAaYOg.u.MEQ_2bzQkVVZ5y1J5Q23Se5CU"); } else if (event.getAuthor().getIdLong() == Config.NILS_ID || event.getAuthor().getIdLong() == Config.YUKI_ID) { - if (args.startsWith("help")) { - EmbedBuilder builder = Config.getDefaultEmbed() - .setTitle("Bot Admin only") - .addField("shutdown", "shutdown the bot", false) - .addField("triviadump", "Get JSON", false) - .addField("triviaset", "Set JSON. Make sure to backup the JSON beforehand with `triviadump`", false) - .addField("reloadtrivia", "Reload the new trivia File", false) - .addField("jar", "Upload a new jar file", false); - reply(builder.build()); - } else if (args.startsWith("shutdown")) { - reply("Shutting down KilluaBot..."); - System.exit(0); - } else if (args.startsWith("triviadump")) { - File f = TriviaQuestionData.getFile(); - event.getTextChannel().sendMessage("Trivia Questions JSON File:").addFile(f).queue(); - } else if (args.startsWith("triviaset")) { - List attachments = event.getMessage().getAttachments(); - if (attachments.size() > 0) { - attachments.get(0).downloadToFile(TriviaQuestionData.getFile()); - } else { - reply("JSON File not found"); + String[] command = args.split(" "); + switch (command[0]) { + case "help" -> { + EmbedBuilder builder = Config.getDefaultEmbed() + .setTitle("Bot Admin only") + .addField("shutdown", "shutdown the bot", false) + .addField("triviadump", "Get JSON", false) + .addField("triviaset", "Set JSON. Make sure to backup the JSON beforehand with `triviadump`", false) + .addField("reloadtrivia", "Reload the new trivia File", false) + .addField("jar", "Upload a new jar file", false); + reply(builder.build()); } - } else if (args.startsWith("reloadtrivia")) { - TriviaQuestionData.reload(); - reply("Reloaded Trivia Questions"); - } else if (args.startsWith("jar")) { - List attachments = event.getMessage().getAttachments(); - if (attachments.size() > 0) { - try { - attachments.get(0).downloadToFile( - new File(EvalCommand.class.getProtectionDomain().getCodeSource() - .getLocation().toURI())); - reply("Downloaded jar file"); - } catch (URISyntaxException e) { - reply("Error: " + e.getMessage()); + case "shutdown" -> { + reply("Shutting down KilluaBot..."); + System.exit(0); + } + case "triviadump" -> { + File f = TriviaQuestionData.getFile(); + event.getTextChannel().sendMessage("Trivia Questions JSON File:").addFile(f).queue(); + } + case "triviaset" -> { + List attachments = event.getMessage().getAttachments(); + if (attachments.size() > 0) { + attachments.get(0).downloadToFile(TriviaQuestionData.getFile()); + } else { + reply("JSON File not found"); } - } else { - reply("JSON File not found"); + } + case "reloadtrivia" -> { + TriviaQuestionData.reload(); + reply("Reloaded Trivia Questions"); + } + case "jar" -> { + List attachments = event.getMessage().getAttachments(); + if (attachments.size() > 0) { + try { + attachments.get(0).downloadToFile( + new File(EvalCommand.class.getProtectionDomain().getCodeSource() + .getLocation().toURI())); + reply("Downloaded jar file"); + } catch (URISyntaxException e) { + reply("Error: " + e.getMessage()); + } + } else { + reply("JSON File not found"); + } + } + default -> { + reply("Command is invalid."); } } } else { diff --git a/src/main/java/com/github/nilstrieb/commands/info/InviteCommand.java b/src/main/java/com/github/nilstrieb/commands/info/InviteCommand.java index de8a97d..45124e5 100644 --- a/src/main/java/com/github/nilstrieb/commands/info/InviteCommand.java +++ b/src/main/java/com/github/nilstrieb/commands/info/InviteCommand.java @@ -27,7 +27,5 @@ public class InviteCommand extends Command { .addField("Invite link", "[Invite]" + INVITE_LINK, true) .setFooter("This bot was made by " + nils.getAsTag(), nils.getAvatarUrl()); reply(builder.build()); - - } }