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

+25 -20
View File
@@ -3,22 +3,27 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xtremcommunity.discord</groupId>
<artifactId>netneutrality</artifactId>
<version>0.0.1</version>
<name>MusicBot</name>
<description>Music bot</description>
<version>1.0.0</version>
<name>netneutrality-discord-bot</name>
<description>Discord bot</description>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target>
</properties>
<distributionManagement>
<downloadUrl>https://gitlab.xtremcommunity.com/nn.jar</downloadUrl>
</distributionManagement>
<repositories>
<repository> <!-- This repo fixes issues with transitive dependencies -->
<id>jcenter</id>
<url>http://jcenter.bintray.com</url>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
</repositories>
@@ -27,27 +32,27 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.1.0_81</version>
<version>4.3.0_277</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.13.0</version>
<version>4.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
<version>20210307</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
<dependency>
@@ -58,33 +63,33 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.10.0</version>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.10.0</version>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.10.0</version>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.17</version>
<version>2.3.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.33</version>
<version>1.3.77</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<version>4.13.2</version>
</dependency>
</dependencies>
+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=""