Compare commits
No commits in common. "c3272ad9aca03c8e77f714497748a0211ec3eaf5" and "448f98ba354ba62b3a1057081f5b5a74ca161cfc" have entirely different histories.
c3272ad9ac
...
448f98ba35
7 changed files with 16 additions and 68 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,4 @@
|
||||||
target/
|
target/
|
||||||
out/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
<component name="ArtifactManager">
|
|
||||||
<artifact type="jar" name="doki:jar">
|
|
||||||
<output-path>$PROJECT_DIR$/out/artifacts/doki_jar</output-path>
|
|
||||||
<root id="archive" name="doki.jar">
|
|
||||||
<element id="module-output" name="doki" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/commons/commons-dbcp2/2.12.0/commons-dbcp2-2.12.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.17.0/jackson-core-2.17.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.3.0/commons-logging-1.3.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.21/kotlin-stdlib-jdk8-1.8.21.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.17.0/jackson-annotations-2.17.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/ben-manes/caffeine/caffeine/3.1.5/caffeine-3.1.5.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/okio/okio/3.6.0/okio-3.6.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/io/github/freya022/BotCommands/2.10.4/BotCommands-2.10.4.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/io/github/classgraph/classgraph/4.8.157/classgraph-4.8.157.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.17.0/jackson-databind-2.17.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/club/minnced/opus-java-api/1.1.1/opus-java-api-1.1.1.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/ch/qos/logback/logback-classic/1.5.6/logback-classic-1.5.6.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/net/sf/trove4j/core/3.1.0/core-3.1.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/jakarta/transaction/jakarta.transaction-api/1.3.3/jakarta.transaction-api-1.3.3.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.8.21/kotlin-stdlib-1.8.21.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/minndevelopment/emoji-java/5622646ccb/emoji-java-5622646ccb.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.12.0/commons-pool2-2.12.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/net/dv8tion/JDA/5.0.1/JDA-5.0.1.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/me/xdrop/fuzzywuzzy/1.4.0/fuzzywuzzy-1.4.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/checkerframework/checker-qual/3.32.0/checker-qual-3.32.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/json/json/20231013/json-20231013.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.18.0/error_prone_annotations-2.18.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/mariadb/jdbc/mariadb-java-client/2.1.2/mariadb-java-client-2.1.2.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.10/kotlin-stdlib-common-1.9.10.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/net/bytebuddy/byte-buddy/1.14.9/byte-buddy-1.14.9.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/neovisionaries/nv-websocket-client/2.14/nv-websocket-client-2.14.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/okhttp3/okhttp/4.12.0/okhttp-4.12.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/commons-dbutils/commons-dbutils/1.8.1/commons-dbutils-1.8.1.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.21/kotlin-stdlib-jdk7-1.8.21.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/squareup/okio/okio-jvm/3.6.0/okio-jvm-3.6.0.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/club/minnced/opus-java/1.1.1/opus-java-1.1.1.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/club/minnced/opus-java-natives/1.1.1/opus-java-natives-1.1.1.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/ch/qos/logback/logback-core/1.5.6/logback-core-1.5.6.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/2.0.13/slf4j-api-2.0.13.jar" path-in-jar="/" />
|
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar" path-in-jar="/" />
|
|
||||||
</root>
|
|
||||||
</artifact>
|
|
||||||
</component>
|
|
|
@ -1,14 +1,12 @@
|
||||||
package net.hypr.doki;
|
package net.hypr.doki;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.Logging;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
//You can add more fields in this class, if your input json matches the structure
|
//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 {
|
public class Config {
|
||||||
@SuppressWarnings("unused") private String token;
|
@SuppressWarnings("unused") private String token;
|
||||||
@SuppressWarnings("unused") private String prefix;
|
@SuppressWarnings("unused") private String prefix;
|
||||||
|
@ -21,15 +19,19 @@ public class Config {
|
||||||
* @throws IOException if the config JSON could not be read
|
* @throws IOException if the config JSON could not be read
|
||||||
*/
|
*/
|
||||||
public static Config readConfig() throws IOException {
|
public static Config readConfig() throws IOException {
|
||||||
Logger log = Logging.getLogger();
|
|
||||||
try (InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json")) {
|
try (InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json")) {
|
||||||
assert in != null;
|
assert in != null;
|
||||||
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
|
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
|
||||||
log.info("Loaded config");
|
|
||||||
return new Gson().fromJson(reader, Config.class);
|
return new Gson().fromJson(reader, Config.class);
|
||||||
} catch (IOException | NullPointerException e) {
|
} catch (IOException | NullPointerException e) {
|
||||||
log.error("Failed to load config.json, does the file exist?");
|
throw new IOException("""
|
||||||
throw new IOException(e);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.slf4j.Logger;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Doki {
|
public class Doki {
|
||||||
private static final Logger log = Logging.getLogger();
|
private static final Logger LOGGER = Logging.getLogger();
|
||||||
private static JDA jda;
|
private static JDA jda;
|
||||||
private static Config config;
|
private static Config config;
|
||||||
private static final BasicDataSource dataSource = new BasicDataSource();
|
private static final BasicDataSource dataSource = new BasicDataSource();
|
||||||
|
@ -50,10 +50,10 @@ public class Doki {
|
||||||
dataSource.setInitialSize(10);
|
dataSource.setInitialSize(10);
|
||||||
|
|
||||||
//Print some information about the bot
|
//Print some information about the bot
|
||||||
log.info("Bot connected as {}", jda.getSelfUser().getAsTag());
|
LOGGER.info("Bot connected as {}", jda.getSelfUser().getAsTag());
|
||||||
log.info("The bot is present in the following guilds:");
|
LOGGER.info("The bot is present on these guilds :");
|
||||||
for (Guild guild : jda.getGuildCache()) {
|
for (Guild guild : jda.getGuildCache()) {
|
||||||
log.info("\t- {} ({})", guild.getName(), guild.getId());
|
LOGGER.info("\t- {} ({})", guild.getName(), guild.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
new Doki(jda, config);
|
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
|
.build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib
|
||||||
jda.addEventListener(new LevellingListener());
|
jda.addEventListener(new LevellingListener());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to start the bot", e);
|
LOGGER.error("Unable to start the bot", e);
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +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());
|
DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName());
|
||||||
LevellingUtils.incrementXp(log, rec);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class DBUtils {
|
||||||
* @param username The users username
|
* @param username The users username
|
||||||
* @throws SQLException A SQL exception
|
* @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();
|
Logger log = Logging.getLogger();
|
||||||
log.info("Creating record (usr:{},srv:{},unm:{})", user_id, server_id, username);
|
log.info("Creating record (usr:{},srv:{},unm:{})", user_id, server_id, username);
|
||||||
BasicDataSource dataSource = Doki.getDataSource();
|
BasicDataSource dataSource = Doki.getDataSource();
|
||||||
|
@ -67,7 +67,6 @@ public class DBUtils {
|
||||||
stmt.setTimestamp(4, Timestamp.valueOf(LocalDateTime.now()));
|
stmt.setTimestamp(4, Timestamp.valueOf(LocalDateTime.now()));
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
log.info("Record (usr:{},srv:{},unm:{}) created!", user_id, server_id, username);
|
log.info("Record (usr:{},srv:{},unm:{}) created!", user_id, server_id, username);
|
||||||
return new UserRecord(user_id, server_id, username);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: net.hypr.doki.Doki
|
|
||||||
|
|
Loading…
Reference in a new issue