Search in sources :

Example 1 with Playlist

use of com.discordbolt.boltbot.modules.music.playlists.Playlist in project BoltBot by DiscordBolt.

the class PlayCommand method playPlaylist.

@BotCommand(command = { "play", "-p" }, module = MusicModule.MODULE, description = "Queue up the requested playlist", usage = "Play playlist {number/name}", allowedChannels = "music", minArgs = 2, maxArgs = 100)
public static void playPlaylist(CommandContext cc) throws CommandException {
    if (cc.getArgCount() == 2) {
        Playlist current = MusicModule.getPlaylistManager().getSelectedPlaylist(cc.getAuthor().getLongID());
        if (current == null)
            throw new CommandStateException("You do not have a selected playlist to queue!");
        MusicModule.getVoiceManager().queue(cc.getGuild(), cc.getAuthor(), current);
        cc.replyWith("Your playlist is now being queued and may take ~30 seconds to fully appear in the queue.");
    } else {
        String playlistRequest = cc.combineArgs(2, cc.getArgCount() - 1);
        if (playlistRequest.contains(":")) {
            String playlistTitle = playlistRequest.split(":")[0];
            String playlistNumber = playlistRequest.split(":")[1];
            int songNumber;
            try {
                songNumber = Integer.valueOf(playlistNumber);
            } catch (NumberFormatException e) {
                throw new CommandArgumentException("\"" + playlistRequest.split(":")[1] + "\" is not a valid number!");
            }
            Playlist toPlay = MusicModule.getPlaylistManager().getPlaylist(playlistTitle).orElse(null);
            if (toPlay == null)
                throw new CommandArgumentException("\"" + playlistTitle + "\" could not be found!");
            if (songNumber < 1 || songNumber > toPlay.getSongIDs().size())
                throw new CommandArgumentException("\"" + songNumber + "\" is not a valid number for \"" + toPlay.getTitle() + "\"");
            MusicModule.getVoiceManager().queue(cc.getGuild(), cc.getAuthor(), toPlay.getSongIDs().get(songNumber - 1));
        } else {
            Playlist toPlay = MusicModule.getPlaylistManager().getPlaylist(playlistRequest).orElse(null);
            if (toPlay == null)
                throw new CommandArgumentException("\"" + playlistRequest + "\" could not be found!");
            MusicModule.getVoiceManager().queue(cc.getGuild(), cc.getAuthor(), toPlay);
            cc.replyWith("Your playlist is now being queued and may take ~30 seconds to fully appear in the queue.");
        }
    }
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 2 with Playlist

use of com.discordbolt.boltbot.modules.music.playlists.Playlist in project BoltBot by DiscordBolt.

the class PlaylistCommand method playlistRemoveCommand.

@BotCommand(command = { "playlist", "remove" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "Remove a song from your selected playlist", usage = "Playlist remove [number/URL]", allowedChannels = "music", args = 3)
public static void playlistRemoveCommand(CommandContext cc) throws CommandException {
    Playlist selectedPlaylist = MusicModule.getPlaylistManager().getSelectedPlaylist(cc.getAuthor().getLongID());
    if (selectedPlaylist == null)
        throw new CommandStateException(NO_PLAYLIST_SELECTED);
    if (cc.getArgument(2).matches("^-?\\d+$")) {
        selectedPlaylist.removeSong(cc.getAuthor(), Integer.valueOf(cc.getArgument(2)) - 1);
    } else {
        selectedPlaylist.removeSong(cc.getAuthor(), cc.getArgument(2));
    }
    cc.replyWith("Successfully removed the song from " + selectedPlaylist.getTitle() + ".");
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 3 with Playlist

use of com.discordbolt.boltbot.modules.music.playlists.Playlist in project BoltBot by DiscordBolt.

the class PlaylistCommand method playlistViewCommand.

@BotCommand(command = { "playlist", "view" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "View a playlist's details", usage = "Playlist view {name}", allowedChannels = "music", minArgs = 2, maxArgs = 100)
public static void playlistViewCommand(CommandContext cc) throws CommandException {
    if (cc.getArgCount() == 2) {
        Playlist playlist = MusicModule.getPlaylistManager().getSelectedPlaylist(cc.getAuthor().getLongID());
        if (playlist == null)
            throw new CommandStateException(NO_PLAYLIST_SELECTED);
        cc.replyWith(playlist.toEmbed());
    } else {
        Optional<Playlist> playlist = MusicModule.getPlaylistManager().getPlaylist(getPlaylistName(cc));
        if (!playlist.isPresent())
            throw new CommandArgumentException(NO_SUCH_PLAYLIST);
        cc.replyWith(playlist.get().toEmbed());
    }
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 4 with Playlist

use of com.discordbolt.boltbot.modules.music.playlists.Playlist in project BoltBot by DiscordBolt.

the class PlaylistCommand method playlistShareCommand.

@BotCommand(command = { "playlist", "share" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "Give another user access to add/remove songs", usage = "Playlist share [@User]", allowedChannels = "music", args = 3)
public static void playlistShareCommand(CommandContext cc) throws CommandException {
    Playlist selectedPlaylist = MusicModule.getPlaylistManager().getSelectedPlaylist(cc.getAuthor().getLongID());
    if (selectedPlaylist == null)
        throw new CommandStateException(NO_PLAYLIST_SELECTED);
    if (cc.getMessage().getMentions().size() != 1) {
        cc.sendUsage();
        return;
    }
    selectedPlaylist.addContributor(cc.getAuthor(), cc.getMessage().getMentions().get(0));
    cc.replyWith("Successfully added " + cc.getMessage().getMentions().get(0).getName() + " as a contributor to playlist " + selectedPlaylist.getTitle());
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 5 with Playlist

use of com.discordbolt.boltbot.modules.music.playlists.Playlist in project BoltBot by DiscordBolt.

the class DJ method starSong.

public void starSong(AudioTrack track, IUser user) throws CommandStateException, CommandPermissionException {
    if (track == null || user == null)
        throw new CommandStateException("That track can not be found.");
    Playlist playlist = MusicModule.getPlaylistManager().getSelectedPlaylist(user.getLongID());
    if (playlist == null)
        throw new CommandStateException("You must have a selected playlist to save a song!");
    playlist.addSong(user, track.getInfo().uri);
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException)

Aggregations

Playlist (com.discordbolt.boltbot.modules.music.playlists.Playlist)12 BotCommand (com.discordbolt.api.command.BotCommand)9 CommandStateException (com.discordbolt.api.command.exceptions.CommandStateException)8 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)4 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 IUser (sx.blah.discord.handle.obj.IUser)2 com.discordbolt.api.command.exceptions (com.discordbolt.api.command.exceptions)1 MusicModule (com.discordbolt.boltbot.modules.music.MusicModule)1 ChannelUtil (com.discordbolt.boltbot.utils.ChannelUtil)1 ExceptionMessage (com.discordbolt.boltbot.utils.ExceptionMessage)1 StandardAudioDataFormats (com.sedmelluq.discord.lavaplayer.format.StandardAudioDataFormats)1 AudioConfiguration (com.sedmelluq.discord.lavaplayer.player.AudioConfiguration)1 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)1 AudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager)1 DefaultAudioPlayerManager (com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager)1 AudioSourceManagers (com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers)1 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)1 HashMap (java.util.HashMap)1 List (java.util.List)1