Unbreak everything

This commit is contained in:
floppydiskette 2024-08-21 21:57:00 +01:00
parent c229823a0a
commit f8f0bb493b
Signed by: fwoppydwisk
SSH key fingerprint: SHA256:Hqn452XQ1ETzUt/FthJu6+OFkS4NBxCv5VQSEvuk7CE
2 changed files with 24 additions and 13 deletions

View file

@ -10,7 +10,8 @@ import java.nio.file.Path;
//You will need a valid config.json in the package com.freya02.bot for this to work
public class Config {
@SuppressWarnings("unused") private String token;
@SuppressWarnings("unused") private DBConfig dbConfig;
@SuppressWarnings("unused") private String prefix;
@SuppressWarnings("unused") private DBConfig mariadb;
/**
* Returns the configuration object for this bot
@ -38,18 +39,17 @@ public class Config {
public String getToken() {
return token;
}
public String getPrefix() { return prefix; }
public DBConfig getDbConfig() {
return dbConfig;
return mariadb;
}
public static class DBConfig {
@SuppressWarnings("unused") private String serverName, user, password, dbName;
@SuppressWarnings("unused") private String host, user, password, database;
@SuppressWarnings("unused") private int portNumber;
public String getServerName() {
return serverName;
}
public String getHost() { return host; }
public String getUser() {
return user;
@ -59,10 +59,7 @@ public class Config {
return password;
}
public String getDbName() {
return dbName;
}
public String getDatabase() { return database; }
public int getPortNumber() {
return portNumber;
}

View file

@ -6,6 +6,7 @@ import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.hypr.doki.listeners.LevellingListener;
import org.apache.commons.dbcp2.BasicDataSource;
import org.slf4j.Logger;
@ -15,7 +16,6 @@ public class Doki {
private static final Logger LOGGER = Logging.getLogger();
private static JDA jda;
private static Config config;
private static String prefix;
private static final BasicDataSource dataSource = new BasicDataSource();
private Doki(JDA jda, Config config) {
@ -23,12 +23,15 @@ public class Doki {
Doki.config = config;
}
public JDA getJDA() {
public static JDA getJDA() {
return jda;
}
public static String getPrefix() { return config.getPrefix(); }
public static BasicDataSource getDataSource() { return dataSource; }
public static Doki 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"))
@ -36,6 +39,16 @@ public class Doki {
.build()
.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);
//Print some information about the bot
LOGGER.info("Bot connected as {}", jda.getSelfUser().getAsTag());
LOGGER.info("The bot is present on these guilds :");
@ -50,8 +63,9 @@ public class Doki {
try {
jda = start().getJDA();
CommandsBuilder.newBuilder(437970062922612737L)
.textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix("oki!"))
.textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(getPrefix()))
.build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib
jda.addEventListener(new LevellingListener());
} catch (Exception e) {
LOGGER.error("Unable to start the bot", e);
System.exit(-1);