Migrated settings to database and prepared for a onGuildJoin handler
This commit is contained in:
1 parent
2750f6f71d
commit
7fce891712
4 files changed
+32
-20
No files matched your search
@@ -28,7 +28,7 @@ public class MysqlDatabase {
|
|||||||
connection = new MysqlConnector(dbName, "root", "localhost", "").connect().getConnection();
|
connection = new MysqlConnector(dbName, "root", "localhost", "").connect().getConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
MusicBot.LOGGER.error("Error connecting to database. Shutting down..");
|
MusicBot.LOGGER.error("Error connecting to database. Shutting down..");
|
||||||
MusicBot.disconnect();
|
MusicBot.shutdown();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,15 @@ public class MysqlDatabase {
|
|||||||
return executeUpdate(sql, params);
|
return executeUpdate(sql, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean exists(String table, String key, String value) {
|
||||||
|
ResultSet rs = prepareAndExecute("SELECT 1 FROM " + table + " WHERE " + key + " = ?", value);
|
||||||
|
try {
|
||||||
|
return rs.next();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -190,7 +199,6 @@ public class MysqlDatabase {
|
|||||||
* Check if the database is closed.
|
* Check if the database is closed.
|
||||||
*
|
*
|
||||||
* @return the connection status
|
* @return the connection status
|
||||||
* @throws SQLException
|
|
||||||
*/
|
*/
|
||||||
public boolean isClosed() {
|
public boolean isClosed() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ package netneutrality.db.controllers;
|
|||||||
* https://discord.gg/CdFcyQ
|
* https://discord.gg/CdFcyQ
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.TextChannel;
|
import net.dv8tion.jda.core.entities.TextChannel;
|
||||||
import netneutrality.MusicBot;
|
import netneutrality.MusicBot;
|
||||||
import netneutrality.ThreadManager;
|
import netneutrality.ThreadManager;
|
||||||
import netneutrality.db.AbstractController;
|
import netneutrality.db.AbstractController;
|
||||||
|
import netneutrality.db.DBController;
|
||||||
import netneutrality.handler.LogHandler;
|
import netneutrality.handler.LogHandler;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -19,6 +21,14 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class DBLogging extends AbstractController {
|
public class DBLogging extends AbstractController {
|
||||||
|
|
||||||
|
public void logGuild(Guild g) {
|
||||||
|
ThreadManager.executor.submit(() -> {
|
||||||
|
if (!database.exists("guilds", "guild_id", g.getId())) {
|
||||||
|
database.insert("INSERT INTO guilds VALUES(?, ?, ?)", g.getId(), g.getName(), g.getOwner().getUser().getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void getLoggingChannel(String serverId, Consumer<TextChannel> success) {
|
public void getLoggingChannel(String serverId, Consumer<TextChannel> success) {
|
||||||
ThreadManager.executor.submit(() -> {
|
ThreadManager.executor.submit(() -> {
|
||||||
TextChannel txt = null;
|
TextChannel txt = null;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package netneutrality.utils;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||||
@@ -42,16 +43,18 @@ public class MessageFunction {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageEmbed buildAddingTrackMessage(AudioTrack track) {
|
public static MessageEmbed buildAddingTrackMessage(AudioTrack track, Member user) {
|
||||||
EmbedBuilder message = new EmbedBuilder();
|
EmbedBuilder message = new EmbedBuilder();
|
||||||
message.setTitle("Adding track to queue..");
|
message.setTitle("Adding track to queue..");
|
||||||
message.setColor(Color.BLUE);
|
message.setColor(Color.BLUE);
|
||||||
message.addField("Track title :", track.getInfo().title, false);
|
message.addField("Track title :", track.getInfo().title, false);
|
||||||
|
message.setFooter("Requested by " + user.getUser().getName(), "");
|
||||||
|
message.setTimestamp(OffsetDateTime.now());
|
||||||
|
|
||||||
return message.build();
|
return message.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkBlacklist(String guildId, Message message, TextChannel channel,String msg) {
|
public static void checkBlacklist(String guildId, Message message, TextChannel channel, String msg) {
|
||||||
try {
|
try {
|
||||||
((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(guildId, mBlacklists -> {
|
((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(guildId, mBlacklists -> {
|
||||||
if (!mBlacklists.isEmpty()) {
|
if (!mBlacklists.isEmpty()) {
|
||||||
|
|||||||
@@ -3,34 +3,25 @@ package netneutrality.utils;
|
|||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.TextChannel;
|
import net.dv8tion.jda.core.entities.TextChannel;
|
||||||
import net.dv8tion.jda.core.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
|
import netneutrality.MusicBot;
|
||||||
|
import netneutrality.db.DBController;
|
||||||
|
import netneutrality.db.controllers.DBSettings;
|
||||||
|
|
||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
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 = "$";
|
public static String PREFIX = ((DBSettings) DBController.get("settings")).getSettingsByKey("prefix");
|
||||||
private static User owner;
|
|
||||||
private static Guild ownerGuild;
|
|
||||||
private static TextChannel logChannel;
|
|
||||||
|
|
||||||
public static User getCreator() {
|
public static User getCreator() {
|
||||||
return owner;
|
return MusicBot.getJDA().getUserById(((DBSettings) DBController.get("settings")).getSettingsByKey("owner"));
|
||||||
}
|
|
||||||
|
|
||||||
public static void setCreator(User creator) {
|
|
||||||
Settings.owner = creator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Guild getOwnerGuild() {
|
public static Guild getOwnerGuild() {
|
||||||
return ownerGuild;
|
return MusicBot.getJDA().getGuildById(((DBSettings) DBController.get("settings")).getSettingsByKey("ownerguild"));
|
||||||
}
|
|
||||||
|
|
||||||
public static void setOwnerGuild(Guild ownerGuild) {
|
|
||||||
Settings.ownerGuild = ownerGuild;
|
|
||||||
logChannel = ownerGuild.getTextChannelById("400383009330823179");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextChannel getLogChannel() {
|
public static TextChannel getLogChannel() {
|
||||||
return logChannel;
|
return MusicBot.getJDA().getTextChannelById(((DBSettings) DBController.get("settings")).getSettingsByKey("errorchannel"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user