Changed settings controller
This commit is contained in:
1 parent
a94d234d26
commit
c8477466a5
3 files changed
+32
-52
No files matched your search
@@ -26,7 +26,9 @@ public class MusicBot {
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("log4j.skipJansi", "false");
|
||||
DBController.init();
|
||||
String token = ((DBSettings) DBController.get("settings")).getToken();
|
||||
|
||||
String token = ((DBSettings) DBController.get("settings")).getSettingsByKey("token");
|
||||
|
||||
try {
|
||||
jda = new JDABuilder(AccountType.BOT).setToken(token).buildBlocking();
|
||||
} catch (LoginException | IllegalArgumentException | InterruptedException e) {
|
||||
|
||||
@@ -51,8 +51,8 @@ public class SellyCommand extends AbstractCommand {
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
|
||||
String sellyEmail = ((DBSettings) DBController.get("settings")).getSellyEmail();
|
||||
String sellyKey = ((DBSettings) DBController.get("settings")).getSellyKey();
|
||||
String sellyEmail = ((DBSettings) DBController.get("settings")).getSettingsByKey("selly_email");
|
||||
String sellyKey = ((DBSettings) DBController.get("settings")).getSettingsByKey("");
|
||||
Selly selly = new Selly(sellyEmail, sellyKey);
|
||||
|
||||
Map<String, MSellyOrder> orders = selly.getOrders();
|
||||
|
||||
@@ -2,66 +2,44 @@ package netneutrality.db.controllers;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import netneutrality.ThreadManager;
|
||||
import netneutrality.db.AbstractController;
|
||||
import netneutrality.db.MysqlDatabase;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
|
||||
public class DBSettings extends AbstractController {
|
||||
|
||||
public String getLoggingChannel(String serverId) {
|
||||
if (serverId.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
public void getSettingsByKey(String key, Consumer<Object> success) {
|
||||
|
||||
try {
|
||||
ResultSet rs = database.prepareAndExecute("SELECT channelId FROM logging WHERE serverId = ? AND enabled = 1", serverId);
|
||||
if (rs.next()) {
|
||||
return rs.getString(1);
|
||||
ThreadManager.executor.submit(() -> {
|
||||
Object value = null;
|
||||
|
||||
ResultSet rs;
|
||||
rs = database.prepareAndExecute("SELECT value FROM settings WHERE skey = ?", key);
|
||||
MTableModel table = MysqlDatabase.convertToTableModel(rs);
|
||||
|
||||
if (table.getNbRows() == 1) {
|
||||
value = table.getRow(0).get(0);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
success.accept(value);
|
||||
});
|
||||
}
|
||||
|
||||
public String getSettingsByKey(String key) {
|
||||
|
||||
ResultSet rs;
|
||||
rs = database.prepareAndExecute("SELECT value FROM settings WHERE skey = ?", key);
|
||||
MTableModel table = MysqlDatabase.convertToTableModel(rs);
|
||||
|
||||
if (table.getNbRows() == 1) {
|
||||
return table.getRow(0).get(0).toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
try {
|
||||
ResultSet rs = database.prepareAndExecute("SELECT token FROM settings");
|
||||
if (rs.next()) {
|
||||
return rs.getString(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSellyEmail() {
|
||||
try {
|
||||
ResultSet rs = database.prepareAndExecute("SELECT selly_email FROM settings");
|
||||
if (rs.next()) {
|
||||
return rs.getString(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSellyKey() {
|
||||
try {
|
||||
ResultSet rs = database.prepareAndExecute("SELECT selly_key FROM settings");
|
||||
if (rs.next()) {
|
||||
return rs.getString(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControllerName() {
|
||||
|
||||
Reference in new issue
Block a user