Argument support for joining channels (untested) resultseta and preparedstatements closing

This commit is contained in:
Venal 2017-07-28 13:03:29 -04:00
parent f718d28239
commit 1ebe1bc2e2
7 changed files with 732 additions and 324 deletions

View File

@ -1,12 +1,9 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Gradle: commons-io:commons-io:2.5"> <library name="Gradle: commons-io:commons-io:2.5">
<CLASSES> <CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.5/2852e6e05fbb95076fc091f6d1780f1f8fe35e0f/commons-io-2.5.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/2.5/commons-io-2.5.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/2.5/commons-io-2.5.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.5/caf033a4a7c37b4a8ff3ea084cba591539b0b69/commons-io-2.5-sources.jar!/" />
</SOURCES>
</library> </library>
</component> </component>

View File

@ -1,11 +1,9 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Gradle: net.sf.trove4j:trove4j:3.0.3"> <library name="Gradle: net.sf.trove4j:trove4j:3.0.3">
<CLASSES> <CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.sf.trove4j/trove4j/3.0.3/42ccaf4761f0dfdfa805c9e340d99a755907e2dd/trove4j-3.0.3.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.sf.trove4j/trove4j/3.0.3/109c5be93362e6e651e417c51d1863477a22969c/trove4j-3.0.3-sources.jar!/" />
</SOURCES>
</library> </library>
</component> </component>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Rixa:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="1.0" type="JAVA_MODULE" version="4"> <module external.linked.project.id="Rixa:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="1.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/../../out/production/classes" /> <output url="file://$MODULE_DIR$/../../build/classes/main" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../../src/main"> <content url="file://$MODULE_DIR$/../../src/main">
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Rixa:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="1.0" type="JAVA_MODULE" version="4"> <module external.linked.project.id="Rixa:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="1.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output-test url="file://$MODULE_DIR$/../../out/test/classes" /> <output-test url="file://$MODULE_DIR$/../../build/classes/test" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../../src/test"> <content url="file://$MODULE_DIR$/../../src/test">
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />

File diff suppressed because it is too large Load Diff

View File

