Argument support for joining channels (untested) resultseta and preparedstatements closing
This commit is contained in:
parent
f718d28239
commit
1ebe1bc2e2
@ -1,12 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: commons-io:commons-io:2.5">
|
||||
<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!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<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>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,11 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Gradle: net.sf.trove4j:trove4j:3.0.3">
|
||||
<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>
|
||||
<JAVADOC />
|
||||
<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>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -1,7 +1,7 @@
|
||||
<?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">
|
||||
<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 />
|
||||
<content url="file://$MODULE_DIR$/../../src/main">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?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">
|
||||
<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 />
|
||||
<content url="file://$MODULE_DIR$/../../src/test">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -218,18 +218,23 @@ public class MusicCommand implements CommandExec {
|
||||
} else if (message.length == 3) {
|
||||
if(message[1].equalsIgnoreCase("join")) {
|
||||
VoiceChannel chan = null;
|
||||
if (guild.getVoiceChannelsByName(message[2], true).size() >= 1) {
|
||||
chan = guild.getVoiceChannelsByName(message[2], true).get(0);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
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 {
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
guild.getAudioManager().setSendingHandler(mng.sendHandler);
|
||||
try {
|
||||
|
@ -11,8 +11,9 @@ import java.sql.SQLException;
|
||||
|
||||
public class DatabaseManager {
|
||||
|
||||
private Connection connection = null;
|
||||
private Connection connection;
|
||||
private MySQL MYSQL = null;
|
||||
|
||||
public DatabaseManager(String hostName, String port, String databaseName, String userName, String password) {
|
||||
MYSQL = new MySQL(hostName, port, databaseName, userName, password);
|
||||
}
|
||||
@ -32,6 +33,8 @@ public class DatabaseManager {
|
||||
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`));");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
Rixa.getInstance().getLogger().severe("Could not check if table exists, stopping server.");
|
||||
e.printStackTrace();
|
||||
@ -41,20 +44,20 @@ public class DatabaseManager {
|
||||
|
||||
private void checkConnection() {
|
||||
try {
|
||||
if(!MYSQL.checkConnection()) {
|
||||
if (!MYSQL.checkConnection()) {
|
||||
connection = MYSQL.openConnection();
|
||||
}
|
||||
} catch(ClassNotFoundException | SQLException e) {
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Result executeUpdate(PreparedStatement ps) {
|
||||
public Result executeUpdate(PreparedStatement ps) throws SQLException {
|
||||
checkConnection();
|
||||
try {
|
||||
ps.executeUpdate();
|
||||
return Result.SUCCESS;
|
||||
} catch(SQLException e) {
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return Result.ERROR;
|
||||
}
|
||||
@ -74,7 +77,7 @@ public class DatabaseManager {
|
||||
public ResultSet getObject(PreparedStatement ps) throws SQLException {
|
||||
checkConnection();
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs.next()) {
|
||||
if (rs.next()) {
|
||||
return rs;
|
||||
}
|
||||
return null;
|
||||
@ -93,40 +96,38 @@ public class DatabaseManager {
|
||||
|
||||
public int getCount(String table) {
|
||||
checkConnection();
|
||||
ResultSet rs;
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement("SELECT count(*) FROM '" + table + "';");
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
return rs.getInt(1);
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT count(*) FROM '" + table + "';");
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt(1);
|
||||
}
|
||||
preparedStatement.close();
|
||||
resultSet.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Result checkExists(String string) {
|
||||
public Result checkExists(String string) throws SQLException {
|
||||
checkConnection();
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement(string);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs.next()) {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(string);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
return Result.TRUE;
|
||||
}else {
|
||||
} else {
|
||||
return Result.FALSE;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
return Result.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Result insert(String string) {
|
||||
checkConnection();
|
||||
PreparedStatement ps;
|
||||
try {
|
||||
ps = connection.prepareStatement(string);
|
||||
ps.executeUpdate();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(string);
|
||||
preparedStatement.executeUpdate();
|
||||
preparedStatement.close();
|
||||
return Result.SUCCESS;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user