This commit is contained in:
2022-04-25 20:00:40 -04:00
parent 7deb3dabc7
commit d2b6e0de80
6 changed files with 224 additions and 4 deletions

View File

@@ -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();
@@ -27,11 +25,16 @@ public class Config {
System.out.println("Error while loading config file!");
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();

View File

@@ -0,0 +1,9 @@
package net.nevet5.buzzbot;
import java.time.LocalTime;
public class Test {
public static void main(String[] args) {
}
}

View 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;
}
}