Improved logging and refactored code
This commit is contained in:
1 parent
c92fab3a3c
commit
b019852c62
8 files changed
+107
-48
No files matched your search
@@ -10,6 +10,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import netneutrality.MusicBot;
|
import netneutrality.MusicBot;
|
||||||
import netneutrality.ThreadManager;
|
import netneutrality.ThreadManager;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When creating a controller, all database actions must be executed in another thread using an executor. One is provided in the {@link ThreadManager} class
|
* When creating a controller, all database actions must be executed in another thread using an executor. One is provided in the {@link ThreadManager} class
|
||||||
@@ -22,7 +24,7 @@ public class DBController {
|
|||||||
*/
|
*/
|
||||||
private final static HashMap<String, AbstractController> controllers = new HashMap<>();
|
private final static HashMap<String, AbstractController> controllers = new HashMap<>();
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(DBController.class);
|
||||||
private static MysqlDatabase database = new MysqlDatabase("netneutrality");
|
private static MysqlDatabase database = new MysqlDatabase("netneutrality");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +48,7 @@ public class DBController {
|
|||||||
|
|
||||||
public static MysqlDatabase get() {
|
public static MysqlDatabase get() {
|
||||||
if (database.isClosed()) {
|
if (database.isClosed()) {
|
||||||
MusicBot.LOGGER.info("Reconnecting to database..");
|
logger.info("Reconnecting to database..");
|
||||||
database.reconnect();
|
database.reconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ public class DBController {
|
|||||||
* Loads all the controllers which extends {@link AbstractController}
|
* Loads all the controllers which extends {@link AbstractController}
|
||||||
*/
|
*/
|
||||||
private static void loadControllers() {
|
private static void loadControllers() {
|
||||||
MusicBot.LOGGER.info("Loading databases controllers..");
|
logger.info("Loading databases controllers..");
|
||||||
|
|
||||||
Reflections reflections = new Reflections("netneutrality.db.controllers");
|
Reflections reflections = new Reflections("netneutrality.db.controllers");
|
||||||
Set<Class<? extends AbstractController>> classes = reflections.getSubTypesOf(AbstractController.class);
|
Set<Class<? extends AbstractController>> classes = reflections.getSubTypesOf(AbstractController.class);
|
||||||
@@ -91,7 +93,7 @@ public class DBController {
|
|||||||
|
|
||||||
if (!controllers.containsKey(c.getControllerName())) {
|
if (!controllers.containsKey(c.getControllerName())) {
|
||||||
controllers.put(c.getControllerName(), c);
|
controllers.put(c.getControllerName(), c);
|
||||||
MusicBot.LOGGER.debug("Loaded controller: " + c.getControllerName());
|
logger.debug("Loaded controller: " + c.getControllerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) {
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) {
|
||||||
|
|||||||
@@ -17,9 +17,15 @@ import netneutrality.db.models.MRowModel;
|
|||||||
import netneutrality.db.models.MTableModel;
|
import netneutrality.db.models.MTableModel;
|
||||||
import netneutrality.exceptions.UnimplementedParameterException;
|
import netneutrality.exceptions.UnimplementedParameterException;
|
||||||
import netneutrality.handler.LogHandler;
|
import netneutrality.handler.LogHandler;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class MysqlDatabase {
|
public class MysqlDatabase {
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(MysqlDatabase.class);
|
||||||
|
private Connection connection;
|
||||||
|
private String dbName;
|
||||||
|
|
||||||
protected enum CommandType {
|
protected enum CommandType {
|
||||||
SELECT("SELECT"), INSERT("INSERT"), UPDATE("UPDATE"), DELETE("DELETE");
|
SELECT("SELECT"), INSERT("INSERT"), UPDATE("UPDATE"), DELETE("DELETE");
|
||||||
|
|
||||||
@@ -34,16 +40,15 @@ public class MysqlDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection connection;
|
|
||||||
private String dbName;
|
|
||||||
|
|
||||||
protected MysqlDatabase(String dbName) {
|
protected MysqlDatabase(String dbName) {
|
||||||
this.dbName = dbName;
|
this.dbName = dbName;
|
||||||
try {
|
try {
|
||||||
MusicBot.LOGGER.info("Connecting to database...");
|
logger.info("Connecting to database...");
|
||||||
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..");
|
logger.error("Error connecting to database. Shutting down..");
|
||||||
MusicBot.shutdown();
|
MusicBot.shutdown();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
@@ -57,14 +62,14 @@ public class MysqlDatabase {
|
|||||||
* @return {@link ResultSet}
|
* @return {@link ResultSet}
|
||||||
*/
|
*/
|
||||||
public ResultSet query(String query) {
|
public ResultSet query(String query) {
|
||||||
MusicBot.LOGGER.debug("Query: " + query);
|
logger.debug("Query: " + query);
|
||||||
|
|
||||||
Statement stmt;
|
Statement stmt;
|
||||||
try {
|
try {
|
||||||
stmt = connection.createStatement();
|
stmt = connection.createStatement();
|
||||||
return stmt.executeQuery(query);
|
return stmt.executeQuery(query);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
logger.error(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -138,7 +143,7 @@ public class MysqlDatabase {
|
|||||||
* @return a ResultSet object, which can be converted to a model using {@link MysqlDatabase#convertToTableModel(ResultSet)}
|
* @return a ResultSet object, which can be converted to a model using {@link MysqlDatabase#convertToTableModel(ResultSet)}
|
||||||
*/
|
*/
|
||||||
public ResultSet prepareAndExecute(String sql, Object... params) {
|
public ResultSet prepareAndExecute(String sql, Object... params) {
|
||||||
MusicBot.LOGGER.debug("Query: " + sql);
|
logger.debug("Query: " + sql);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PreparedStatement query = connection.prepareStatement(sql);
|
PreparedStatement query = connection.prepareStatement(sql);
|
||||||
@@ -146,7 +151,7 @@ public class MysqlDatabase {
|
|||||||
ResultSet rs = query.executeQuery();
|
ResultSet rs = query.executeQuery();
|
||||||
return rs;
|
return rs;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
MusicBot.LOGGER.error(e.toString());
|
logger.error(e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +217,7 @@ public class MysqlDatabase {
|
|||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void close() throws SQLException {
|
public void close() throws SQLException {
|
||||||
MusicBot.LOGGER.info("Closing database...");
|
logger.info("Closing database...");
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,10 +227,10 @@ public class MysqlDatabase {
|
|||||||
public void reconnect() {
|
public void reconnect() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println("Reconnecting to database...");
|
logger.info("Reconnecting to database...");
|
||||||
connection = new MysqlConnector(dbName, "root", "localhost", "").connect().getConnection();
|
connection = new MysqlConnector(dbName, "root", "localhost", "").connect().getConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.err.println("Error connecting to database. Shutting down..");
|
logger.error("Error connecting to database. Shutting down..");
|
||||||
MusicBot.shutdown();
|
MusicBot.shutdown();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,13 @@ import netneutrality.db.DBController;
|
|||||||
import netneutrality.db.MysqlDatabase;
|
import netneutrality.db.MysqlDatabase;
|
||||||
import netneutrality.db.models.MBlacklist;
|
import netneutrality.db.models.MBlacklist;
|
||||||
import netneutrality.db.models.MTableModel;
|
import netneutrality.db.models.MTableModel;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class DBBlacklist extends AbstractController {
|
public class DBBlacklist extends AbstractController {
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(DBBlacklist.class);
|
||||||
|
|
||||||
public DBBlacklist() {
|
public DBBlacklist() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -45,10 +49,10 @@ public class DBBlacklist extends AbstractController {
|
|||||||
isAlreadyBlacklisted(word, serverId, blacklisted -> {
|
isAlreadyBlacklisted(word, serverId, blacklisted -> {
|
||||||
if (blacklisted >= 1) {
|
if (blacklisted >= 1) {
|
||||||
database.prepareAndExecuteAsync("DELETE FROM blacklist WHERE word = ? AND serverId = ?", word, serverId).async();
|
database.prepareAndExecuteAsync("DELETE FROM blacklist WHERE word = ? AND serverId = ?", word, serverId).async();
|
||||||
MusicBot.LOGGER.info("blacklisted");
|
logger.info("blacklisted");
|
||||||
success.accept(true);
|
success.accept(true);
|
||||||
} else {
|
} else {
|
||||||
MusicBot.LOGGER.info("not blacklisted");
|
logger.info("not blacklisted");
|
||||||
success.accept(false);
|
success.accept(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -60,10 +64,10 @@ public class DBBlacklist extends AbstractController {
|
|||||||
isAlreadyBlacklisted(word, serverId, blacklisted -> {
|
isAlreadyBlacklisted(word, serverId, blacklisted -> {
|
||||||
if (blacklisted >= 1) {
|
if (blacklisted >= 1) {
|
||||||
database.prepareAndExecuteAsync("UPDATE blacklist SET isEnabled = 1 WHERE word = ? AND serverId = ?", word, serverId).async();
|
database.prepareAndExecuteAsync("UPDATE blacklist SET isEnabled = 1 WHERE word = ? AND serverId = ?", word, serverId).async();
|
||||||
MusicBot.LOGGER.info("enabled");
|
logger.info("enabled");
|
||||||
success.accept(true);
|
success.accept(true);
|
||||||
} else {
|
} else {
|
||||||
MusicBot.LOGGER.info("error enabling");
|
logger.info("error enabling");
|
||||||
success.accept(false);
|
success.accept(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -75,16 +79,17 @@ public class DBBlacklist extends AbstractController {
|
|||||||
isAlreadyBlacklisted(word, serverId, blacklisted -> {
|
isAlreadyBlacklisted(word, serverId, blacklisted -> {
|
||||||
if (blacklisted >= 1) {
|
if (blacklisted >= 1) {
|
||||||
database.prepareAndExecuteAsync("UPDATE blacklist SET isEnabled = 0 WHERE word = ? AND serverId = ?", word, serverId).async();
|
database.prepareAndExecuteAsync("UPDATE blacklist SET isEnabled = 0 WHERE word = ? AND serverId = ?", word, serverId).async();
|
||||||
MusicBot.LOGGER.info("disabled");
|
logger.info("disabled");
|
||||||
success.accept(true);
|
success.accept(true);
|
||||||
} else {
|
} else {
|
||||||
MusicBot.LOGGER.info("error disabled");
|
logger.info("error disabled");
|
||||||
success.accept(false);
|
success.accept(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void getBlacklistForWord(String word, String serverId, Consumer<MBlacklist> success) {
|
public void getBlacklistForWord(String word, String serverId, Consumer<MBlacklist> success) {
|
||||||
ThreadManager.executor.submit(() -> {
|
ThreadManager.executor.submit(() -> {
|
||||||
MBlacklist blacklisted = null;
|
MBlacklist blacklisted = null;
|
||||||
@@ -94,8 +99,7 @@ public class DBBlacklist extends AbstractController {
|
|||||||
MTableModel table = MysqlDatabase.convertToTableModel(rs);
|
MTableModel table = MysqlDatabase.convertToTableModel(rs);
|
||||||
|
|
||||||
if (table.getNbRows() > 0) {
|
if (table.getNbRows() > 0) {
|
||||||
blacklisted = new MBlacklist((String) table.getRow(0).get(0), (Boolean) table.getRow(0).get(2), (String) table.getRow(0).get(3),
|
blacklisted = new MBlacklist(table.getRow(0));
|
||||||
(String) table.getRow(0).get(1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +113,14 @@ public class DBBlacklist extends AbstractController {
|
|||||||
database.prepareAndExecuteAsync("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId).async(model -> {
|
database.prepareAndExecuteAsync("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId).async(model -> {
|
||||||
ArrayList<MBlacklist> output = new ArrayList<>();
|
ArrayList<MBlacklist> output = new ArrayList<>();
|
||||||
|
|
||||||
if (model.getNbRows() != 0) {
|
|
||||||
|
if (model.getNbRows() > 0) {
|
||||||
|
|
||||||
|
|
||||||
for (int row = 0; row < model.getNbRows(); row++) {
|
for (int row = 0; row < model.getNbRows(); row++) {
|
||||||
output.add(new MBlacklist((String) model.getRow(row).get(0), (Boolean) model.getRow(row).get(2), (String) model.getRow(row).get(3),
|
logger.debug("enter loop");
|
||||||
(String) model.getRow(row).get(1)));
|
MBlacklist bl = new MBlacklist(model.getRow(row));
|
||||||
|
output.add(bl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +129,23 @@ public class DBBlacklist extends AbstractController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public ArrayList<MBlacklist> getBlacklistFromServer(String serverId) {
|
||||||
|
|
||||||
|
MTableModel model = database.prepareAndExecuteAsync("SELECT * FROM blacklist WHERE serverId = ? AND isEnabled = 1", serverId).blocking();
|
||||||
|
ArrayList<MBlacklist> output = new ArrayList<>();
|
||||||
|
|
||||||
|
if (model.getNbRows() > 0) {
|
||||||
|
|
||||||
|
for (int row = 0; row < model.getNbRows(); row++) {
|
||||||
|
MBlacklist bl = new MBlacklist(model.getRow(row));
|
||||||
|
output.add(bl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private boolean isAlreadyBlacklisted(String word, String serverId) {
|
private boolean isAlreadyBlacklisted(String word, String serverId) {
|
||||||
AtomicBoolean result = new AtomicBoolean();
|
AtomicBoolean result = new AtomicBoolean();
|
||||||
@@ -131,6 +156,7 @@ public class DBBlacklist extends AbstractController {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return result.get();
|
return result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,29 @@
|
|||||||
package netneutrality.db.controllers;
|
package netneutrality.db.controllers;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
import netneutrality.ThreadManager;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import netneutrality.db.AbstractController;
|
import netneutrality.db.AbstractController;
|
||||||
import netneutrality.db.DBController;
|
import netneutrality.db.DBController;
|
||||||
import netneutrality.db.MysqlDatabase;
|
import netneutrality.db.MysqlDatabase;
|
||||||
import netneutrality.db.models.MMessage;
|
import netneutrality.db.models.MMessage;
|
||||||
import netneutrality.db.models.MTableModel;
|
import netneutrality.db.models.MTableModel;
|
||||||
import netneutrality.handler.LogHandler;
|
import netneutrality.handler.LogHandler;
|
||||||
|
import netneutrality.utils.Settings;
|
||||||
import javax.swing.table.TableModel;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class DBMessage extends AbstractController {
|
public class DBMessage extends AbstractController {
|
||||||
|
|
||||||
public DBMessage() { }
|
private final static Logger logger = LoggerFactory.getLogger(DBMessage.class);
|
||||||
|
public DBMessage() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance of {@link MysqlDatabase} with the database name as set in the {@link DBController} class
|
* Returns an instance of {@link MysqlDatabase} with the database name as set in the {@link DBController} class
|
||||||
@@ -27,8 +34,15 @@ public class DBMessage extends AbstractController {
|
|||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String servername, String channelname, String username, String datesent, String messageId, String message) {
|
public void log(Guild guild, TextChannel channel, User author, Message message) {
|
||||||
database.prepareAndExecuteAsync("INSERT INTO log_message VALUES(?,?,?,?,?,?,?)", servername, channelname, username, datesent, messageId, message, null).async();
|
String servername = guild.getName();
|
||||||
|
String channelname = channel.getName();
|
||||||
|
String username = author.getName();
|
||||||
|
String datesent = message.getTimeCreated().format(DateTimeFormatter.ofPattern(Settings.DATETIMEFORMAT));
|
||||||
|
String messageid = message.getId();
|
||||||
|
String msg = message.getContentRaw().trim();
|
||||||
|
|
||||||
|
database.prepareAndExecuteAsync("INSERT INTO log_message VALUES(?,?,?,?,?,?,?)", servername, channelname, username, datesent, messageid, msg, null).async();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +86,7 @@ public class DBMessage extends AbstractController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
LogHandler.log(e);
|
LogHandler.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +94,6 @@ public class DBMessage extends AbstractController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getControllerName() {
|
public String getControllerName() {
|
||||||
return "message";
|
return "message";
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package netneutrality.db.models;
|
package netneutrality.db.models;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MBlacklist {
|
public class MBlacklist {
|
||||||
|
|
||||||
protected String word;
|
protected String word = "";
|
||||||
protected boolean enabled;
|
protected boolean enabled = false;
|
||||||
protected String creatorId;
|
protected String creatorId= "";
|
||||||
protected String serverId;
|
protected String serverId;
|
||||||
|
|
||||||
public MBlacklist(String word, boolean enabled, String creatorId, String serverId) {
|
public MBlacklist(String word, boolean enabled, String creatorId, String serverId) {
|
||||||
@@ -14,6 +16,13 @@ public class MBlacklist {
|
|||||||
this.serverId = serverId;
|
this.serverId = serverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MBlacklist(List<Object> row) {
|
||||||
|
this.word = (String) row.get(0);
|
||||||
|
this.enabled = (Boolean) row.get(2);
|
||||||
|
this.creatorId = (String) row.get(3);
|
||||||
|
this.serverId = (String) row.get(1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return String The blacklisted word
|
* @return String The blacklisted word
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ public class MSellyOrder {
|
|||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Construct from JSONObject
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package netneutrality.handler;
|
package netneutrality.handler;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
@@ -32,10 +31,7 @@ public class NewCommandListener extends ListenerAdapter {
|
|||||||
if (MessageRateLimit.check(event.getMember(), event.getMessage(), event.getChannel())) return;
|
if (MessageRateLimit.check(event.getMember(), event.getMessage(), event.getChannel())) return;
|
||||||
|
|
||||||
if (event.isFromType(ChannelType.TEXT)) {
|
if (event.isFromType(ChannelType.TEXT)) {
|
||||||
((DBMessage) DBController.get("message")).log(event.getGuild().getName(), event.getTextChannel().getName(),
|
((DBMessage) DBController.get("message")).log(event.getGuild(), event.getTextChannel(), event.getAuthor(), event.getMessage());
|
||||||
event.getMember().getUser().getName(),
|
|
||||||
event.getMessage().getTimeCreated().format(DateTimeFormatter.ofPattern(Settings.DATETIMEFORMAT)), event.getMessage().getId(),
|
|
||||||
event.getMessage().getContentDisplay().trim());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Message message = event.getMessage();
|
Message message = event.getMessage();
|
||||||
@@ -50,19 +46,15 @@ public class NewCommandListener extends ListenerAdapter {
|
|||||||
AbstractCommand c = CommandManager.commands.containsKey(cmd) ? CommandManager.commands.get(cmd) : CommandManager.commandsAlias.get(cmd);
|
AbstractCommand c = CommandManager.commands.containsKey(cmd) ? CommandManager.commands.get(cmd) : CommandManager.commandsAlias.get(cmd);
|
||||||
|
|
||||||
if (Visibility.check(event.getChannel(), c.getVisibility())) {
|
if (Visibility.check(event.getChannel(), c.getVisibility())) {
|
||||||
if (c.needAdmin() && c.getVisibility() != Visibility.PRIVATE) {
|
if (c.needAdmin()) {
|
||||||
if (!UserFunction.isAdmin(event.getMember())) {
|
if (!UserFunction.isAdmin(event.getMember())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.equals("help")) {
|
|
||||||
((HelpCommand) CommandManager.commands.get("help")).sendHelp(CommandManager.commands, CommandManager.commandsAlias, event.getAuthor(), event.getChannel());
|
|
||||||
} else {
|
|
||||||
c.execute(event, msg.replaceFirst("(" + cmd + ")( )?", ""));
|
c.execute(event, msg.replaceFirst("(" + cmd + ")( )?", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
MessageFunction.checkBlacklist(event.getGuild().getId(), event.getMessage(), event.getTextChannel(), msg);
|
MessageFunction.checkBlacklist(event.getGuild().getId(), event.getMessage(), event.getTextChannel(), msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,13 @@ import net.dv8tion.jda.api.entities.*;
|
|||||||
import netneutrality.db.DBController;
|
import netneutrality.db.DBController;
|
||||||
import netneutrality.db.controllers.DBBlacklist;
|
import netneutrality.db.controllers.DBBlacklist;
|
||||||
import netneutrality.db.models.MBlacklist;
|
import netneutrality.db.models.MBlacklist;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class MessageFunction {
|
public class MessageFunction {
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(MessageFunction.class);
|
||||||
|
|
||||||
public static Member getStartingMention(Message message) {
|
public static Member getStartingMention(Message message) {
|
||||||
if (isStartingWithMention(message)) {
|
if (isStartingWithMention(message)) {
|
||||||
return message.getMentionedMembers().get(0);
|
return message.getMentionedMembers().get(0);
|
||||||
@@ -43,7 +47,7 @@ public class MessageFunction {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageEmbed buildAddingTrackMessage(AudioTrack track, Member user) {
|
public synchronized 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);
|
||||||
@@ -51,6 +55,7 @@ public class MessageFunction {
|
|||||||
message.setFooter("Requested by " + user.getUser().getName(), user.getUser().getAvatarUrl());
|
message.setFooter("Requested by " + user.getUser().getName(), user.getUser().getAvatarUrl());
|
||||||
message.setTimestamp(OffsetDateTime.now());
|
message.setTimestamp(OffsetDateTime.now());
|
||||||
|
|
||||||
|
|
||||||
return message.build();
|
return message.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,11 +64,15 @@ public class MessageFunction {
|
|||||||
((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(guildId, mBlacklists -> {
|
((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(guildId, mBlacklists -> {
|
||||||
if (!mBlacklists.isEmpty()) {
|
if (!mBlacklists.isEmpty()) {
|
||||||
|
|
||||||
|
logger.debug("Not Empty");
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (MBlacklist aBlacklist : mBlacklists) {
|
for (MBlacklist aBlacklist : mBlacklists) {
|
||||||
if (msg.toLowerCase().contains(aBlacklist.getWord()))
|
logger.debug("TESTING WORD:" + aBlacklist.getWord());
|
||||||
|
if (msg.toLowerCase().contains(aBlacklist.getWord())) {
|
||||||
|
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
message.delete().queue();
|
message.delete().queue();
|
||||||
|
|||||||
Reference in new issue
Block a user