Compare commits
	
		
			5 commits
		
	
	
		
			
				448f98ba35
			
			...
			
				c3272ad9ac
			
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						
							
							
								
							
							
	
	
	c3272ad9ac | 
						
						
							||
| 
							 | 
						
							
							
								
							
							
	
	
	319eefbd2a | 
						
						
							||
| 
							 | 
						
							
							
								
							
							
	
	
	9b3b3ef320 | 
						
						
							||
| 
							 | 
						
							
							
								
							
							
	
	
	3001616fcb | 
						
						
							||
| 
							 | 
						
							
							
								
							
							
	
	
	1a196d9fb3 | 
						
						
							
					 7 changed files with 68 additions and 16 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
target/
 | 
			
		||||
out/
 | 
			
		||||
!.mvn/wrapper/maven-wrapper.jar
 | 
			
		||||
!**/src/main/**/target/
 | 
			
		||||
!**/src/test/**/target/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										48
									
								
								.idea/artifacts/doki_jar.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								.idea/artifacts/doki_jar.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,48 @@
 | 
			
		|||
<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,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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								src/main/resources/META-INF/MANIFEST.MF
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/main/resources/META-INF/MANIFEST.MF
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
Manifest-Version: 1.0
 | 
			
		||||
Main-Class: net.hypr.doki.Doki
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue