From 62988e9a40674a8f8ca5e51de07bdba2fbe27569 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Fri, 1 Sep 2017 11:10:42 +0200 Subject: [PATCH] Added playnow command to play a song immediately. --- .../commands/music/PlayNowCommand.java | 79 +++++++++++++++++++ src/main/resources/Strings.properties | 1 + src/main/resources/Strings_nl.properties | 1 + 3 files changed, 81 insertions(+) create mode 100644 src/main/java/handiebot/command/commands/music/PlayNowCommand.java diff --git a/src/main/java/handiebot/command/commands/music/PlayNowCommand.java b/src/main/java/handiebot/command/commands/music/PlayNowCommand.java new file mode 100644 index 0000000..a0bf26d --- /dev/null +++ b/src/main/java/handiebot/command/commands/music/PlayNowCommand.java @@ -0,0 +1,79 @@ +package handiebot.command.commands.music; + +import com.google.api.services.youtube.model.Video; +import handiebot.HandieBot; +import handiebot.command.CommandContext; +import handiebot.command.ReactionHandler; +import handiebot.command.reactionListeners.YoutubeChoiceListener; +import handiebot.command.types.ContextCommand; +import handiebot.lavaplayer.TrackScheduler; +import handiebot.lavaplayer.playlist.UnloadedTrack; +import handiebot.utils.MessageUtils; +import handiebot.utils.YoutubeSearch; +import sx.blah.discord.handle.obj.IMessage; + +import java.util.ArrayList; +import java.util.List; + +import static handiebot.HandieBot.resourceBundle; +import static handiebot.utils.MessageUtils.sendMessage; +import static handiebot.utils.YoutubeSearch.WATCH_URL; + +/** + * @author Andrew Lalis + * Command to make a song play immediately. + */ +public class PlayNowCommand extends ContextCommand { +//TODO: Externalize strings. + public PlayNowCommand() { + super("playnow", + "", + resourceBundle.getString("commands.command.playnow.description"), + 8); + } + + @Override + public void execute(CommandContext context) { + if (context.getArgs().length < 1){ + sendMessage("You must provide a URL or series of words to search.", context.getChannel()); + } + if (context.getArgs()[0].startsWith("http")) { + //The user has given only a URL. + try { + playTrackNow(new UnloadedTrack(context.getArgs()[0]), context); + } catch (Exception e) { + e.printStackTrace(); + sendMessage("Unable to load the song.", context.getChannel()); + } + } else { + //The user has given a search query. + List