diff --git a/.gitignore b/.gitignore index 88f2c75..7cb2ea7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ 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 new file mode 100644 index 0000000..b4fd852 --- /dev/null +++ b/.idea/artifacts/doki_jar.xml @@ -0,0 +1,48 @@ + + + $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 72b5395..c6b233e 100644 --- a/src/main/java/net/hypr/doki/Config.java +++ b/src/main/java/net/hypr/doki/Config.java @@ -1,12 +1,14 @@ 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 package com.freya02.bot for this to work +//You will need a valid config.json in the resources folder for this to work public class Config { @SuppressWarnings("unused") private String token; @SuppressWarnings("unused") private String prefix; @@ -19,19 +21,15 @@ 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) { - 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); + log.error("Failed to load config.json, does the file exist?"); + throw new IOException(e); } } diff --git a/src/main/java/net/hypr/doki/Doki.java b/src/main/java/net/hypr/doki/Doki.java index c0251fb..43d23cf 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 LOGGER = Logging.getLogger(); + private static final Logger log = 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 - LOGGER.info("Bot connected as {}", jda.getSelfUser().getAsTag()); - LOGGER.info("The bot is present on these guilds :"); + log.info("Bot connected as {}", jda.getSelfUser().getAsTag()); + log.info("The bot is present in the following guilds:"); for (Guild guild : jda.getGuildCache()) { - LOGGER.info("\t- {} ({})", guild.getName(), guild.getId()); + log.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) { - LOGGER.error("Unable to start the bot", e); + log.error("Failed 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 2568523..330cb46 100644 --- a/src/main/java/net/hypr/doki/listeners/LevellingListener.java +++ b/src/main/java/net/hypr/doki/listeners/LevellingListener.java @@ -64,7 +64,8 @@ public class LevellingListener extends ListenerAdapter { } else { log.info("No record of user ID {} in server {}, creating blank record", user.getId(), guild.getId()); try { - DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName()); + UserRecord rec = DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName()); + LevellingUtils.incrementXp(log, rec); } 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 7825b2a..48f04fc 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 void createUserRecord(long user_id, long server_id, String username) throws SQLException { + public static UserRecord 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,6 +67,7 @@ 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 new file mode 100644 index 0000000..f185663 --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: net.hypr.doki.Doki +