Updated dependencies and added file for basic settings

This commit is contained in:
anthorob committed 2021-09-10 18:37:06 -04:00
1 parent 7e7a0b1b89
commit b0dcc1d334
6 files changed
+87 -44

No files matched your search

+8 -6
View File
@@ -26,10 +26,11 @@ public class MusicBot {
public static void main(String[] args) {
System.setProperty("log4j.skipJansi", "false");
Settings.init();
DBController.init();
try {
jda = new JDABuilder(AccountType.BOT).setToken(Settings.TOKEN).build();
jda = JDABuilder.createDefault(Settings.TOKEN).build();
jda.awaitReady();
} catch (LoginException | IllegalArgumentException e) {
LogHandler.log(e);
@@ -42,8 +43,7 @@ public class MusicBot {
jda.addEventListener(new NewCommandListener(), new EditHandler());
// WebApi webserver = new WebApi();
jda.getPresence().setActivity(Activity.watching("rape"));
jda.getPresence().setActivity(Activity.watching("you"));
ConsoleHandler consoleInput = new ConsoleHandler();
@@ -61,9 +61,9 @@ public class MusicBot {
public static void shutdown() {
LOGGER.info("[Net Neutrality] Shutting down...");
MusicManager.disconnectPlayers();
ThreadManager.shutdownExecutor();
disconnect();
DBController.shutdown();
ThreadManager.shutdownExecutor();
LOGGER.info("[Net Neutrality] Shutdown complete");
System.exit(0);
}
@@ -73,8 +73,10 @@ public class MusicBot {
}
public static void disconnect() {
if (jda != null)
jda.shutdown();
if (jda != null) {
jda.shutdownNow();
}
}
+15 -3
View File
@@ -17,10 +17,13 @@ public class ThreadManager {
public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
public static void shutdownExecutor() {
MusicBot.LOGGER.info("[Executor] Shutting down...");
try {
MusicBot.LOGGER.info("[Executor] Shutting down...");
executor.shutdown();
scheduler.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS);
scheduler.awaitTermination(5, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
MusicBot.LOGGER.warn("[Executor] Running tasks interrupted");
@@ -28,9 +31,18 @@ public class ThreadManager {
finally {
if (!executor.isTerminated()) {
MusicBot.LOGGER.warn("[Executor] Forcing shutdown of running tasks..");
executor.shutdownNow();
}
executor.shutdownNow();
MusicBot.LOGGER.info("[Executor] Shutdown finished!");
if (!scheduler.isTerminated()) {
MusicBot.LOGGER.warn("[Executor] Forcing shutdown of running tasks..");
scheduler.shutdownNow();
}
}
MusicBot.LOGGER.info("[Executor] Shutdown finished!");
}
}
@@ -117,6 +117,7 @@ public class MysqlDatabase {
private int executeUpdate(String sql, Object[] params) {
try {
PreparedStatement query = connection.prepareStatement(sql);
resolveParameters(query, params);
@@ -142,7 +143,8 @@ public class MysqlDatabase {
try {
PreparedStatement query = connection.prepareStatement(sql);
resolveParameters(query, params);
return query.executeQuery();
ResultSet rs = query.executeQuery();
return rs;
} catch (SQLException e) {
MusicBot.LOGGER.error(e.toString());
e.printStackTrace();
+31 -14
View File
@@ -7,23 +7,40 @@ import netneutrality.MusicBot;
import netneutrality.db.DBController;
import netneutrality.db.controllers.DBSettings;
import java.io.*;
import java.util.Properties;
public class Settings {
public static final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss";
public static String PREFIX = ((DBSettings) DBController.get("settings")).getSettingsByKey("prefix");
public static final String TOKEN = ((DBSettings) DBController.get("settings")).getSettingsByKey("token");
static Properties prop = new Properties();
static String configFile = "bot.config";
public static User getCreator() {
return MusicBot.getJDA().getUserById(((DBSettings) DBController.get("settings")).getSettingsByKey("owner"));
}
public static void init() {
InputStream is = Settings.class.getClassLoader().getResourceAsStream(configFile);
try (FileInputStream fis = new FileInputStream(configFile)) {
prop.load(fis);
} catch (IOException ignored) {
}
}
public static final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss";
public static String PREFIX = prop.getProperty("bot.prefix");
public static final String TOKEN = prop.getProperty("bot.token");
public static User getCreator() {
return MusicBot.getJDA().getUserById(prop.getProperty("bot.owner"));
}
public static Guild getOwnerGuild() {
return MusicBot.getJDA().getGuildById(prop.getProperty("bot.ownerguild"));
}
public static TextChannel getLogChannel() {
return MusicBot.getJDA().getTextChannelById(prop.getProperty("bot.errorchannel"));
}
public static Guild getOwnerGuild() {
return MusicBot.getJDA().getGuildById(((DBSettings) DBController.get("settings")).getSettingsByKey("ownerguild"));
}
public static TextChannel getLogChannel() {
return MusicBot.getJDA().getTextChannelById(((DBSettings) DBController.get("settings")).getSettingsByKey("errorchannel"));
}
}
+5
View File
@@ -0,0 +1,5 @@
bot.token=""
bot.prefix="$"
bot.owner=""
bot.ownerguild=""
bot.errorchannel=""