Refactored code and fixed bugs
This commit is contained in:
1 parent
a5354a5793
commit
fe0ce72492
4 files changed
+38
-27
No files matched your search
@@ -48,23 +48,19 @@ public class MusicBot {
|
||||
|
||||
ConsoleHandler consoleInput = new ConsoleHandler();
|
||||
|
||||
try {
|
||||
switch (consoleInput.init()) {
|
||||
switch (consoleInput.init()) {
|
||||
|
||||
case "quit":
|
||||
System.out.println("Shutting down...");
|
||||
MusicManager.disconnectPlayers();
|
||||
jda.shutdown();
|
||||
DBController.shutdown();
|
||||
ThreadManager.shutdownExecutor();
|
||||
System.out.println("Shutdown complete");
|
||||
System.exit(0);
|
||||
break;
|
||||
case "quit":
|
||||
System.out.println("Shutting down...");
|
||||
MusicManager.disconnectPlayers();
|
||||
jda.shutdown();
|
||||
DBController.shutdown();
|
||||
ThreadManager.shutdownExecutor();
|
||||
System.out.println("Shutdown complete");
|
||||
System.exit(0);
|
||||
break;
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,16 @@ public class MysqlDatabase {
|
||||
return query.executeQuery();
|
||||
}
|
||||
|
||||
// https://github.com/Kaaz/DiscordBot/blob/master/src/main/java/emily/db/MySQLAdapter.java#resolveParameters
|
||||
//
|
||||
|
||||
/**
|
||||
* Insert parameters (specified with a ?) in the SQL statement
|
||||
* Taken from https://github.com/Kaaz/DiscordBot/blob/master/src/main/java/emily/db/MySQLAdapter.java#resolveParameters
|
||||
*
|
||||
* @param query The PreparedStatement object
|
||||
* @param params The parameters to be included in the prepared statement
|
||||
* @throws SQLException
|
||||
*/
|
||||
private void resolveParameters(PreparedStatement query, Object... params) throws SQLException {
|
||||
int index = 1;
|
||||
for (Object p : params) {
|
||||
@@ -163,7 +172,7 @@ public class MysqlDatabase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Recreate the MySQL connection.
|
||||
* Recreate and reconnect the MySQL connection.
|
||||
*/
|
||||
public void reconnect() {
|
||||
|
||||
@@ -193,7 +202,7 @@ public class MysqlDatabase {
|
||||
* <br>The first row of the array is the names of the columns.
|
||||
* <br>The other rows are their corresponding value
|
||||
*
|
||||
*
|
||||
* @deprecated Use {@link #convertToTableModel(ResultSet)} instead
|
||||
* @param rs The ResultSet returned by the SELECT query
|
||||
* @return an array of Object with the table structure
|
||||
* @throws SQLException
|
||||
@@ -218,8 +227,9 @@ public class MysqlDatabase {
|
||||
}
|
||||
|
||||
try {
|
||||
if (array[1][0] == null)
|
||||
if (array[1][0] == null) {
|
||||
nbRow = 0;
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException ignored) {
|
||||
|
||||
}
|
||||
@@ -231,7 +241,7 @@ public class MysqlDatabase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rs
|
||||
* @param rs The ResultSet returned by the SELECT query
|
||||
* @return a {@link MTableModel} with the appropriate column and rows
|
||||
* @throws SQLException
|
||||
*/
|
||||
|
||||
@@ -84,10 +84,11 @@ public class DBBlacklist extends AbstractController {
|
||||
try {
|
||||
if (isAlreadyBlacklisted(word, serverId)) {
|
||||
ResultSet rs = database.prepareAndExecute("SELECT * FROM blacklist WHERE word = ? AND serverId = ?", word, serverId);
|
||||
Object array[][] = database.convertToArray(rs);
|
||||
if (database.getNbRow() != 0) {
|
||||
blacklisted = new MBlacklist((String) array[1][0], (Boolean) array[1][2], (String) array[1][3],
|
||||
(String) array[1][1]);
|
||||
MTableModel table = database.convertToTableModel(rs);
|
||||
|
||||
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),
|
||||
(String) table.getRow(0).get(1));
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Is not blacklisted");
|
||||
|
||||
@@ -13,13 +13,17 @@ public class ConsoleHandler {
|
||||
MusicBot.LOGGER.info("Console input ready!");
|
||||
}
|
||||
|
||||
public String init() throws IOException {
|
||||
public String init() {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
String input;
|
||||
String input = "";
|
||||
do {
|
||||
System.out.print(">");
|
||||
input = br.readLine();
|
||||
try {
|
||||
input = br.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} while (!input.equalsIgnoreCase("quit"));
|
||||
|
||||
return input;
|
||||
|
||||
Reference in new issue
Block a user