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