Search in sources :

Example 16 with CommandStateException

use of com.discordbolt.api.command.exceptions.CommandStateException 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)

Example 17 with CommandStateException

use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.

the class Playlist method addSong.

public String addSong(IUser requester, String songID) throws CommandStateException, CommandPermissionException {
    if (!(ownerID.equals(requester.getLongID()) || contributors.contains(requester.getLongID())))
        throw new CommandPermissionException("You are not allowed to add songs to " + this.getTitle() + ".");
    if (songs.containsKey(songID))
        throw new CommandStateException("That song is already in this playlist!");
    String songTitle = MusicModule.getVoiceManager().getSongTitle(songID);
    songs.put(songID, songTitle);
    PlaylistManager.writePlaylistFile(this);
    return songTitle;
}
Also used : CommandPermissionException(com.discordbolt.api.command.exceptions.CommandPermissionException) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException)

Example 18 with CommandStateException

use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.

the class Playlist method addContributor.

public void addContributor(IUser requestor, IUser contributor) throws CommandStateException, CommandPermissionException {
    if (!ownerID.equals(requestor.getLongID()))
        throw new CommandPermissionException("You are not allowed to add contributors to " + this.getTitle() + ".");
    if (contributors.contains(contributor.getLongID()))
        throw new CommandStateException(contributor.getName() + " is already a contributor to " + this.getTitle() + ".");
    contributors.add(contributor.getLongID());
    PlaylistManager.writePlaylistFile(this);
}
Also used : CommandPermissionException(com.discordbolt.api.command.exceptions.CommandPermissionException) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException)

Example 19 with CommandStateException

use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.

the class PlaylistManager method createPlaylist.

public Playlist createPlaylist(String title, IUser owner, IGuild guild) throws CommandStateException {
    if (playlists.stream().filter(p -> p.getTitle().equalsIgnoreCase(title)).findAny().isPresent())
        throw new CommandStateException("There already exists a playlist with that title!");
    Playlist pl = new Playlist(title, owner, guild);
    // Saves the playlist to disk
    writePlaylistFile(pl);
    playlists.add(pl);
    Collections.sort(playlists);
    return pl;
}
Also used : CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException)

Example 20 with CommandStateException

use of com.discordbolt.api.command.exceptions.CommandStateException in project BoltBot by DiscordBolt.

the class DJ method removeStar.

public void removeStar(IMessage message, IUser user) throws CommandStateException, CommandPermissionException {
    if (message == null || user == null || !trackMessages.containsKey(message))
        throw new CommandStateException("That track can not be found.");
    AudioTrack track = trackMessages.get(message);
    Playlist playlist = MusicModule.getPlaylistManager().getSelectedPlaylist(user.getLongID());
    if (playlist == null)
        throw new CommandStateException("You must have a selected playlist to unsave a song!");
    playlist.removeSong(user, track);
}
Also used : Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Aggregations

CommandStateException (com.discordbolt.api.command.exceptions.CommandStateException)21 BotCommand (com.discordbolt.api.command.BotCommand)12 Playlist (com.discordbolt.boltbot.modules.music.playlists.Playlist)8 CommandPermissionException (com.discordbolt.api.command.exceptions.CommandPermissionException)6 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)5 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)3 TagData (com.discordbolt.boltbot.system.mysql.data.persistent.TagData)2 CommandContext (com.discordbolt.api.command.CommandContext)1 CommandException (com.discordbolt.api.command.exceptions.CommandException)1 MusicModule (com.discordbolt.boltbot.modules.music.MusicModule)1 TimeUtil (com.discordbolt.boltbot.utils.TimeUtil)1 List (java.util.List)1 IMessage (sx.blah.discord.handle.obj.IMessage)1 IUser (sx.blah.discord.handle.obj.IUser)1 IVoiceChannel (sx.blah.discord.handle.obj.IVoiceChannel)1 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)1