diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 63e9001..aa00ffa 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/src/main/java/net/hypr/doki/Config.java b/src/main/java/net/hypr/doki/Config.java index f329059..dd9e7af 100644 --- a/src/main/java/net/hypr/doki/Config.java +++ b/src/main/java/net/hypr/doki/Config.java @@ -4,13 +4,13 @@ import com.google.gson.Gson; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; //You can add more fields in this class, if your input json matches the structure //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 String prefix; - @SuppressWarnings("unused") private DBConfig mariadb; + @SuppressWarnings("unused") private DBConfig dbConfig; /** * Returns the configuration object for this bot @@ -19,18 +19,18 @@ public class Config { * @throws IOException if the config JSON could not be read */ public static Config readConfig() throws IOException { + System.out.println(Path.of("config.json")); try (InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json")) { assert in != null; Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8); return new Gson().fromJson(reader, Config.class); } catch (IOException e) { throw new IOException(""" - config.json was not found in the root folder (of the project), did you forget to create it ? + config.json was not found in the root folder (of the project), did you forget to put it ? Example structure: { - "token": "[your_bot_token_here]", - "prefix": "!" + "token": "[your_bot_token_here]" } """, e); } @@ -39,19 +39,17 @@ public class Config { public String getToken() { return token; } - public String getPrefix() { - return prefix; - } public DBConfig getDbConfig() { - return mariadb; + return dbConfig; } public static class DBConfig { - @SuppressWarnings("unused") private String host, user, password, database; + @SuppressWarnings("unused") private String serverName, user, password, dbName; + @SuppressWarnings("unused") private int portNumber; - public String getHost() { - return host; + public String getServerName() { + return serverName; } public String getUser() { @@ -62,8 +60,12 @@ public class Config { return password; } - public String getDatabase() { - return database; + public String getDbName() { + return dbName; + } + + public int getPortNumber() { + return portNumber; } } } \ No newline at end of file diff --git a/src/main/java/net/hypr/doki/Doki.java b/src/main/java/net/hypr/doki/Doki.java index 75225ed..55b33ce 100644 --- a/src/main/java/net/hypr/doki/Doki.java +++ b/src/main/java/net/hypr/doki/Doki.java @@ -6,7 +6,6 @@ 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; @@ -19,21 +18,21 @@ public class Doki { private static String prefix; private static final BasicDataSource dataSource = new BasicDataSource(); - private Doki(JDA jda, Config config) { Doki.jda = jda; Doki.config = config; - Doki.prefix = config.getPrefix(); } - @SuppressWarnings("InstantiationOfUtilityClass") - private static void start() throws IOException, InterruptedException { + public JDA getJDA() { + return jda; + } + + public static Doki start() throws IOException, InterruptedException { config = Config.readConfig(); final JDA jda = JDABuilder.createLight(config.getToken()) .setActivity(Activity.customStatus("Banned from everywhere")) .enableIntents(GatewayIntent.MESSAGE_CONTENT) - .addEventListeners(new LevellingListener()) .build() .awaitReady(); @@ -43,34 +42,16 @@ public class Doki { for (Guild guild : jda.getGuildCache()) { LOGGER.info("\t- {} ({})", guild.getName(), guild.getId()); } - LOGGER.info("Registered prefix: " + config.getPrefix()); - Config.DBConfig dbConfig = config.getDbConfig(); - dataSource.setDriverClassName("org.mariadb.jdbc.Driver"); - dataSource.setUrl("jdbc:mariadb://" + dbConfig.getHost() + "/" + dbConfig.getDatabase()); - dataSource.setUsername(dbConfig.getUser()); - dataSource.setPassword(dbConfig.getPassword()); - dataSource.setMaxTotal(15); - dataSource.setMaxIdle(5); - dataSource.setMinIdle(2); - dataSource.setInitialSize(20); - - new Doki(jda, config); + return new Doki(jda, config); } - public static BasicDataSource getDataSource() { return dataSource; } - - public static JDA getJDA() { return jda; } - - public static String getPrefix() { return prefix; } - public static void main(String[] args) { try { - start(); - jda = getJDA(); + jda = start().getJDA(); CommandsBuilder.newBuilder(437970062922612737L) - .textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(config.getPrefix())) - .build(jda, "net.hypr.doki.commands"); + .textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix("oki!")) + .build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib } catch (Exception e) { LOGGER.error("Unable to start the bot", e); System.exit(-1);