Cleanup of code
This commit is contained in:
1 parent
f10009670e
commit
4c79bd5e71
12 files changed
+26
-50
No files matched your search
@@ -25,7 +25,7 @@ public abstract class AbstractController {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AbstractController end() {
|
||||
protected AbstractController end() {
|
||||
System.out.println("Ended task! ["+ getControllerName() + "}");
|
||||
DBController.isDoingSomething = false;
|
||||
isDoingSomething = false;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class DBController {
|
||||
/**
|
||||
* Loads all the controllers which extends {@link AbstractController}
|
||||
*/
|
||||
public static void loadControllers() {
|
||||
private static void loadControllers() {
|
||||
System.out.println("Loading databases controllers..");
|
||||
|
||||
Reflections reflections = new Reflections("netneutrality.db.controllers");
|
||||
|
||||
@@ -7,13 +7,13 @@ import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
|
||||
|
||||
public class MysqlConnector {
|
||||
|
||||
protected String dbName;
|
||||
protected String dbUser;
|
||||
protected String dbHost;
|
||||
protected String dbPass;
|
||||
private String dbName;
|
||||
private String dbUser;
|
||||
private String dbHost;
|
||||
private String dbPass;
|
||||
private Connection c;
|
||||
|
||||
public MysqlConnector(String dbName, String dbUser, String dbHost, String dbPass) {
|
||||
MysqlConnector(String dbName, String dbUser, String dbHost, String dbPass) {
|
||||
this.dbName = dbName;
|
||||
this.dbUser = dbUser;
|
||||
this.dbHost = dbHost;
|
||||
|
||||
@@ -158,8 +158,6 @@ public class MysqlDatabase {
|
||||
|
||||
/**
|
||||
* Recreate the MySQL connection.
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void reconnect() {
|
||||
|
||||
@@ -216,7 +214,7 @@ public class MysqlDatabase {
|
||||
try {
|
||||
if (array[1][0] == null)
|
||||
nbRow = 0;
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
} catch (ArrayIndexOutOfBoundsException ignored) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -134,9 +134,7 @@ public class DBBlacklist extends AbstractController {
|
||||
} catch (SQLException e) {
|
||||
end();
|
||||
e.printStackTrace();
|
||||
} catch (NullPointerException e) {
|
||||
end();
|
||||
} catch (IndexOutOfBoundsException i) {
|
||||
} catch (NullPointerException | IndexOutOfBoundsException e) {
|
||||
end();
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DBMessage extends AbstractController {
|
||||
}
|
||||
|
||||
public ArrayList<MMessage> getMessagesFromUser(String username, String serverName, int max) {
|
||||
ArrayList<MMessage> messages = new ArrayList<MMessage>();
|
||||
ArrayList<MMessage> messages = new ArrayList<>();
|
||||
|
||||
try {
|
||||
ResultSet rs = database.prepareAndExecute("SELECT * FROM log_message WHERE userName = ? AND serverName = ? ORDER BY dateSent DESC", username, serverName);
|
||||
|
||||
@@ -2,8 +2,6 @@ package netneutrality.db.controllers;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import netneutrality.db.AbstractController;
|
||||
|
||||
@@ -14,7 +12,7 @@ public class DBSettings extends AbstractController {
|
||||
}
|
||||
|
||||
public String getLoggingChannel(String serverId) {
|
||||
if (serverId.isEmpty() || serverId == null) {
|
||||
if (serverId.isEmpty()) {
|
||||
end();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -6,22 +6,20 @@ import java.io.InputStreamReader;
|
||||
|
||||
public class ConsoleHandler {
|
||||
|
||||
|
||||
private BufferedReader br;
|
||||
private String input = "";
|
||||
|
||||
|
||||
public ConsoleHandler() {
|
||||
System.out.println("Console input ready!");
|
||||
}
|
||||
|
||||
public String init() throws IOException {
|
||||
this.br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
String input;
|
||||
do {
|
||||
System.out.print(">");
|
||||
this.input = this.br.readLine();
|
||||
} while (!this.input.equalsIgnoreCase("quit"));
|
||||
input = br.readLine();
|
||||
} while (!input.equalsIgnoreCase("quit"));
|
||||
|
||||
return this.input;
|
||||
return input;
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,11 @@ import java.lang.reflect.Modifier;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.command.basic.HelpCommand;
|
||||
import netneutrality.utils.MessageFunction;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
@@ -29,8 +27,6 @@ public class NewCommandListener extends ListenerAdapter {
|
||||
|
||||
private HashMap<String, AbstractCommand> commands = new HashMap<>();
|
||||
private HashMap<String, AbstractCommand> commandsAlias = new HashMap<>();
|
||||
private Map<String, String[]> alias = new HashMap<>();
|
||||
|
||||
|
||||
public NewCommandListener() {
|
||||
initCommands();
|
||||
@@ -76,24 +72,23 @@ public class NewCommandListener extends ListenerAdapter {
|
||||
if (cmd.equals("help")) {
|
||||
((HelpCommand) commands.get("help")).sendHelp(commands, commandsAlias, event.getAuthor(), event.getChannel());
|
||||
} else {
|
||||
c.execute(event, msg.replaceFirst("(" + cmd + ")(\\ )?", ""));
|
||||
c.execute(event, msg.replaceFirst("(" + cmd + ")( )?", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
String finalMsg = msg;
|
||||
ArrayList<MBlacklist> blacklist = new ArrayList<>();
|
||||
|
||||
try {
|
||||
blacklist = ((DBBlacklist) DBController.get("blacklist")).getBlacklistFromServer(event.getGuild().getId());
|
||||
} catch (RuntimeException e) { }
|
||||
} catch (RuntimeException ignored) { }
|
||||
|
||||
if (!blacklist.isEmpty()) {
|
||||
|
||||
boolean found = false;
|
||||
for (int i = 0; i < blacklist.size(); i++) {
|
||||
if (finalMsg.toLowerCase().contains(blacklist.get(i).getWord()))
|
||||
for (MBlacklist aBlacklist : blacklist) {
|
||||
if (msg.toLowerCase().contains(aBlacklist.getWord()))
|
||||
found = true;
|
||||
}
|
||||
|
||||
@@ -105,7 +100,7 @@ public class NewCommandListener extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public void initCommands() {
|
||||
private void initCommands() {
|
||||
System.out.println("Loading commands..");
|
||||
|
||||
Reflections reflections = new Reflections("netneutrality.command");
|
||||
@@ -134,7 +129,7 @@ public class NewCommandListener extends ListenerAdapter {
|
||||
System.out.println("Loaded " + commands.size() + " commands!");
|
||||
}
|
||||
|
||||
public void initAlias() {
|
||||
private void initAlias() {
|
||||
|
||||
for (AbstractCommand command : commands.values()) {
|
||||
for (String alias : command.getAlias()) {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package netneutrality.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import okhttp3.*;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@@ -63,7 +61,7 @@ public class WebModule {
|
||||
for (Map.Entry<String, String> header : headers.entrySet()) {
|
||||
builder.addHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
Request request = builder.build();
|
||||
Request request = builder.post(body).build();
|
||||
response = client.newCall(request).execute();
|
||||
|
||||
return this;
|
||||
@@ -88,7 +86,7 @@ public class WebModule {
|
||||
StringBuilder json = new StringBuilder();
|
||||
|
||||
for (String str : list) {
|
||||
json.append("\"" + str + "\"");
|
||||
json.append("\"").append(str).append("\"");
|
||||
json.append(",");
|
||||
}
|
||||
json.insert(0, "[");
|
||||
|
||||
@@ -6,18 +6,10 @@ package netneutrality.http.server;
|
||||
* This file is closed-source. It should not be distributed or copied in any way or form
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.http.WebModule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class WebApi {
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.List;
|
||||
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import netneutrality.handler.LogHandler;
|
||||
|
||||
public class ChannelFunction {
|
||||
|
||||
|
||||
Reference in new issue
Block a user