diff --git a/src/main/java/net/hypr/doki/Config.java b/src/main/java/net/hypr/doki/Config.java index 28bcbf8..506f47b 100644 --- a/src/main/java/net/hypr/doki/Config.java +++ b/src/main/java/net/hypr/doki/Config.java @@ -13,6 +13,7 @@ public class Config { @SuppressWarnings("unused") private String token; @SuppressWarnings("unused") private String prefix; @SuppressWarnings("unused") private DBConfig mariadb; + @SuppressWarnings("unused") private boolean levelling = false; /** * Returns the configuration object for this bot @@ -36,6 +37,7 @@ public class Config { return token; } public String getPrefix() { return prefix; } + public boolean getLevelling() { return levelling; } public DBConfig getDbConfig() { return mariadb; diff --git a/src/main/java/net/hypr/doki/Doki.java b/src/main/java/net/hypr/doki/Doki.java index 43d23cf..1beb95a 100644 --- a/src/main/java/net/hypr/doki/Doki.java +++ b/src/main/java/net/hypr/doki/Doki.java @@ -31,7 +31,6 @@ public class Doki { public static void start() throws IOException, InterruptedException { config = Config.readConfig(); - Config.DBConfig dbConfig = config.getDbConfig(); final JDA jda = JDABuilder.createLight(config.getToken()) .setActivity(Activity.customStatus("Banned from everywhere")) @@ -40,16 +39,19 @@ public class Doki { .awaitReady(); // Connect to the DB - dataSource.setDriverClassName("org.mariadb.jdbc.Driver"); - dataSource.setUrl("jdbc:mariadb://" + dbConfig.getHost() + ":" + dbConfig.getPortNumber() + "/" + dbConfig.getDatabase()); - dataSource.setUsername(dbConfig.getUser()); - dataSource.setPassword(dbConfig.getPassword()); - dataSource.setMaxTotal(10); - dataSource.setMaxIdle(5); - dataSource.setMinIdle(2); - dataSource.setInitialSize(10); + if (config.getLevelling()) { + Config.DBConfig dbConfig = config.getDbConfig(); + dataSource.setDriverClassName("org.mariadb.jdbc.Driver"); + dataSource.setUrl("jdbc:mariadb://" + dbConfig.getHost() + ":" + dbConfig.getPortNumber() + "/" + dbConfig.getDatabase()); + dataSource.setUsername(dbConfig.getUser()); + dataSource.setPassword(dbConfig.getPassword()); + dataSource.setMaxTotal(10); + dataSource.setMaxIdle(5); + dataSource.setMinIdle(2); + dataSource.setInitialSize(10); + } - //Print some information about the bot + // Print some information about the bot log.info("Bot connected as {}", jda.getSelfUser().getAsTag()); log.info("The bot is present in the following guilds:"); for (Guild guild : jda.getGuildCache()) { @@ -66,7 +68,11 @@ public class Doki { CommandsBuilder.newBuilder(437970062922612737L) .textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(getPrefix())) .build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib - jda.addEventListener(new LevellingListener()); + if (config.getLevelling()) { + jda.addEventListener(new LevellingListener()); + } else { + log.info("Levelling is disabled"); + } } catch (Exception e) { log.error("Failed to start the bot", e); System.exit(-1); diff --git a/src/main/java/net/hypr/doki/listeners/LevellingListener.java b/src/main/java/net/hypr/doki/listeners/LevellingListener.java index 330cb46..bf8afff 100644 --- a/src/main/java/net/hypr/doki/listeners/LevellingListener.java +++ b/src/main/java/net/hypr/doki/listeners/LevellingListener.java @@ -64,7 +64,7 @@ public class LevellingListener extends ListenerAdapter { } else { log.info("No record of user ID {} in server {}, creating blank record", user.getId(), guild.getId()); try { - UserRecord rec = DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName()); + UserRecord rec = DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong()); LevellingUtils.incrementXp(log, rec); } catch (SQLException e) { throw new RuntimeException(e); diff --git a/src/main/resources/config.schema.json b/src/main/resources/config.schema.json index 8649af9..a403108 100644 --- a/src/main/resources/config.schema.json +++ b/src/main/resources/config.schema.json @@ -32,6 +32,9 @@ "password", "database" ] + }, + "levelling": { + "type": "boolean" } }, "required": [