CI Test
This commit is contained in:
		
							parent
							
								
									7deb3dabc7
								
							
						
					
					
						commit
						d2b6e0de80
					
				
							
								
								
									
										12
									
								
								.idea/dataSources.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								.idea/dataSources.xml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
 | 
			
		||||
    <data-source source="LOCAL" name="Buzzbot - Controller" uuid="f2f3d0fe-a522-464a-9bef-16ab03af762c">
 | 
			
		||||
      <driver-ref>mysql.8</driver-ref>
 | 
			
		||||
      <synchronize>true</synchronize>
 | 
			
		||||
      <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
 | 
			
		||||
      <jdbc-url>jdbc:mysql://10.69.0.2:3306/buzzbot</jdbc-url>
 | 
			
		||||
      <working-dir>$ProjectFileDir$</working-dir>
 | 
			
		||||
    </data-source>
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										7
									
								
								.idea/sqldialects.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								.idea/sqldialects.xml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="SqlDialectMappings">
 | 
			
		||||
    <file url="file://$PROJECT_DIR$/src/main/java/net/nevet5/buzzbot/database/SqlDB.java" dialect="GenericSQL" />
 | 
			
		||||
    <file url="PROJECT" dialect="MySQL" />
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
@ -30,6 +30,7 @@ dependencies {
 | 
			
		||||
    implementation group: 'me.duncte123', name: 'botCommons', version: '2.3.8'
 | 
			
		||||
    implementation 'com.google.code.gson:gson:2.9.0'
 | 
			
		||||
    implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.2'
 | 
			
		||||
    implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.28'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
compileJava.options.encoding = 'UTF-8'
 | 
			
		||||
@ -3,6 +3,8 @@ package net.nevet5.buzzbot;
 | 
			
		||||
import org.simpleyaml.configuration.file.YamlFile;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class Config {
 | 
			
		||||
    private static final YamlFile YML_FILE = new YamlFile("./config.yml");
 | 
			
		||||
@ -14,10 +16,6 @@ public class Config {
 | 
			
		||||
                System.out.println("Config file not found, creating new one...");
 | 
			
		||||
                YML_FILE.createNewFile(true);
 | 
			
		||||
                System.out.println("Config file created!");
 | 
			
		||||
//                YML_FILE.addDefault("bot.token", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
 | 
			
		||||
//                YML_FILE.addDefault("bot.prefix", "!");
 | 
			
		||||
//                YML_FILE.set("bot.token", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
 | 
			
		||||
//                YML_FILE.set("bot.prefix", "!");
 | 
			
		||||
            } else {
 | 
			
		||||
                System.out.println("Loading Config file...");
 | 
			
		||||
                YML_FILE.loadWithComments();
 | 
			
		||||
@ -28,10 +26,15 @@ public class Config {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        YML_FILE.addDefault("bot.token", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
 | 
			
		||||
        YML_FILE.addDefault("bot.prefix", "!");
 | 
			
		||||
        YML_FILE.addDefault("bot.activity", "playing");
 | 
			
		||||
        YML_FILE.addDefault("bot.action", "with myself");
 | 
			
		||||
        YML_FILE.addDefault("database.url", "localhost");
 | 
			
		||||
        YML_FILE.addDefault("database.user", "barry");
 | 
			
		||||
        YML_FILE.addDefault("database.password", "benson");
 | 
			
		||||
        YML_FILE.addDefault("database.database", "buzzbot");
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            YML_FILE.save();
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								src/main/java/net/nevet5/buzzbot/Test.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/main/java/net/nevet5/buzzbot/Test.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
package net.nevet5.buzzbot;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalTime;
 | 
			
		||||
 | 
			
		||||
public class Test {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										188
									
								
								src/main/java/net/nevet5/buzzbot/database/SqlDB.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										188
									
								
								src/main/java/net/nevet5/buzzbot/database/SqlDB.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,188 @@
 | 
			
		||||
package net.nevet5.buzzbot.database;
 | 
			
		||||
 | 
			
		||||
import net.nevet5.buzzbot.Config;
 | 
			
		||||
 | 
			
		||||
import java.sql.*;
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
import java.time.LocalTime;
 | 
			
		||||
 | 
			
		||||
public class SqlDB {
 | 
			
		||||
    //TODO Make this a two way class for reading and writing from db
 | 
			
		||||
    
 | 
			
		||||
    private int userId;
 | 
			
		||||
    private String userName;
 | 
			
		||||
    private int userDiscriminator;
 | 
			
		||||
    private String date = LocalDate.now().toString();
 | 
			
		||||
    private String time = LocalTime.now().toString().split("\\.")[0];
 | 
			
		||||
    private boolean banType;
 | 
			
		||||
    private int banLength;
 | 
			
		||||
    private String banReason;
 | 
			
		||||
    private String modName;
 | 
			
		||||
    private int modId;
 | 
			
		||||
    private String serverName;
 | 
			
		||||
    private int serverId;
 | 
			
		||||
 | 
			
		||||
    private Connection connect;
 | 
			
		||||
    private Statement statement;
 | 
			
		||||
    private PreparedStatement preparedStatement;
 | 
			
		||||
    private ResultSet resultSet;
 | 
			
		||||
 | 
			
		||||
    public SqlDB() {
 | 
			
		||||
        try {
 | 
			
		||||
            Class.forName("com.mysql.jdbc.Driver");
 | 
			
		||||
            connect = DriverManager.getConnection("jdbc:mysql://" + Config.getConfig().getString("database.url") + "/" + Config.getConfig().getString("database.database") + "?user=" + Config.getConfig().getString("database.user") + "&password=" + Config.getConfig().getString("database.password"));
 | 
			
		||||
            statement = connect.createStatement();
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void readDatabase() {
 | 
			
		||||
        try {
 | 
			
		||||
            Class.forName("com.mysql.jdbc.Driver");
 | 
			
		||||
 | 
			
		||||
            connect = DriverManager.getConnection("jdbc:mysql://" + Config.getConfig().getString("database.url") + "/" + Config.getConfig().getString("database.database") + "?user=" + Config.getConfig().getString("database.user") + "&password=" + Config.getConfig().getString("database.password"));
 | 
			
		||||
 | 
			
		||||
            statement = connect.createStatement();
 | 
			
		||||
 | 
			
		||||
            resultSet = statement
 | 
			
		||||
                    .executeQuery("SELECT * FROM masterbanlist");
 | 
			
		||||
        } catch (ClassNotFoundException | SQLException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void insert() {
 | 
			
		||||
        try {
 | 
			
		||||
            statement = connect.createStatement();
 | 
			
		||||
 | 
			
		||||
            resultSet = statement.executeQuery("INSERT INTO " + Config.getConfig().getString("database.database") + " VALUES (default, " + userId + ", '" + userName + "', '" + userDiscriminator + "', '" + date + "', '" + time + "', " + banType + ", " + banLength + ", '" + banReason + "', '" + modName + "', " + modId + ", '" + serverName + "', " + serverId + ");");
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void writeResultSet(ResultSet resultSet) throws SQLException {
 | 
			
		||||
        while (resultSet.next()) {
 | 
			
		||||
            userId = resultSet.getInt("userid");
 | 
			
		||||
            userName = resultSet.getString("username");
 | 
			
		||||
            userDiscriminator = resultSet.getInt("userdiscriminator");
 | 
			
		||||
//            date;
 | 
			
		||||
//            time;
 | 
			
		||||
//            banType;
 | 
			
		||||
//            banLength;
 | 
			
		||||
//            banReason;
 | 
			
		||||
//            modName;
 | 
			
		||||
//            modId;
 | 
			
		||||
//            serverName;
 | 
			
		||||
//            serverId;
 | 
			
		||||
 | 
			
		||||
            String user = resultSet.getString("myuser");
 | 
			
		||||
            String website = resultSet.getString("webpage");
 | 
			
		||||
            String summary = resultSet.getString("summary");
 | 
			
		||||
            Date date = resultSet.getDate("datum");
 | 
			
		||||
            String comment = resultSet.getString("comments");
 | 
			
		||||
            System.out.println("User: " + user);
 | 
			
		||||
            System.out.println("Website: " + website);
 | 
			
		||||
            System.out.println("summary: " + summary);
 | 
			
		||||
            System.out.println("Date: " + date);
 | 
			
		||||
            System.out.println("Comment: " + comment);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUserId(int userId) {
 | 
			
		||||
        this.userId = userId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getUserId() {
 | 
			
		||||
        return userId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUserName(String userName) {
 | 
			
		||||
        this.userName = userName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getUserName() {
 | 
			
		||||
        return userName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUserDiscriminator(int userDiscriminator) {
 | 
			
		||||
        this.userDiscriminator = userDiscriminator;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getUserDiscriminator() {
 | 
			
		||||
        return userDiscriminator;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDate(String date) {
 | 
			
		||||
        this.date = date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getDate() {
 | 
			
		||||
        return date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTime(String time) {
 | 
			
		||||
        this.time = time;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getTime() {
 | 
			
		||||
        return time;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBanType(boolean banType) {
 | 
			
		||||
        this.banType = banType;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean getBanType() {
 | 
			
		||||
        return banType;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBanLength(int banLength) {
 | 
			
		||||
        this.banLength = banLength;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getBanLength() {
 | 
			
		||||
        return banLength;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBanReason(String banReason) {
 | 
			
		||||
        this.banReason = banReason;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getBanReason() {
 | 
			
		||||
        return banReason;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setModName(String modName) {
 | 
			
		||||
        this.modName = modName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getModName() {
 | 
			
		||||
        return modName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setModId(int modId) {
 | 
			
		||||
        this.modId = modId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getModId() {
 | 
			
		||||
        return modId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setServerName(String serverName) {
 | 
			
		||||
        this.serverName = serverName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getServerName() {
 | 
			
		||||
        return serverName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setServerId(int serverId) {
 | 
			
		||||
        this.serverId = serverId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getServerId() {
 | 
			
		||||
        return serverId;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user