Changed settings class to remove dependency to JDA
This commit is contained in:
1 parent
132fa92557
commit
2a1c7c4f3b
9 files changed
+36
-38
No files matched your search
@@ -26,19 +26,9 @@ public class MusicBot {
|
||||
public final static Logger logger = LoggerFactory.getLogger(MusicBot.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("log4j.skipJansi", "false");
|
||||
|
||||
DBController.init();
|
||||
|
||||
try {
|
||||
jda = JDABuilder.createDefault(Settings.getInstance().get("BOT_TOKEN"))
|
||||
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES)
|
||||
.build();
|
||||
jda.awaitReady();
|
||||
} catch (LoginException | IllegalArgumentException | InterruptedException e) {
|
||||
logger.error(e.getMessage());
|
||||
System.exit(0);
|
||||
}
|
||||
initJDA();
|
||||
|
||||
jda.getPresence().setActivity(Activity.watching("me load..."));
|
||||
jda.addEventListener(new NewCommandListener(), new EditHandler());
|
||||
@@ -57,6 +47,18 @@ public class MusicBot {
|
||||
|
||||
}
|
||||
|
||||
public static void initJDA() {
|
||||
try {
|
||||
jda = JDABuilder.createDefault(Settings.getInstance().get("BOT_TOKEN"))
|
||||
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES)
|
||||
.build();
|
||||
jda.awaitReady();
|
||||
} catch (LoginException | IllegalArgumentException | InterruptedException e) {
|
||||
logger.error(e.getMessage());
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
System.out.println("[Net Neutrality] Shutting down...");
|
||||
MusicManager.disconnectPlayers();
|
||||
|
||||
@@ -4,10 +4,8 @@ import java.awt.Color;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.PrivateChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
@@ -66,7 +64,7 @@ public class DatabaseCommand extends AbstractCommand {
|
||||
|
||||
event.getMessage().delete().queue();
|
||||
|
||||
if (!event.getAuthor().getDiscriminator().equals(Settings.getInstance().getCreator().getDiscriminator()))
|
||||
if (!event.getAuthor().getId().equals(Settings.getInstance().getCreatorId()))
|
||||
return null;
|
||||
|
||||
if (args.length > 0) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class EvalMethod extends AbstractCommand {
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
if (event.getAuthor().getId().equals(Settings.getInstance().getCreator().getId())) {
|
||||
if (event.getAuthor().getId().equals(Settings.getInstance().getCreatorId())) {
|
||||
ScriptEngine se = new ScriptEngineManager().getEngineByName("Nashorn");
|
||||
try {
|
||||
se.eval("var imports = new JavaImporter(java.io, java.lang, java.util);");
|
||||
|
||||
@@ -57,7 +57,7 @@ public class TestCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String[] args) {
|
||||
if (event.getAuthor().getDiscriminator().equals(Settings.getInstance().getCreator().getDiscriminator())) {
|
||||
if (event.getAuthor().getId().equals(Settings.getInstance().getCreatorId())) {
|
||||
MessageFunction.isStartingWithMention(event.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package netneutrality.db;
|
||||
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
@@ -25,14 +27,15 @@ public class MysqlConnector {
|
||||
* @return {@link MysqlConnector}
|
||||
*/
|
||||
public MysqlConnector connect() throws SQLException {
|
||||
MysqlDataSource dataSource = new MysqlDataSource();
|
||||
String jdbc = "jdbc:mysql://" + dbHost + ":3306/" + dbName;
|
||||
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
c = DriverManager.getConnection(jdbc, dbUser, dbPass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
dataSource.setURL(jdbc);
|
||||
dataSource.setUser(dbUser);
|
||||
dataSource.setPassword(dbPass);
|
||||
dataSource.setAutoReconnect(true);
|
||||
dataSource.setConnectTimeout(5000);
|
||||
c = dataSource.getConnection();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public abstract class AbstractEntity implements EntityInterface {
|
||||
this.table = DBController.get().prepareAndExecuteAsync(sql, this.primaryKey, this.primaryKeys).blocking();
|
||||
else
|
||||
this.table = DBController.get().prepareAndExecuteAsync(sql, this.primaryKey).blocking();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,8 @@ public class LogHandler {
|
||||
logger.error(e.getMessage());
|
||||
|
||||
//TODO: to remove or add check if jda is started
|
||||
Settings.getInstance().getLogChannel().sendMessage("Error : " + e).queue();
|
||||
String channel = Settings.getInstance().getLogChannel();
|
||||
MusicBot.getJDA().getTextChannelById(channel).sendMessage("Error : " + e).queue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package netneutrality.utils;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import netneutrality.MusicBot;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -68,16 +63,16 @@ public class Settings {
|
||||
|
||||
public final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public User getCreator() {
|
||||
return MusicBot.getJDA().getUserById(get("BOT_OWNER"));
|
||||
public String getCreatorId() {
|
||||
return get("BOT_OWNER");
|
||||
}
|
||||
|
||||
public Guild getOwnerGuild() {
|
||||
return MusicBot.getJDA().getGuildById(get("BOT_OWNERGUILD"));
|
||||
public String getOwnerGuild() {
|
||||
return get("BOT_OWNERGUILD");
|
||||
}
|
||||
|
||||
public TextChannel getLogChannel() {
|
||||
return MusicBot.getJDA().getTextChannelById(get("BOT_ERRORCHANNEL"));
|
||||
public String getLogChannel() {
|
||||
return get("BOT_ERRORCHANNEL");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,15 +3,14 @@ package netneutrality.utils;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
public class UserFunction {
|
||||
|
||||
public static boolean isAdmin(Member user) {
|
||||
|
||||
// This check will only be present during the development of the bot
|
||||
User creator = Settings.getInstance().getCreator();
|
||||
if (creator != null && user.getId().equals(creator.getId())) {
|
||||
String creatorId = Settings.getInstance().getCreatorId();
|
||||
if (creatorId != null && user.getId().equals(creatorId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user