Search in sources :

Example 11 with CommandStateException

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

the class Playlist method removeSong.

public void removeSong(IUser requester, int index) throws CommandPermissionException, CommandStateException {
    if (!(ownerID.equals(requester.getLongID()) || contributors.contains(requester.getLongID())))
        throw new CommandPermissionException("You are not allowed to remove songs from " + this.getTitle() + ".");
    if (index < 0 || index >= songs.size())
        throw new CommandStateException(index + " is not a valid index!");
    songs.remove(getSongIDs().get(index));
    PlaylistManager.writePlaylistFile(this);
}
Also used : CommandPermissionException(com.discordbolt.api.command.exceptions.CommandPermissionException) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException)

Example 12 with CommandStateException

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

Example 13 with CommandStateException

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

the class DJ method skip.

public boolean skip(IUser requester) throws CommandStateException {
    if (votesToSkip.contains(requester))
        throw new CommandStateException("You have already voted to skip the current song!");
    votesToSkip.add(requester);
    // Filter out users who have voted but are no longer connected to the voice channel
    votesToSkip.removeIf(u -> u.getVoiceStateForGuild(guild).getChannel() != getVoiceChannel());
    if ((double) votesToSkip.size() / (double) (getVoiceChannel().getConnectedUsers().size() - 1) >= MusicModule.VOTE_SKIP_PERCENT) {
        skipCurrentTrack();
        votesToSkip.clear();
        return true;
    }
    return false;
}
Also used : CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException)

Example 14 with CommandStateException

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

the class TagModule method tagEditCommand.

@BotCommand(command = { "tag", "edit" }, description = "Edits a Tag", usage = "Tag edit [tag]", module = "Tag Module", minArgs = 4, maxArgs = 100)
public static void tagEditCommand(CommandContext cc) throws CommandException {
    Optional<TagData> tag = TagData.getById(cc.getGuild().getLongID(), cc.getArgument(2));
    if (!tag.isPresent())
        throw new CommandStateException("That tag does not exist!");
    if (tag.get().getUserId() != cc.getAuthor().getLongID())
        throw new CommandPermissionException("You do not have permission to edit this tag!");
    tag.get().setContent(cc.combineArgs(3, cc.getArgCount() - 1));
    cc.replyWith("Successfully updated your tag. Use `" + getTagPrefix(cc.getGuild()) + tag.get().getName() + "` to view it.");
}
Also used : CommandPermissionException(com.discordbolt.api.command.exceptions.CommandPermissionException) TagData(com.discordbolt.boltbot.system.mysql.data.persistent.TagData) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 15 with CommandStateException

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

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