diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fd60df1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,63 @@
+# Created by .ignore support plugin (hsz.mobi)
+### Maven template
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+
+# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
+!/.mvn/wrapper/maven-wrapper.jar
+### JetBrains template
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff:
+.idea/**/tasks.xml
+.idea/dictionaries
+
+# Sensitive or high-churn files:
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.xml
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+
+# Gradle:
+.idea/**/libraries
+.idea\libraries
+
+# Mongo Explorer plugin:
+.idea/**/mongoSettings.xml
+
+## File-based project format:
+*.iws
+*.iml
+
+## Plugin-specific files:
+
+# IntelliJ
+/out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+.idea/
+
+src/test/
+.gradle/
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 9afb719..8085409 100644
--- a/build.gradle
+++ b/build.gradle
@@ -25,5 +25,7 @@ dependencies {
compile "org.reflections:reflections:0.9.10"
compile "org.slf4j:slf4j-simple:1.6.1"
compileOnly "org.projectlombok:lombok:1.16.12"
+ compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
+
}
compileJava.options.encoding = 'UTF-8'
\ No newline at end of file
diff --git a/src/main/java/de/arraying/Copycat/Copycat.java b/src/main/java/de/arraying/Copycat/Copycat.java
index 4a3c856..1c690be 100644
--- a/src/main/java/de/arraying/Copycat/Copycat.java
+++ b/src/main/java/de/arraying/Copycat/Copycat.java
@@ -1,14 +1,24 @@
package de.arraying.Copycat;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import de.arraying.Copycat.commands.Command;
import de.arraying.Copycat.data.DataConfig;
import de.arraying.Copycat.data.DataGuild;
import de.arraying.Copycat.data.DataManager;
import de.arraying.Copycat.data.DataSay;
import de.arraying.Copycat.listeners.ListenerChange;
-import de.arraying.Copycat.commands.Command;
import de.arraying.Copycat.listeners.ListenerChat;
import de.arraying.Copycat.parameters.Parameter;
+import de.arraying.Copycat.utils.UtilsJson;
import de.arraying.Copycat.utils.UtilsRequester;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.TreeMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import javax.security.auth.login.LoginException;
import lombok.Getter;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
@@ -17,19 +27,8 @@
import net.dv8tion.jda.core.entities.Game;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
import net.dv8tion.jda.core.utils.SimpleLog;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
import org.reflections.Reflections;
-import javax.security.auth.login.LoginException;
-import java.io.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.TreeMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-
/**
* Copyright 2017 Arraying
*
@@ -47,161 +46,171 @@
*/
public class Copycat {
- private static Copycat instance;
- @Getter private JDA jda;
- @Getter private TreeMap commands;
- @Getter private HashMap localGuilds;
- @Getter private HashMap queue;
- @Getter private ArrayList parameters;
- @Getter private SimpleLog logger;
- @Getter private DataConfig dataConfig;
- @Getter private DataSay dataSay;
- @Getter private DataManager dataManager;
- @Getter private UtilsRequester requester;
- @Getter private ScheduledExecutorService scheduler;
+ private static Copycat instance;
+ @Getter private JDA jda;
+ @Getter private TreeMap commands;
+ @Getter private HashMap localGuilds;
+ @Getter private HashMap queue;
+ @Getter private ArrayList parameters;
+ @Getter private static SimpleLog logger;
+ @Getter private static DataConfig dataConfig;
+ @Getter private DataSay dataSay;
+ @Getter private DataManager dataManager;
+ @Getter private UtilsRequester requester;
+ @Getter private ScheduledExecutorService scheduler;
+ @Getter private static Gson save;
+ @Getter private static Gson load;
+
+ /**
+ * Static instance getter.
+ *
+ * @return An instance of the object.
+ */
+ public static Copycat getInstance() {
+ if(instance == null) {
+ instance = new Copycat();
+ }
+ return instance;
+ }
+
+ /**
+ * Static gson object for loading
+ *
+ * @return The object
+ */
+ public static Gson getGsonLoad() {
+ return load;
+ }
+
+ /**
+ * Static gson object for saving
+ *
+ * @return The object
+ */
+ public static Gson getGsonSave() {
+ return save;
+ }
+
+ /**
+ * Static logger object for logging
+ *
+ * @return The object
+ */
+ public static SimpleLog getLogger() {
+ return logger;
+ }
- /**
- * Static instance getter.
- * @return An instance of the object.
- */
- public static Copycat getInstance() {
- if(instance == null) {
- instance = new Copycat();
- }
- return instance;
- }
+ /**
+ * Static config object for info
+ *
+ * @return The object
+ */
+ public static DataConfig getConfig() {
+ return dataConfig;
+ }
- void run() {
- long timeBegin = System.currentTimeMillis();
- logger = SimpleLog.getLog("Copycat");
- logger.log(SimpleLog.Level.INFO, "Copycat is now starting.");
- String botToken = "none";
- String botBetaToken = "none";
- String botAuthor = "115134128717955080";
- String botPrefix = "copycat ";
- String botVersion = "1.0.0";
- boolean botBeta = true;
- String mySQLHost = "FILL_IN";
- String mySQLDatabase = "Arraybot";
- String mySQLUsername = "Arraybot";
- String mySQLPassword = "FILL_IN";
- String mySQLGuildsTable = "cc_guilds";
- String keyCarbonitex = "arraying123456789";
- String keyBotsDiscordPw = "abcdefghijklmnopqrstuvwxyz123456789";
- String keyDiscordBotsOrg = "qwertyuiop1234567890";
- File configFile = new File("config.json");
- if(!configFile.exists()) {
- try {
- if(configFile.createNewFile()) {
- String jsonString = "{\n"+
- "\t\"botToken\":\""+botToken+"\",\n"+
- "\t\"botBetaToken\":\""+botBetaToken+"\",\n"+
- "\t\"botAuthor\":\""+botAuthor+"\",\n"+
- "\t\"botPrefix\":\""+botPrefix+"\",\n"+
- "\t\"botVersion\":\""+botVersion+"\",\n"+
- "\t\"botBeta\":"+botBeta+",\n"+
- "\t\"mySQLHost\":\""+mySQLHost+"\",\n"+
- "\t\"mySQLDatabase\":\""+mySQLDatabase+"\",\n"+
- "\t\"mySQLUsername\":\""+mySQLUsername+"\",\n"+
- "\t\"mySQLPassword\":\""+mySQLPassword+"\",\n"+
- "\t\"mySQLGuildsTable\":\""+mySQLGuildsTable+"\",\n"+
- "\t\"keyCarbonitex\":\""+keyCarbonitex+"\",\n"+
- "\t\"keyBotsDiscordPw\":\""+keyBotsDiscordPw+"\",\n"+
- "\t\"keyDiscordBotsOrg\":\""+keyDiscordBotsOrg+"\"\n"+
- "}";
- BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(configFile));
- bufferedWriter.write(jsonString);
- bufferedWriter.close();
- logger.log(SimpleLog.Level.INFO, "Please fill in the config.json information.");
- }
- System.exit(0);
- } catch(Exception e) {
- logger.log(SimpleLog.Level.FATAL, "Could not create config.json.");
- e.printStackTrace();
- System.exit(1);
- }
- } else {
- try {
- JSONParser jsonParser = new JSONParser();
- Object json = jsonParser.parse(new FileReader(configFile));
- JSONObject jsonObject = (JSONObject) json;
- botToken = (String) jsonObject.get("botToken");
- botBetaToken = (String) jsonObject.get("botBetaToken");
- botAuthor = (String) jsonObject.get("botAuthor");
- botPrefix = (String) jsonObject.get("botPrefix");
- botVersion = (String) jsonObject.get("botVersion");
- botBeta = (boolean) jsonObject.get("botBeta");
- mySQLHost = (String) jsonObject.get("mySQLHost");
- mySQLDatabase = (String) jsonObject.get("mySQLDatabase");
- mySQLUsername = (String) jsonObject.get("mySQLUsername");
- mySQLPassword = (String) jsonObject.get("mySQLPassword");
- mySQLGuildsTable = (String) jsonObject.get("mySQLGuildsTable");
- keyCarbonitex = (String) jsonObject.get("keyCarbonitex");
- keyBotsDiscordPw = (String) jsonObject.get("keyBotsDiscordPw");
- keyDiscordBotsOrg = (String) jsonObject.get("keyDiscordBotsOrg");
- dataConfig = new DataConfig(botToken, botBetaToken, botAuthor, botPrefix, botVersion, botBeta,
- mySQLHost, mySQLDatabase, mySQLUsername, mySQLPassword, mySQLGuildsTable,
- keyCarbonitex, keyBotsDiscordPw, keyDiscordBotsOrg);
- } catch(IOException | ParseException e) {
- logger.log(SimpleLog.Level.FATAL, "Could not parse config.json, shutting down.");
- }
- }
- logger.log(SimpleLog.Level.INFO, "Caching all the guilds...");
- localGuilds = new HashMap<>();
- try {
- dataManager = new DataManager();
- dataManager.cacheGuilds();
- } catch(IllegalStateException exception) {
- logger.log(SimpleLog.Level.FATAL, "An exception occurred starting the database manager: "+exception.getMessage());
- return;
- }
- logger.log(SimpleLog.Level.INFO, "Loading in all the languages...");
- try {
- Messages.init();
- } catch(IllegalStateException exception) {
- logger.log(SimpleLog.Level.FATAL, "Unable to start the bot due to a language error.");
- return;
- }
- logger.log(SimpleLog.Level.INFO, "Registering all commands...");
- commands = new TreeMap<>();
- Reflections reflections = new Reflections("de.arraying.Copycat.commands");
- reflections.getSubTypesOf(Command.class).forEach(subclass -> {
- try {
- Command command = subclass.newInstance();
- commands.put(command.getName(), command);
- logger.log(SimpleLog.Level.INFO, "Registered the command \""+command.getName()+"\".");
- } catch(InstantiationException | IllegalAccessException exception) {
- logger.log(SimpleLog.Level.FATAL, "Could not register \""+subclass.getSimpleName()+"\".");
- }
- });
- parameters = new ArrayList<>();
- reflections = new Reflections("de.arraying.Copycat.parameters");
- reflections.getSubTypesOf(Parameter.class).forEach(subclass -> {
- try {
- Parameter parameter = subclass.newInstance();
- parameters.add(parameter);
- logger.log(SimpleLog.Level.INFO, "Registered the parameter \""+parameter.getTrigger()+"\"");
- } catch(InstantiationException | IllegalAccessException exception) {
- logger.log(SimpleLog.Level.FATAL, "Could not register \""+subclass.getSimpleName()+"\".");
- }
- });
- queue = new HashMap<>();
- dataSay = new DataSay();
- requester = new UtilsRequester();
- scheduler = Executors.newScheduledThreadPool(1);
- logger.log(SimpleLog.Level.INFO, "Loaded everything, it took "+(System.currentTimeMillis()-timeBegin)+" milliseconds. Starting JDA now.");
- try {
- jda = new JDABuilder(AccountType.BOT)
- .setToken(botBeta ? botBetaToken : botToken)
- .setStatus(OnlineStatus.DO_NOT_DISTURB)
- .setGame(Game.of(botPrefix+"help || "+botVersion))
- .addEventListener(new ListenerChat())
- .addEventListener(new ListenerChange())
- .buildBlocking();
- } catch(LoginException | InterruptedException | RateLimitedException exception) {
- logger.log(SimpleLog.Level.FATAL, "The bot encountered an exception: "+exception.getMessage());
- return;
- }
- }
+ void run() {
+ long timeBegin = System.currentTimeMillis();
+ save = new GsonBuilder().setPrettyPrinting().create();
+ load = new Gson();
+ logger = SimpleLog.getLog("Copycat");
+ logger.log(SimpleLog.Level.INFO, "Copycat is now starting.");
+ String botToken = "none";
+ String botBetaToken = "none";
+ String botAuthor = "115134128717955080";
+ String botPrefix = "copycat ";
+ String botVersion = "1.0.0";
+ boolean botBeta = true;
+ String mySQLHost = "FILL_IN";
+ String mySQLDatabase = "Arraybot";
+ String mySQLUsername = "Arraybot";
+ String mySQLPassword = "FILL_IN";
+ String mySQLGuildsTable = "cc_guilds";
+ String keyCarbonitex = "arraying123456789";
+ String keyBotsDiscordPw = "abcdefghijklmnopqrstuvwxyz123456789";
+ String keyDiscordBotsOrg = "qwertyuiop1234567890";
+ File configFile = new File("config.json");
+ if(!configFile.exists()) {
+ try {
+ if(configFile.createNewFile()) {
+ dataConfig = new DataConfig(botToken, botBetaToken, botAuthor, botPrefix, botVersion,
+ botBeta, mySQLHost, mySQLDatabase, mySQLUsername, mySQLPassword, mySQLGuildsTable,
+ keyCarbonitex, keyBotsDiscordPw, keyDiscordBotsOrg);
+ UtilsJson.saveConfig(configFile);
+ logger.log(SimpleLog.Level.INFO, "Please fill in the config.json information.");
+ }
+ System.exit(0);
+ } catch(Exception e) {
+ logger.log(SimpleLog.Level.FATAL, "Could not create config.json.");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ } else {
+ dataConfig = UtilsJson.loadConfig(configFile);
+ }
+ logger.log(SimpleLog.Level.INFO, "Caching all the guilds...");
+ localGuilds = new HashMap<>();
+ try {
+ dataManager = new DataManager();
+ dataManager.cacheGuilds();
+ } catch(IllegalStateException exception) {
+ logger.log(SimpleLog.Level.FATAL,
+ "An exception occurred starting the database manager: " + exception.getMessage());
+ return;
+ }
+ logger.log(SimpleLog.Level.INFO, "Loading in all the languages...");
+ try {
+ Messages.init();
+ } catch(IllegalStateException exception) {
+ logger.log(SimpleLog.Level.FATAL, "Unable to start the bot due to a language error.");
+ return;
+ }
+ logger.log(SimpleLog.Level.INFO, "Registering all commands...");
+ commands = new TreeMap<>();
+ Reflections reflections = new Reflections("de.arraying.Copycat.commands");
+ reflections.getSubTypesOf(Command.class).forEach(subclass -> {
+ try {
+ Command command = subclass.newInstance();
+ commands.put(command.getName(), command);
+ logger.log(SimpleLog.Level.INFO, "Registered the command \"" + command.getName() + "\".");
+ } catch(InstantiationException | IllegalAccessException exception) {
+ logger
+ .log(SimpleLog.Level.FATAL, "Could not register \"" + subclass.getSimpleName() + "\".");
+ }
+ });
+ parameters = new ArrayList<>();
+ reflections = new Reflections("de.arraying.Copycat.parameters");
+ reflections.getSubTypesOf(Parameter.class).forEach(subclass -> {
+ try {
+ Parameter parameter = subclass.newInstance();
+ parameters.add(parameter);
+ logger.log(SimpleLog.Level.INFO,
+ "Registered the parameter \"" + parameter.getTrigger() + "\"");
+ } catch(InstantiationException | IllegalAccessException exception) {
+ logger
+ .log(SimpleLog.Level.FATAL, "Could not register \"" + subclass.getSimpleName() + "\".");
+ }
+ });
+ queue = new HashMap<>();
+ dataSay = new DataSay();
+ requester = new UtilsRequester();
+ scheduler = Executors.newScheduledThreadPool(1);
+ logger.log(SimpleLog.Level.INFO,
+ "Loaded everything, it took " + (System.currentTimeMillis() - timeBegin)
+ + " milliseconds. Starting JDA now.");
+ try {
+ jda = new JDABuilder(AccountType.BOT)
+ .setToken(botBeta ? botBetaToken : botToken)
+ .setStatus(OnlineStatus.DO_NOT_DISTURB)
+ .setGame(Game.of(botPrefix + "help || " + botVersion))
+ .addEventListener(new ListenerChat())
+ .addEventListener(new ListenerChange())
+ .buildBlocking();
+ } catch(LoginException | InterruptedException | RateLimitedException exception) {
+ logger.log(SimpleLog.Level.FATAL,
+ "The bot encountered an exception: " + exception.getMessage());
+ return;
+ }
+ }
}
diff --git a/src/main/java/de/arraying/Copycat/data/DataConfig.java b/src/main/java/de/arraying/Copycat/data/DataConfig.java
index f0641d4..a8f56e9 100644
--- a/src/main/java/de/arraying/Copycat/data/DataConfig.java
+++ b/src/main/java/de/arraying/Copycat/data/DataConfig.java
@@ -17,57 +17,191 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-public @Data class DataConfig {
-
- private final String botToken;
- private final String botBetaToken;
- private final String botAuthor;
- private final String botPrefix;
- private final String botVersion;
- private final boolean botBeta;
- private final String mySQLHost;
- private final String mySQLDatabase;
- private final String mySQLUsername;
- private final String mySQLPassword;
- private final String mySQLGuildsTable;
- private final String keyCarbonitex;
- private final String keyBotsDiscordPw;
- private final String keyDiscordBotsOrg;
-
- /**
- * The local config objects file for the bot.
- * @param botToken The token of the bot.
- * @param botBetaToken The token of the beta bot.
- * @param botAuthor The ID of the author of the bot.
- * @param botPrefix The prefix the bot will use.
- * @param botVersion The version of the bot.
- * @param botBeta Whether or not the bot should use the beta token.
- * @param mySQLHost The host name of the MySQL database.
- * @param mySQLDatabase The database name of the MySQL database.
- * @param mySQLUsername The username of the MySQL database.
- * @param mySQLPassword The password of the MySQL database.
- * @param mySQLGuildsTable The name of the table where guilds will be stored in.
- * @param keyCarbonitex The Carbonitex API key.
- * @param keyBotsDiscordPw The bots.discord.pw API key.
- * @param keyDiscordBotsOrg The discordbots.org API key.
- */
- public DataConfig(String botToken, String botBetaToken, String botAuthor, String botPrefix, String botVersion, boolean botBeta,
- String mySQLHost, String mySQLDatabase, String mySQLUsername, String mySQLPassword, String mySQLGuildsTable,
- String keyCarbonitex, String keyBotsDiscordPw, String keyDiscordBotsOrg) {
- this.botToken = botToken;
- this.botBetaToken = botBetaToken;
- this.botAuthor = botAuthor;
- this.botPrefix = botPrefix;
- this.botVersion = botVersion;
- this.botBeta = botBeta;
- this.mySQLHost = mySQLHost;
- this.mySQLDatabase = mySQLDatabase;
- this.mySQLUsername = mySQLUsername;
- this.mySQLPassword = mySQLPassword;
- this.mySQLGuildsTable = mySQLGuildsTable;
- this.keyCarbonitex = keyCarbonitex;
- this.keyBotsDiscordPw = keyBotsDiscordPw;
- this.keyDiscordBotsOrg = keyDiscordBotsOrg;
- }
+public @Data
+class DataConfig {
+
+ private String botToken;
+ private String botBetaToken;
+ private String botAuthor;
+ private String botPrefix;
+ private String botVersion;
+ private boolean botBeta;
+ private String mySQLHost;
+ private String mySQLDatabase;
+ private String mySQLUsername;
+ private String mySQLPassword;
+ private String mySQLGuildsTable;
+ private String keyCarbonitex;
+ private String keyBotsDiscordPw;
+ private String keyDiscordBotsOrg;
+
+ /**
+ * The local config objects file for the bot.
+ *
+ * @param botToken The token of the bot.
+ * @param botBetaToken The token of the beta bot.
+ * @param botAuthor The ID of the author of the bot.
+ * @param botPrefix The prefix the bot will use.
+ * @param botVersion The version of the bot.
+ * @param botBeta Whether or not the bot should use the beta token.
+ * @param mySQLHost The host name of the MySQL database.
+ * @param mySQLDatabase The database name of the MySQL database.
+ * @param mySQLUsername The username of the MySQL database.
+ * @param mySQLPassword The password of the MySQL database.
+ * @param mySQLGuildsTable The name of the table where guilds will be stored in.
+ * @param keyCarbonitex The Carbonitex API key.
+ * @param keyBotsDiscordPw The bots.discord.pw API key.
+ * @param keyDiscordBotsOrg The discordbots.org API key.
+ */
+ public DataConfig(String botToken, String botBetaToken, String botAuthor, String botPrefix,
+ String botVersion, boolean botBeta,
+ String mySQLHost, String mySQLDatabase, String mySQLUsername, String mySQLPassword,
+ String mySQLGuildsTable,
+ String keyCarbonitex, String keyBotsDiscordPw, String keyDiscordBotsOrg) {
+ this.botToken = botToken;
+ this.botBetaToken = botBetaToken;
+ this.botAuthor = botAuthor;
+ this.botPrefix = botPrefix;
+ this.botVersion = botVersion;
+ this.botBeta = botBeta;
+ this.mySQLHost = mySQLHost;
+ this.mySQLDatabase = mySQLDatabase;
+ this.mySQLUsername = mySQLUsername;
+ this.mySQLPassword = mySQLPassword;
+ this.mySQLGuildsTable = mySQLGuildsTable;
+ this.keyCarbonitex = keyCarbonitex;
+ this.keyBotsDiscordPw = keyBotsDiscordPw;
+ this.keyDiscordBotsOrg = keyDiscordBotsOrg;
+ }
+
+ public DataConfig() {
+ }
+
+ /**
+ * Gets the token for the beta bot
+ *
+ * @return The bot's token
+ */
+ public String getBotToken() {
+ return this.botToken;
+ }
+
+ /**
+ * Gets the token for the bot
+ *
+ * @return The beta bot's token
+ */
+ public String getBotBetaToken() {
+ return botBetaToken;
+ }
+
+ /**
+ * Gets the author of the bot
+ *
+ * @return The bot's author
+ */
+ public String getBotAuthor() {
+ return botAuthor;
+ }
+
+ /**
+ * Gets the prefix for the bot
+ *
+ * @return The bot's prefix
+ */
+ public String getBotPrefix() {
+ return botPrefix;
+ }
+
+ /**
+ * Gets the version of the bot
+ *
+ * @return The bot's version
+ */
+ public String getBotVersion() {
+ return botVersion;
+ }
+
+ /**
+ * Gets if the bot is beta or not
+ *
+ * @return {@code true} if it is; otherwise {@code false}
+ */
+ public boolean isBotBeta() {
+ return botBeta;
+ }
+
+ /**
+ * Gets the MySQL host for the bot
+ *
+ * @return The bot's MySQL host
+ */
+ public String getMySQLHost() {
+ return mySQLHost;
+ }
+
+ /**
+ * Gets the MySQL DB for the bot
+ *
+ * @return The bot's DB
+ */
+ public String getMySQLDatabase() {
+ return mySQLDatabase;
+ }
+
+ /**
+ * Gets the <> for the bot
+ *
+ * @return The bot's <>
+ */
+ public String getMySQLUsername() {
+ return mySQLUsername;
+ }
+
+ /**
+ * Gets the MySQL password for the bot
+ *
+ * @return The bot's MySQL password
+ */
+ public String getMySQLPassword() {
+ return mySQLPassword;
+ }
+
+ /**
+ * Gets the Carbonitex key for the bot
+ *
+ * @return The bot's key
+ */
+ public String getKeyCarbonitex() {
+ return keyCarbonitex;
+ }
+
+ /**
+ * Gets the MySQL guild table for the bot
+ *
+ * @return The bot's table name
+ */
+ public String getMySQLGuildsTable() {
+ return mySQLGuildsTable;
+ }
+
+ /**
+ * Gets the Discordpw key for the bot
+ *
+ * @return The bot's key
+ */
+ public String getKeyBotsDiscordPw() {
+ return keyBotsDiscordPw;
+ }
+
+ /**
+ * Gets the DiscordBotsOrg for the bot
+ *
+ * @return The bot's key
+ */
+ public String getKeyDiscordBotsOrg() {
+ return keyDiscordBotsOrg;
+ }
}
+
diff --git a/src/main/java/de/arraying/Copycat/utils/UtilsJson.java b/src/main/java/de/arraying/Copycat/utils/UtilsJson.java
new file mode 100644
index 0000000..33ea695
--- /dev/null
+++ b/src/main/java/de/arraying/Copycat/utils/UtilsJson.java
@@ -0,0 +1,50 @@
+package de.arraying.Copycat.utils;
+
+import de.arraying.Copycat.Copycat;
+import de.arraying.Copycat.data.DataConfig;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * Created by Jacob on 5/5/2017.
+ */
+public class UtilsJson {
+
+ public static boolean saveConfig(File file) {
+ String json = Copycat.save.toJson(Copycat.dataConfig);
+ FileWriter fw = null;
+ try {
+ fw = new FileWriter(file);
+ } catch(IOException e) {
+ Copycat.logger.fatal("Config file failed to write! (Could not create FileWriter)");
+ e.printStackTrace();
+ return false;
+ }
+ try {
+ assert fw != null;
+ fw.write(json);
+ fw.close();
+ } catch(IOException | NullPointerException e) {
+ Copycat.logger.fatal("Config file failed to write! (Could not write)");
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ public static DataConfig loadConfig(File file) {
+ FileReader fr = null;
+ try {
+ fr = new FileReader(file);
+ } catch(FileNotFoundException e) {
+ Copycat.logger.fatal("Config file failed to load! (Could not make FileReader)");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ assert fr != null;
+ return Copycat.load.fromJson(fr, DataConfig.class);
+ }
+}