diff --git a/pom.xml b/pom.xml
index 482faaf..e72c71f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.github.andrewlalis
HandieBot
- 1.5.3
+ 1.6.0
diff --git a/src/main/java/handiebot/command/commands/music/PlayCommand.java b/src/main/java/handiebot/command/commands/music/PlayCommand.java
index c55957d..5dd6502 100644
--- a/src/main/java/handiebot/command/commands/music/PlayCommand.java
+++ b/src/main/java/handiebot/command/commands/music/PlayCommand.java
@@ -1,19 +1,26 @@
package handiebot.command.commands.music;
import com.google.api.services.youtube.model.Video;
+import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
+import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
+import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
+import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import handiebot.HandieBot;
import handiebot.command.CommandContext;
+import handiebot.command.Commands;
import handiebot.command.ReactionHandler;
import handiebot.command.reactionListeners.YoutubePlayListener;
import handiebot.command.types.ContextCommand;
import handiebot.lavaplayer.playlist.UnloadedTrack;
import handiebot.utils.MessageUtils;
import handiebot.utils.YoutubeSearch;
+import handiebot.view.BotLog;
import sx.blah.discord.handle.obj.IMessage;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ExecutionException;
import static handiebot.HandieBot.resourceBundle;
import static handiebot.utils.MessageUtils.sendMessage;
@@ -39,11 +46,50 @@ public class PlayCommand extends ContextCommand {
} else {
//Check if an actual URL is used, and if not, create a youtube request.
if (context.getArgs()[0].startsWith("http")) {
- try {
- HandieBot.musicPlayer.addToQueue(context.getGuild(), new UnloadedTrack(context.getArgs()[0]), context.getUser());
- } catch (Exception e) {
- sendMessage(MessageFormat.format(resourceBundle.getString("commands.command.play.songAddError"), context.getArgs()[0]), context.getChannel());
- e.printStackTrace();
+ if (context.getArgs()[0].contains("list") && Commands.hasPermission(context, 8)){
+ try {
+ HandieBot.musicPlayer.getPlayerManager().loadItem(context.getArgs()[0], new AudioLoadResultHandler() {
+ @Override
+ public void trackLoaded(AudioTrack track) {
+ //This should not happen.
+ HandieBot.log.log(BotLog.TYPE.ERROR, "Loaded song while attempting to load playlist.");
+ }
+
+ @Override
+ public void playlistLoaded(AudioPlaylist playlist) {
+ //This is expected to happen.
+ HandieBot.log.log(BotLog.TYPE.MUSIC, "Loading a playlist named: "+playlist.getName()+" with "+playlist.getTracks().size()+" tracks.");
+ MessageUtils.sendMessage("Songs from the playlist **"+playlist.getName()+"** have been added to the queue.", context.getChannel());
+ HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.clearQueue();
+ for (AudioTrack track : playlist.getTracks()){
+ HandieBot.log.log(BotLog.TYPE.MUSIC, "Added song from playlist: "+track.getInfo().title);
+ HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.getActivePlaylist().addTrack(new UnloadedTrack(track));
+ }
+ }
+
+ @Override
+ public void noMatches() {
+ //Error that nothing was found.
+ HandieBot.log.log(BotLog.TYPE.ERROR, "No matches while loading playlist.");
+ }
+
+ @Override
+ public void loadFailed(FriendlyException exception) {
+ //Error that loading failed.
+ HandieBot.log.log(BotLog.TYPE.ERROR, "Loading failed while loading playlist.");
+ }
+ }).get();
+ HandieBot.musicPlayer.playQueue(context.getGuild());
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
+ } else {
+ try {
+ HandieBot.musicPlayer.addToQueue(context.getGuild(), new UnloadedTrack(context.getArgs()[0]), context.getUser());
+ } catch (Exception e) {
+ sendMessage(MessageFormat.format(resourceBundle.getString("commands.command.play.songAddError"), context.getArgs()[0]), context.getChannel());
+ e.printStackTrace();
+ }
}
} else {
//Construct a Youtube song choice.
diff --git a/src/main/java/handiebot/command/commands/music/QueueCommand.java b/src/main/java/handiebot/command/commands/music/QueueCommand.java
index 56da85c..7be6d2a 100644
--- a/src/main/java/handiebot/command/commands/music/QueueCommand.java
+++ b/src/main/java/handiebot/command/commands/music/QueueCommand.java
@@ -37,6 +37,7 @@ public class QueueCommand extends ContextCommand {
@Override
public void execute(CommandContext context) {
+ //TODO: Ensure that queue embed never runs out of space.
if (context.getArgs().length > 0){
switch (context.getArgs()[0]){
case ("all"):
@@ -74,6 +75,7 @@ public class QueueCommand extends ContextCommand {
} else {
sendMessage(resourceBundle.getString("commands.command.queue.remove.error"), context.getChannel());
}
+ break;
case ("move"):
if (context.getArgs().length == 3 && Commands.hasPermission(context, 8)){
int startIndex = Integer.parseInt(context.getArgs()[1]);
@@ -92,6 +94,7 @@ public class QueueCommand extends ContextCommand {
} else {
sendMessage(resourceBundle.getString("commands.command.queue.move.error"), context.getChannel());
}
+ break;
}
} else {
HandieBot.musicPlayer.showQueueList(context.getGuild(), false);
diff --git a/src/main/java/handiebot/lavaplayer/playlist/UnloadedTrack.java b/src/main/java/handiebot/lavaplayer/playlist/UnloadedTrack.java
index 247a6a6..f680856 100644
--- a/src/main/java/handiebot/lavaplayer/playlist/UnloadedTrack.java
+++ b/src/main/java/handiebot/lavaplayer/playlist/UnloadedTrack.java
@@ -17,7 +17,7 @@ import static handiebot.HandieBot.log;
* This is useful for quickly loading playlists and only loading a track when it is needed.
*/
public class UnloadedTrack implements Cloneable {
-
+//TODO: Externalize strings.
private String title;
private String url;
private long duration;