|
|
|
@ -83,11 +83,8 @@ public class Main extends ListenerAdapter |
|
|
|
|
{ |
|
|
|
|
String arg = content.substring("!join ".length()); |
|
|
|
|
onJoinCommand(event, guild, arg); |
|
|
|
|
} |
|
|
|
|
else if (content.equals("!join")) |
|
|
|
|
{ |
|
|
|
|
} else if (content.equals("!join")) |
|
|
|
|
onJoinCommand(event); |
|
|
|
|
} |
|
|
|
|
else if (content.startsWith("!play ")) |
|
|
|
|
{ |
|
|
|
|
String arg = content.substring("!join ".length()); |
|
|
|
@ -111,12 +108,9 @@ public class Main extends ListenerAdapter |
|
|
|
|
{ |
|
|
|
|
connectTo(channel); // Join the channel of the user
|
|
|
|
|
onConnecting(channel, event.getChannel()); // Tell the user about our success
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
} else |
|
|
|
|
onUnknownChannel(event.getChannel(), "your voice channel"); // Tell the user about our failure
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Handle command with arguments. |
|
|
|
@ -133,9 +127,8 @@ public class Main extends ListenerAdapter |
|
|
|
|
boolean isNumber = arg.matches("\\d+"); // This is a regular expression that ensures the input consists of digits
|
|
|
|
|
VoiceChannel channel = null; |
|
|
|
|
if (isNumber) // The input is an id?
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
channel = guild.getVoiceChannelById(arg); |
|
|
|
|
} |
|
|
|
|
if (channel == null) // Then the input must be a name?
|
|
|
|
|
{ |
|
|
|
|
List<VoiceChannel> channels = guild.getVoiceChannelsByName(arg, true); |
|
|
|
@ -171,7 +164,7 @@ public class Main extends ListenerAdapter |
|
|
|
|
|
|
|
|
|
private String downloadSong(String arg) throws IOException, RuntimeException, InterruptedException |
|
|
|
|
{ |
|
|
|
|
String cmd = "/usr/bin/youtube-dl -x --audio-format=wav "+arg; |
|
|
|
|
String cmd = "/usr/bin/youtube-dl -x --audio-format=wav " + arg; |
|
|
|
|
System.out.println("Running command: " + cmd); |
|
|
|
|
// Process exec = Runtime.getRuntime().exec().split(" "));
|
|
|
|
|
Process exec = new ProcessBuilder(cmd.split(" ")).redirectOutput(ProcessBuilder.Redirect.PIPE).start(); |
|
|
|
@ -187,7 +180,6 @@ public class Main extends ListenerAdapter |
|
|
|
|
return destination; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Inform user about successful connection. |
|
|
|
|
* |
|
|
|
@ -205,7 +197,8 @@ public class Main extends ListenerAdapter |
|
|
|
|
* The channel to connect to is not known to us. |
|
|
|
|
* |
|
|
|
|
* @param channel |
|
|
|
|
* The message channel (text channel abstraction) to send failure information to |
|
|
|
|
* The message channel (text channel abstraction) to send failure |
|
|
|
|
* information to |
|
|
|
|
* @param comment |
|
|
|
|
* The information of this channel |
|
|
|
|
*/ |
|
|
|
@ -230,7 +223,6 @@ public class Main extends ListenerAdapter |
|
|
|
|
// EchoHandler handler = new EchoHandler();
|
|
|
|
|
|
|
|
|
|
// The order of the following instructions does not matter!
|
|
|
|
|
|
|
|
|
|
// Set the sending handler to our echo system
|
|
|
|
|
audioManager.setSendingHandler(musicHandler); |
|
|
|
|
// Set the receiving handler to the same echo system, otherwise we can't echo anything
|
|
|
|
|