diff --git a/.gitignore b/.gitignore index 7cb2ea7..88f2c75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ target/ -out/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ diff --git a/.idea/artifacts/doki_jar.xml b/.idea/artifacts/doki_jar.xml deleted file mode 100644 index b4fd852..0000000 --- a/.idea/artifacts/doki_jar.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - $PROJECT_DIR$/out/artifacts/doki_jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ 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 c6b233e..72b5395 100644 --- a/src/main/java/net/hypr/doki/Config.java +++ b/src/main/java/net/hypr/doki/Config.java @@ -1,14 +1,12 @@ package net.hypr.doki; -import com.freya02.botcommands.api.Logging; import com.google.gson.Gson; -import org.slf4j.Logger; import java.io.*; import java.nio.charset.StandardCharsets; //You can add more fields in this class, if your input json matches the structure -//You will need a valid config.json in the resources folder for this to work +//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; @@ -21,15 +19,19 @@ public class Config { * @throws IOException if the config JSON could not be read */ public static Config readConfig() throws IOException { - Logger log = Logging.getLogger(); try (InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json")) { assert in != null; Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8); - log.info("Loaded config"); return new Gson().fromJson(reader, Config.class); } catch (IOException | NullPointerException e) { - log.error("Failed to load config.json, does the file exist?"); - throw new IOException(e); + throw new IOException(""" + 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]" + } + """, e); } } diff --git a/src/main/java/net/hypr/doki/Doki.java b/src/main/java/net/hypr/doki/Doki.java index 43d23cf..c0251fb 100644 --- a/src/main/java/net/hypr/doki/Doki.java +++ b/src/main/java/net/hypr/doki/Doki.java @@ -13,7 +13,7 @@ import org.slf4j.Logger; import java.io.IOException; public class Doki { - private static final Logger log = Logging.getLogger(); + private static final Logger LOGGER = Logging.getLogger(); private static JDA jda; private static Config config; private static final BasicDataSource dataSource = new BasicDataSource(); @@ -50,10 +50,10 @@ public class Doki { dataSource.setInitialSize(10); //Print some information about the bot - log.info("Bot connected as {}", jda.getSelfUser().getAsTag()); - log.info("The bot is present in the following guilds:"); + LOGGER.info("Bot connected as {}", jda.getSelfUser().getAsTag()); + LOGGER.info("The bot is present on these guilds :"); for (Guild guild : jda.getGuildCache()) { - log.info("\t- {} ({})", guild.getName(), guild.getId()); + LOGGER.info("\t- {} ({})", guild.getName(), guild.getId()); } new Doki(jda, config); @@ -68,7 +68,7 @@ public class Doki { .build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib jda.addEventListener(new LevellingListener()); } catch (Exception e) { - log.error("Failed to start the bot", e); + LOGGER.error("Unable 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..2568523 100644 --- a/src/main/java/net/hypr/doki/listeners/LevellingListener.java +++ b/src/main/java/net/hypr/doki/listeners/LevellingListener.java @@ -64,8 +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()); - LevellingUtils.incrementXp(log, rec); + DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName()); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/src/main/java/net/hypr/doki/utils/DBUtils.java b/src/main/java/net/hypr/doki/utils/DBUtils.java index 48f04fc..7825b2a 100644 --- a/src/main/java/net/hypr/doki/utils/DBUtils.java +++ b/src/main/java/net/hypr/doki/utils/DBUtils.java @@ -53,7 +53,7 @@ public class DBUtils { * @param username The users username * @throws SQLException A SQL exception */ - public static UserRecord createUserRecord(long user_id, long server_id, String username) throws SQLException { + public static void createUserRecord(long user_id, long server_id, String username) throws SQLException { Logger log = Logging.getLogger(); log.info("Creating record (usr:{},srv:{},unm:{})", user_id, server_id, username); BasicDataSource dataSource = Doki.getDataSource(); @@ -67,7 +67,6 @@ public class DBUtils { stmt.setTimestamp(4, Timestamp.valueOf(LocalDateTime.now())); stmt.execute(); log.info("Record (usr:{},srv:{},unm:{}) created!", user_id, server_id, username); - return new UserRecord(user_id, server_id, username); } /** diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index f185663..0000000 --- a/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: net.hypr.doki.Doki -