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,16 +39,19 @@ public class Doki {
|
||||||
.awaitReady();
|
.awaitReady();
|
||||||
|
|
||||||
// Connect to the DB
|
// Connect to the DB
|
||||||
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
|
if (config.getLevelling()) {
|
||||||
dataSource.setUrl("jdbc:mariadb://" + dbConfig.getHost() + ":" + dbConfig.getPortNumber() + "/" + dbConfig.getDatabase());
|
Config.DBConfig dbConfig = config.getDbConfig();
|
||||||
dataSource.setUsername(dbConfig.getUser());
|
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
|
||||||
dataSource.setPassword(dbConfig.getPassword());
|
dataSource.setUrl("jdbc:mariadb://" + dbConfig.getHost() + ":" + dbConfig.getPortNumber() + "/" + dbConfig.getDatabase());
|
||||||
dataSource.setMaxTotal(10);
|
dataSource.setUsername(dbConfig.getUser());
|
||||||
dataSource.setMaxIdle(5);
|
dataSource.setPassword(dbConfig.getPassword());
|
||||||
dataSource.setMinIdle(2);
|
dataSource.setMaxTotal(10);
|
||||||
dataSource.setInitialSize(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("Bot connected as {}", jda.getSelfUser().getAsTag());
|
||||||
log.info("The bot is present in the following guilds:");
|
log.info("The bot is present in the following guilds:");
|
||||||
for (Guild guild : jda.getGuildCache()) {
|
for (Guild guild : jda.getGuildCache()) {
|
||||||
|
@ -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
|
||||||
jda.addEventListener(new LevellingListener());
|
if (config.getLevelling()) {
|
||||||
|
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