more worky
This commit is contained in:
@@ -3,4 +3,13 @@ package tech.allydoes;
|
||||
public class Constants {
|
||||
public static final boolean PRODUCTION = true;
|
||||
public static final String TESTING_GUILD = "926369143186403329";
|
||||
|
||||
public static final String BOT_TOKEN = "MTU0MjMzMDM2OTc1MDMzOTcwNQ.G3V2nZ.JHs0uiA_naF4XW2sJOXsokoVMB9koRKIRtzrr8";
|
||||
public static final String TESTING_TOKEN = "MTEzMTIzNzM2ODA2Njc0MDMyNA.GsjDqa.aS5Rrvo-JMHF5tUnOXOUqPCsUWONNcF8H7Dp7c";
|
||||
|
||||
public static final String DB_USER = "postgres";
|
||||
public static final String DB_PASSWORD = "Senator46Aqua6Outward6Resolved6Bargraph6Dotted";
|
||||
public static final String DB_HOST = "localhost";
|
||||
public static final String DB_PORT = "5432";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package tech.allydoes;
|
||||
|
||||
import io.github.cdimascio.dotenv.Dotenv;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
|
||||
@@ -1,28 +1,22 @@
|
||||
package tech.allydoes.database;
|
||||
|
||||
import io.github.cdimascio.dotenv.Dotenv;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import tech.allydoes.Constants;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DatabaseManager {
|
||||
private final Logger LOGGER = LogManager.getLogger(DatabaseManager.class);
|
||||
private final Dotenv dotenv = Dotenv.load();
|
||||
|
||||
public DatabaseManager() {
|
||||
initializeDatabase();
|
||||
}
|
||||
|
||||
private void initializeDatabase() {
|
||||
String user = dotenv.get("DB_USER");
|
||||
String password = dotenv.get("DB_PASSWORD");
|
||||
String host = dotenv.get("DB_HOST");
|
||||
String port = dotenv.get("DB_PORT");
|
||||
|
||||
String defaultDbUrl = String.format("jdbc:postgresql://%s:%s/postgres", host, port);
|
||||
try (Connection conn = DriverManager.getConnection(defaultDbUrl, user, password)) {
|
||||
String defaultDbUrl = String.format("jdbc:postgresql://%s:%s/postgres", Constants.DB_HOST, Constants.DB_PORT);
|
||||
try (Connection conn = DriverManager.getConnection(defaultDbUrl, Constants.DB_USER, Constants.DB_PASSWORD)) {
|
||||
conn.setAutoCommit(true);
|
||||
boolean dbExists = false;
|
||||
|
||||
@@ -49,8 +43,8 @@ public class DatabaseManager {
|
||||
LOGGER.error("Database initialization failed on default DB: {}", e.getMessage());
|
||||
}
|
||||
|
||||
String notifierDbUrl = String.format("jdbc:postgresql://%s:%s/notifier", host, port);
|
||||
try (Connection conn = DriverManager.getConnection(notifierDbUrl, user, password)) {
|
||||
String notifierDbUrl = String.format("jdbc:postgresql://%s:%s/notifier", Constants.DB_HOST, Constants.DB_PORT);
|
||||
try (Connection conn = DriverManager.getConnection(notifierDbUrl, Constants.DB_USER, Constants.DB_PASSWORD)) {
|
||||
try (Statement statement = conn.createStatement()) {
|
||||
statement.executeUpdate(Queries.CREATE_SERVER_TABLE);
|
||||
LOGGER.debug("Server table verified/created successfully.");
|
||||
@@ -63,14 +57,9 @@ public class DatabaseManager {
|
||||
}
|
||||
|
||||
public ArrayList<Notified> getAllNotifiers() {
|
||||
String user = dotenv.get("DB_USER");
|
||||
String password = dotenv.get("DB_PASSWORD");
|
||||
String host = dotenv.get("DB_HOST");
|
||||
String port = dotenv.get("DB_PORT");
|
||||
|
||||
ArrayList<Notified> notified = new ArrayList<>();
|
||||
String defaultDbUrl = String.format("jdbc:postgresql://%s:%s/notifier", host, port);
|
||||
try (Connection conn = DriverManager.getConnection(defaultDbUrl, user, password)) {
|
||||
String defaultDbUrl = String.format("jdbc:postgresql://%s:%s/notifier", Constants.DB_HOST, Constants.DB_PORT);
|
||||
try (Connection conn = DriverManager.getConnection(defaultDbUrl, Constants.DB_USER, Constants.DB_PASSWORD)) {
|
||||
conn.setAutoCommit(true);
|
||||
|
||||
try (Statement statement = conn.createStatement()) {
|
||||
@@ -92,13 +81,8 @@ public class DatabaseManager {
|
||||
}
|
||||
|
||||
public void putNotifier(String guildId, String channelId, String messageId) {
|
||||
String user = dotenv.get("DB_USER");
|
||||
String password = dotenv.get("DB_PASSWORD");
|
||||
String host = dotenv.get("DB_HOST");
|
||||
String port = dotenv.get("DB_PORT");
|
||||
|
||||
String defaultDbUrl = String.format("jdbc:postgresql://%s:%s/notifier", host, port);
|
||||
try (Connection conn = DriverManager.getConnection(defaultDbUrl, user, password)) {
|
||||
String defaultDbUrl = String.format("jdbc:postgresql://%s:%s/notifier", Constants.DB_HOST, Constants.DB_PORT);
|
||||
try (Connection conn = DriverManager.getConnection(defaultDbUrl, Constants.DB_USER, Constants.DB_PASSWORD)) {
|
||||
conn.setAutoCommit(true);
|
||||
|
||||
try (PreparedStatement preparedStatement = conn.prepareStatement(Queries.INSERT_SERVER_CHANNEL)) {
|
||||
@@ -115,13 +99,8 @@ public class DatabaseManager {
|
||||
}
|
||||
|
||||
public void deleteNotifier(String guildId) {
|
||||
String user = dotenv.get("DB_USER");
|
||||
String password = dotenv.get("DB_PASSWORD");
|
||||
String host = dotenv.get("DB_HOST");
|
||||
String port = dotenv.get("DB_PORT");
|
||||
|
||||
String defaultDbUrl = String.format("jdbc:postgresql://%s:%s/notifier", host, port);
|
||||
try (Connection conn = DriverManager.getConnection(defaultDbUrl, user, password)) {
|
||||
String defaultDbUrl = String.format("jdbc:postgresql://%s:%s/notifier", Constants.DB_HOST, Constants.DB_PORT);
|
||||
try (Connection conn = DriverManager.getConnection(defaultDbUrl, Constants.DB_USER, Constants.DB_PASSWORD)) {
|
||||
conn.setAutoCommit(true);
|
||||
|
||||
try (PreparedStatement preparedStatement = conn.prepareStatement(Queries.DELETE_SERVER_CHANNEL)) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package tech.allydoes.discord;
|
||||
|
||||
import io.github.cdimascio.dotenv.Dotenv;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
@@ -23,14 +22,13 @@ public class DiscordManager {
|
||||
public final Logger LOGGER;
|
||||
private final JDA jda;
|
||||
private final HashMap<String, Command> commands;
|
||||
private final Dotenv dotenv = Dotenv.load();
|
||||
|
||||
public DiscordManager() throws InterruptedException {
|
||||
LOGGER = LogManager.getLogger(DiscordManager.class);
|
||||
commands = new HashMap<>();
|
||||
commands.put("savechannel", new SaveChannelCommand());
|
||||
|
||||
String botToken = Constants.PRODUCTION ? dotenv.get("DISCORD_TOKEN") : dotenv.get("TESTING_TOKEN");
|
||||
String botToken = Constants.PRODUCTION ? Constants.BOT_TOKEN : Constants.TESTING_TOKEN;
|
||||
jda = JDABuilder
|
||||
.create(botToken, GatewayIntent.GUILD_MESSAGES)
|
||||
.addEventListeners(new SlashCommandInteractionListener())
|
||||
|
||||
@@ -7,7 +7,6 @@ import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import tech.allydoes.Main;
|
||||
import tech.allydoes.discord.DiscordManager;
|
||||
import tech.allydoes.web.HttpServerHandler;
|
||||
import tech.allydoes.web.RequestHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
Reference in New Issue
Block a user