@ -218,18 +218,23 @@ public class MusicCommand implements CommandExec {
} else if (message.length == 3) { } else if (message.length == 3) {
if(message[1].equalsIgnoreCase("join")) { if(message[1].equalsIgnoreCase("join")) {
VoiceChannel chan = null; VoiceChannel chan = null;
if (guild.getVoiceChannelsByName(message[2], true).size() >= 1) { StringBuilder stringBuilder = new StringBuilder();
chan = guild.getVoiceChannelsByName(message[2], true).get(0); for (int i = 2; i < message.length; i++) {
stringBuilder.append(message[i]).append(" ");
}
String channelName = stringBuilder.toString();
if (guild.getVoiceChannelsByName(channelName, true).size() >= 1) {
chan = guild.getVoiceChannelsByName(channelName, true).get(0);
} else { } else {
for (VoiceChannel voiceChannel : guild.getVoiceChannels()) { for (VoiceChannel voiceChannel : guild.getVoiceChannels()) {
if (voiceChannel.getName().contains(message[2]) || voiceChannel.getId().equalsIgnoreCase(message[2])) { if (voiceChannel.getName().contains(channelName) || voiceChannel.getId().equalsIgnoreCase(channelName)) {
chan = voiceChannel; chan = voiceChannel;
break; break;
} }
} }
} }
if (chan == null) { if (chan == null) {
new MessageBuilder("Sorry I was unable to find the VoiceChannel: `" + message[2] + "`.").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder("Sorry I was unable to find the VoiceChannel: `" + channelName + "`.").setColor(event.getMember().getColor()).queue(event.getChannel());
} else { } else {
guild.getAudioManager().setSendingHandler(mng.sendHandler); guild.getAudioManager().setSendingHandler(mng.sendHandler);
try { try {

View File

@ -11,8 +11,9 @@ import java.sql.SQLException;
public class DatabaseManager { public class DatabaseManager {
private Connection connection = null; private Connection connection;
private MySQL MYSQL = null; private MySQL MYSQL = null;
public DatabaseManager(String hostName, String port, String databaseName, String userName, String password) { public DatabaseManager(String hostName, String port, String databaseName, String userName, String password) {
MYSQL = new MySQL(hostName, port, databaseName, userName, password); MYSQL = new MySQL(hostName, port, databaseName, userName, password);
} }
@ -32,6 +33,8 @@ public class DatabaseManager {
PreparedStatement ps = connection.prepareStatement( PreparedStatement ps = connection.prepareStatement(
"CREATE TABLE IF NOT EXISTS `core` (`guild_id` varchar(255) NOT NULL, `guild_name` varchar(255) NOT NULL, PRIMARY KEY (`guild_id`));"); "CREATE TABLE IF NOT EXISTS `core` (`guild_id` varchar(255) NOT NULL, `guild_name` varchar(255) NOT NULL, PRIMARY KEY (`guild_id`));");
ps.executeUpdate(); ps.executeUpdate();
ps.close();
connection.close();
} catch (SQLException e) { } catch (SQLException e) {
Rixa.getInstance().getLogger().severe("Could not check if table exists, stopping server."); Rixa.getInstance().getLogger().severe("Could not check if table exists, stopping server.");
e.printStackTrace(); e.printStackTrace();
@ -41,20 +44,20 @@ public class DatabaseManager {
private void checkConnection() { private void checkConnection() {
try { try {
if(!MYSQL.checkConnection()) { if (!MYSQL.checkConnection()) {
connection = MYSQL.openConnection(); connection = MYSQL.openConnection();
} }
} catch(ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public Result executeUpdate(PreparedStatement ps) { public Result executeUpdate(PreparedStatement ps) throws SQLException {
checkConnection(); checkConnection();
try { try {
ps.executeUpdate(); ps.executeUpdate();
return Result.SUCCESS; return Result.SUCCESS;
} catch(SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
return Result.ERROR; return Result.ERROR;
} }
@ -74,7 +77,7 @@ public class DatabaseManager {
public ResultSet getObject(PreparedStatement ps) throws SQLException { public ResultSet getObject(PreparedStatement ps) throws SQLException {
checkConnection(); checkConnection();
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
if(rs.next()) { if (rs.next()) {
return rs; return rs;
} }
return null; return null;
@ -93,40 +96,38 @@ public class DatabaseManager {
public int getCount(String table) { public int getCount(String table) {
checkConnection(); checkConnection();
ResultSet rs;
try { try {
PreparedStatement ps = connection.prepareStatement("SELECT count(*) FROM '" + table + "';"); PreparedStatement preparedStatement = connection.prepareStatement("SELECT count(*) FROM '" + table + "';");
rs = ps.executeQuery(); ResultSet resultSet = preparedStatement.executeQuery();
if (rs.next()) { if (resultSet.next()) {
return rs.getInt(1); return resultSet.getInt(1);
} }
preparedStatement.close();
resultSet.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
return 0; return 0;
} }
public Result checkExists(String string) { public Result checkExists(String string) throws SQLException {
checkConnection(); checkConnection();
try { PreparedStatement preparedStatement = connection.prepareStatement(string);
PreparedStatement ps = connection.prepareStatement(string); ResultSet resultSet = preparedStatement.executeQuery();
ResultSet rs = ps.executeQuery(); if (resultSet.next()) {
if(rs.next()) {
return Result.TRUE; return Result.TRUE;
}else { } else {
return Result.FALSE; return Result.FALSE;
} }
} catch (SQLException e) {
return Result.ERROR;
}
} }
public Result insert(String string) { public Result insert(String string) {
checkConnection(); checkConnection();
PreparedStatement ps;
try { try {
ps = connection.prepareStatement(string); PreparedStatement preparedStatement = connection.prepareStatement(string);
ps.executeUpdate(); preparedStatement.executeUpdate();
preparedStatement.close();
return Result.SUCCESS; return Result.SUCCESS;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();