started MySQL implementation

master
BodgeMaster 2022-02-21 12:35:35 +01:00
parent 75b9530029
commit b7b6c2bda9
3 changed files with 31 additions and 6 deletions

View File

@ -12,6 +12,12 @@
<version>3.4.0</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>

View File

@ -8,23 +8,24 @@ import java.util.Date;
import java.util.Scanner;
public class Main {
public static final String startupTime = String.format("%1$tY-%1$tm-%1$td %1$tI:%1$tM:%1$tS%1$tp UTC%1$tz", new Date());
private static String[] commandLineArguments;
public static void main(String[] args) {
String startupTime = String.format("%1$tY-%1$tm-%1$td %1$tI:%1$tM:%1$tS%1$tp UTC%1$tz", new Date());
// [0] token, [1] db username, [2] db password
commandLineArguments = args;
String token = args[0];
String db_username = args[1];
String db_password = args[2];
String db_name = "quizbot";
// CREATE TABLE questions(id INT(32) AUTO_INCREMENT PRIMARY KEY, question TEXT, max_score INT(8));
// CREATE TABLE answer_coices(id INT(32), answer VARCHAR(2048), correctness BOOLEAN);
// CREATE TABLE user_answers(id INT(32), given_answer VARCHAR(2048), discord_user VARCHAR(1024));
// CREATE TABLE categories(id INT(32), category VARCHAR(1024));
// checks every 7500 ms if a deployment happened, if so shuts down the bot
CheckDeploy check = new CheckDeploy(7500, "/var/www/deployment/Hacky-Quizbot/id.txt");
check.start();
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
DiscordApi api = new DiscordApiBuilder().setToken(commandLineArguments[0]).login().join();
//Trivia management
Member member = new Member(api);
@ -37,6 +38,10 @@ public class Main {
});
}
public static String getCommandLineArgument(int index) {
return commandLineArguments[index];
}
//Deploy check thread
public static class CheckDeploy extends Thread {

View File

@ -1,13 +1,27 @@
package linux.general.hackyquizbot;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
public class QuizBackend {
private static final String dbUsername = Main.getCommandLineArgument(1);
private static final String dbPassword = Main.getCommandLineArgument(2);
private static final String dbName = "jdbc:mysql://localhost:3306/quizbot"; //we can make this configurable later
private static Question[] allQuestions;
private static String[] categories;
static {
try (Connection connection = DriverManager.getConnection(dbName, dbUsername, dbPassword)) {
System.out.println("Database connected!");
}
catch (SQLException e) {
System.err.println("Could not connect to DB.");
e.printStackTrace();
}
//TODO: populate allQuestions
//TODO: populate categories
}