Search in sources :

Example 6 with Playlist

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

the class PlaylistCommand method playlistListCommand.

@BotCommand(command = { "playlist", "list" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "List all stored playlists", usage = "Playlist list", allowedChannels = "music", args = 2)
public static void playlistListCommand(CommandContext cc) throws CommandException {
    EmbedBuilder embed = new EmbedBuilder();
    embed.withColor(MusicModule.EMBED_COLOR);
    embed.withAuthorName("Playlists");
    List<Playlist> playlists = MusicModule.getPlaylistManager().getPlaylists();
    embed.withTitle("Number of Playlists:");
    embed.withDescription(playlists.size() + "");
    IUser currentUser = null;
    StringBuilder sb = new StringBuilder();
    int id = 1;
    for (Playlist pl : playlists) {
        if (currentUser == null || !pl.getOwnerID().equals(currentUser.getLongID())) {
            if (currentUser != null)
                embed.appendField(currentUser.getName(), sb.toString(), false);
            sb.setLength(0);
            currentUser = pl.getOwner();
        }
        if (sb.length() != 0)
            sb.append('\n');
        sb.append(id++).append(". ").append(pl.getTitle());
    }
    if (currentUser != null)
        embed.appendField(currentUser.getName(), sb.toString(), false);
    cc.replyWith(embed.build());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) IUser(sx.blah.discord.handle.obj.IUser) BotCommand(com.discordbolt.api.command.BotCommand)

Example 7 with Playlist

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

the class PlaylistCommand method playlistSelectCommand.

@BotCommand(command = { "playlist", "select" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "Select a playlist", usage = "Playlist select [number/name]", allowedChannels = "music", minArgs = 3, maxArgs = 100)
public static void playlistSelectCommand(CommandContext cc) throws CommandException {
    if (cc.getArgCount() == 3 && cc.getArgument(2).matches("^-?\\d+$")) {
        int playlistIndex = Integer.valueOf(cc.getArgument(2)) - 1;
        Playlist playlist = MusicModule.getPlaylistManager().getPlaylist(playlistIndex);
        MusicModule.getPlaylistManager().setSelectedPlaylist(cc.getAuthor().getLongID(), playlist);
        cc.replyWith("Successfully selected " + playlist.getTitle() + " by " + playlist.getOwner().getName() + " as your selected playlist.");
    } else {
        Optional<Playlist> playlist = MusicModule.getPlaylistManager().getPlaylist(getPlaylistName(cc));
        if (!playlist.isPresent())
            throw new CommandArgumentException(NO_SUCH_PLAYLIST);
        MusicModule.getPlaylistManager().setSelectedPlaylist(cc.getAuthor().getLongID(), playlist.get());
        cc.replyWith("Successfully selected " + playlist.get().getTitle() + " by " + playlist.get().getOwner().getName() + " as your selected playlist.");
    }
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 8 with Playlist

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

the class PlaylistCommand method playlistAddCommand.

@BotCommand(command = { "playlist", "add" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "Add a song to your selected playlist", usage = "Playlist add [URL]", allowedChannels = "music", args = 3)
public static void playlistAddCommand(CommandContext cc) throws CommandException {
    Playlist selectedPlaylist = MusicModule.getPlaylistManager().getSelectedPlaylist(cc.getAuthor().getLongID());
    if (selectedPlaylist == null)
        throw new CommandStateException(NO_PLAYLIST_SELECTED);
    String title = selectedPlaylist.addSong(cc.getAuthor(), cc.getArgument(2));
    cc.replyWith("Added \"" + title + "\" to " + 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 9 with Playlist

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

the class PlaylistCommand method playlistCreateCommand.

@BotCommand(command = { "playlist", "create" }, module = MusicModule.MODULE, aliases = "pl", description = "Create a new playlist", usage = "Playlist create [name]", allowedChannels = "music", minArgs = 3, maxArgs = 100)
public static void playlistCreateCommand(CommandContext cc) throws CommandException {
    String title = getPlaylistName(cc);
    if (title.length() > 250)
        throw new CommandArgumentException("Playlist titles can only be 250 characters long.");
    if (!title.matches("[a-zA-Z0-9 ]+"))
        throw new CommandArgumentException("Playlist titles can only contain alphanumeric characters and spaces.");
    Playlist playlist = MusicModule.getPlaylistManager().createPlaylist(title, cc.getAuthor(), cc.getGuild());
    MusicModule.getPlaylistManager().setSelectedPlaylist(cc.getAuthor().getLongID(), playlist);
    cc.replyWith("Successfully created playlist: " + playlist.getTitle());
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 10 with Playlist

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

the class PlaylistCommand method playlistUnshareCommand.

@BotCommand(command = { "playlist", "unshare" }, module = MusicModule.MODULE, aliases = "pl", allowPM = true, description = "Remove another user's access to add/remove songs", usage = "Playlist unshare [@User]", allowedChannels = "music", args = 3)
public static void playlistUnshareCommand(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.removeContributor(cc.getAuthor(), cc.getMessage().getMentions().get(0));
    cc.replyWith("Successfully removed " + cc.getMessage().getMentions().get(0).getName() + " from being 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)

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