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
+78 -35

No files matched your search

+25 -20
View File
@@ -3,22 +3,27 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.xtremcommunity.discord</groupId> <groupId>com.xtremcommunity.discord</groupId>
<artifactId>netneutrality</artifactId> <artifactId>netneutrality</artifactId>
<version>0.0.1</version> <version>1.0.0</version>
<name>MusicBot</name> <name>netneutrality-discord-bot</name>
<description>Music bot</description> <description>Discord bot</description>
<packaging>jar</packaging>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.11</maven.compiler.target>
</properties> </properties>
<distributionManagement>
<downloadUrl>https://gitlab.xtremcommunity.com/nn.jar</downloadUrl>
</distributionManagement>
<repositories> <repositories>
<repository> <!-- This repo fixes issues with transitive dependencies --> <repository> <!-- This repo fixes issues with transitive dependencies -->
<id>jcenter</id> <id>central</id>
<url>http://jcenter.bintray.com</url> <url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository> </repository>
</repositories> </repositories>
@@ -27,27 +32,27 @@
<dependency> <dependency>
<groupId>net.dv8tion</groupId> <groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId> <artifactId>JDA</artifactId>
<version>4.1.0_81</version> <version>4.3.0_277</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId> <artifactId>okhttp</artifactId>
<version>3.13.0</version> <version>4.9.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.json/json --> <!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20180813</version> <version>20210307</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.reflections</groupId> <groupId>org.reflections</groupId>
<artifactId>reflections</artifactId> <artifactId>reflections</artifactId>
<version>0.9.11</version> <version>0.9.12</version>
</dependency> </dependency>
<dependency> <dependency>
@@ -58,33 +63,33 @@
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-api</artifactId>
<version>2.10.0</version> <version>2.14.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
<version>2.10.0</version> <version>2.14.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId> <artifactId>log4j-slf4j-impl</artifactId>
<version>2.10.0</version> <version>2.14.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.fusesource.jansi</groupId> <groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId> <artifactId>jansi</artifactId>
<version>1.17</version> <version>2.3.4</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sedmelluq</groupId> <groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId> <artifactId>lavaplayer</artifactId>
<version>1.3.33</version> <version>1.3.77</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>RELEASE</version> <version>4.13.2</version>
</dependency> </dependency>
</dependencies> </dependencies>
+8 -6
View File
@@ -26,10 +26,11 @@ public class MusicBot {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("log4j.skipJansi", "false"); System.setProperty("log4j.skipJansi", "false");
Settings.init();
DBController.init(); DBController.init();
try { try {
jda = new JDABuilder(AccountType.BOT).setToken(Settings.TOKEN).build(); jda = JDABuilder.createDefault(Settings.TOKEN).build();
jda.awaitReady(); jda.awaitReady();
} catch (LoginException | IllegalArgumentException e) { } catch (LoginException | IllegalArgumentException e) {
LogHandler.log(e); LogHandler.log(e);
@@ -42,8 +43,7 @@ public class MusicBot {
jda.addEventListener(new NewCommandListener(), new EditHandler()); jda.addEventListener(new NewCommandListener(), new EditHandler());
// WebApi webserver = new WebApi(); // WebApi webserver = new WebApi();
jda.getPresence().setActivity(Activity.watching("you"));
jda.getPresence().setActivity(Activity.watching("rape"));
ConsoleHandler consoleInput = new ConsoleHandler(); ConsoleHandler consoleInput = new ConsoleHandler();
@@ -61,9 +61,9 @@ public class MusicBot {
public static void shutdown() { public static void shutdown() {
LOGGER.info("[Net Neutrality] Shutting down..."); LOGGER.info("[Net Neutrality] Shutting down...");
MusicManager.disconnectPlayers(); MusicManager.disconnectPlayers();
ThreadManager.shutdownExecutor();
disconnect(); disconnect();
DBController.shutdown(); DBController.shutdown();
ThreadManager.shutdownExecutor();
LOGGER.info("[Net Neutrality] Shutdown complete"); LOGGER.info("[Net Neutrality] Shutdown complete");
System.exit(0); System.exit(0);
} }
@@ -73,8 +73,10 @@ public class MusicBot {
} }
public static void disconnect() { public static void disconnect() {
if (jda != null) if (jda != null) {
jda.shutdown(); jda.shutdownNow();
}
} }
+15 -3
View File
@@ -17,10 +17,13 @@ public class ThreadManager {
public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2); public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
public static void shutdownExecutor() { public static void shutdownExecutor() {
try {
MusicBot.LOGGER.info("[Executor] Shutting down..."); MusicBot.LOGGER.info("[Executor] Shutting down...");
try {
executor.shutdown(); executor.shutdown();
scheduler.shutdown();
executor.awaitTermination(5, TimeUnit.SECONDS); executor.awaitTermination(5, TimeUnit.SECONDS);
scheduler.awaitTermination(5, TimeUnit.SECONDS);
} }
catch (InterruptedException e) { catch (InterruptedException e) {
MusicBot.LOGGER.warn("[Executor] Running tasks interrupted"); MusicBot.LOGGER.warn("[Executor] Running tasks interrupted");
@@ -28,9 +31,18 @@ public class ThreadManager {
finally { finally {
if (!executor.isTerminated()) { if (!executor.isTerminated()) {
MusicBot.LOGGER.warn("[Executor] Forcing shutdown of running tasks.."); MusicBot.LOGGER.warn("[Executor] Forcing shutdown of running tasks..");
}
executor.shutdownNow(); executor.shutdownNow();
}
if (!scheduler.isTerminated()) {
MusicBot.LOGGER.warn("[Executor] Forcing shutdown of running tasks..");
scheduler.shutdownNow();
}
}
MusicBot.LOGGER.info("[Executor] Shutdown finished!"); MusicBot.LOGGER.info("[Executor] Shutdown finished!");
} }
}
} }
@@ -117,6 +117,7 @@ public class MysqlDatabase {
private int executeUpdate(String sql, Object[] params) { private int executeUpdate(String sql, Object[] params) {
try { try {
PreparedStatement query = connection.prepareStatement(sql); PreparedStatement query = connection.prepareStatement(sql);
resolveParameters(query, params); resolveParameters(query, params);
@@ -142,7 +143,8 @@ public class MysqlDatabase {
try { try {
PreparedStatement query = connection.prepareStatement(sql); PreparedStatement query = connection.prepareStatement(sql);
resolveParameters(query, params); resolveParameters(query, params);
return query.executeQuery(); ResultSet rs = query.executeQuery();
return rs;
} catch (SQLException e) { } catch (SQLException e) {
MusicBot.LOGGER.error(e.toString()); MusicBot.LOGGER.error(e.toString());
e.printStackTrace(); e.printStackTrace();
@@ -7,22 +7,39 @@ import netneutrality.MusicBot;
import netneutrality.db.DBController; import netneutrality.db.DBController;
import netneutrality.db.controllers.DBSettings; import netneutrality.db.controllers.DBSettings;
import java.io.*;
import java.util.Properties;
public class Settings { public class Settings {
static Properties prop = new Properties();
static String configFile = "bot.config";
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 final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss";
public static String PREFIX = ((DBSettings) DBController.get("settings")).getSettingsByKey("prefix"); public static String PREFIX = prop.getProperty("bot.prefix");
public static final String TOKEN = ((DBSettings) DBController.get("settings")).getSettingsByKey("token"); public static final String TOKEN = prop.getProperty("bot.token");
public static User getCreator() { public static User getCreator() {
return MusicBot.getJDA().getUserById(((DBSettings) DBController.get("settings")).getSettingsByKey("owner")); return MusicBot.getJDA().getUserById(prop.getProperty("bot.owner"));
} }
public static Guild getOwnerGuild() { public static Guild getOwnerGuild() {
return MusicBot.getJDA().getGuildById(((DBSettings) DBController.get("settings")).getSettingsByKey("ownerguild")); return MusicBot.getJDA().getGuildById(prop.getProperty("bot.ownerguild"));
} }
public static TextChannel getLogChannel() { public static TextChannel getLogChannel() {
return MusicBot.getJDA().getTextChannelById(((DBSettings) DBController.get("settings")).getSettingsByKey("errorchannel")); return MusicBot.getJDA().getTextChannelById(prop.getProperty("bot.errorchannel"));
} }
+5
View File
@@ -0,0 +1,5 @@
bot.token=""
bot.prefix="$"
bot.owner=""
bot.ownerguild=""
bot.errorchannel=""