Make enabling levelling optional
This commit is contained in:
parent
cc7ea9381c
commit
269c44c065
4 changed files with 23 additions and 12 deletions
|
@ -13,6 +13,7 @@ public class Config {
|
||||||
@SuppressWarnings("unused") private String token;
|
@SuppressWarnings("unused") private String token;
|
||||||
@SuppressWarnings("unused") private String prefix;
|
@SuppressWarnings("unused") private String prefix;
|
||||||
@SuppressWarnings("unused") private DBConfig mariadb;
|
@SuppressWarnings("unused") private DBConfig mariadb;
|
||||||
|
@SuppressWarnings("unused") private boolean levelling = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the configuration object for this bot
|
* Returns the configuration object for this bot
|
||||||
|
@ -36,6 +37,7 @@ public class Config {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
public String getPrefix() { return prefix; }
|
public String getPrefix() { return prefix; }
|
||||||
|
public boolean getLevelling() { return levelling; }
|
||||||
|
|
||||||
public DBConfig getDbConfig() {
|
public DBConfig getDbConfig() {
|
||||||
return mariadb;
|
return mariadb;
|
||||||
|
|
|
@ -31,7 +31,6 @@ public class Doki {
|
||||||
|
|
||||||
public static void start() throws IOException, InterruptedException {
|
public static void start() throws IOException, InterruptedException {
|
||||||
config = Config.readConfig();
|
config = Config.readConfig();
|
||||||
Config.DBConfig dbConfig = config.getDbConfig();
|
|
||||||
|
|
||||||
final JDA jda = JDABuilder.createLight(config.getToken())
|
final JDA jda = JDABuilder.createLight(config.getToken())
|
||||||
.setActivity(Activity.customStatus("Banned from everywhere"))
|
.setActivity(Activity.customStatus("Banned from everywhere"))
|
||||||
|
@ -40,6 +39,8 @@ public class Doki {
|
||||||
.awaitReady();
|
.awaitReady();
|
||||||
|
|
||||||
// Connect to the DB
|
// Connect to the DB
|
||||||
|
if (config.getLevelling()) {
|
||||||
|
Config.DBConfig dbConfig = config.getDbConfig();
|
||||||
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
|
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
|
||||||
dataSource.setUrl("jdbc:mariadb://" + dbConfig.getHost() + ":" + dbConfig.getPortNumber() + "/" + dbConfig.getDatabase());
|
dataSource.setUrl("jdbc:mariadb://" + dbConfig.getHost() + ":" + dbConfig.getPortNumber() + "/" + dbConfig.getDatabase());
|
||||||
dataSource.setUsername(dbConfig.getUser());
|
dataSource.setUsername(dbConfig.getUser());
|
||||||
|
@ -48,6 +49,7 @@ public class Doki {
|
||||||
dataSource.setMaxIdle(5);
|
dataSource.setMaxIdle(5);
|
||||||
dataSource.setMinIdle(2);
|
dataSource.setMinIdle(2);
|
||||||
dataSource.setInitialSize(10);
|
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("Bot connected as {}", jda.getSelfUser().getAsTag());
|
||||||
|
@ -66,7 +68,11 @@ public class Doki {
|
||||||
CommandsBuilder.newBuilder(437970062922612737L)
|
CommandsBuilder.newBuilder(437970062922612737L)
|
||||||
.textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(getPrefix()))
|
.textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(getPrefix()))
|
||||||
.build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib
|
.build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib
|
||||||
|
if (config.getLevelling()) {
|
||||||
jda.addEventListener(new LevellingListener());
|
jda.addEventListener(new LevellingListener());
|
||||||
|
} else {
|
||||||
|
log.info("Levelling is disabled");
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to start the bot", e);
|
log.error("Failed to start the bot", e);
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class LevellingListener extends ListenerAdapter {
|
||||||
} else {
|
} else {
|
||||||
log.info("No record of user ID {} in server {}, creating blank record", user.getId(), guild.getId());
|
log.info("No record of user ID {} in server {}, creating blank record", user.getId(), guild.getId());
|
||||||
try {
|
try {
|
||||||
UserRecord rec = DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName());
|
UserRecord rec = DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong());
|
||||||
LevellingUtils.incrementXp(log, rec);
|
LevellingUtils.incrementXp(log, rec);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
"password",
|
"password",
|
||||||
"database"
|
"database"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"levelling": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|
Loading…
Reference in a new issue