Search in sources :

Example 1 with CommandStateException

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

the class DisconnectModule method disconnectCommand.

@BotCommand(command = "disconnect", module = "Disconnect Module", description = "Disconnect user(s) from their voice channel.", usage = "Disconnect [User] ", permissions = Permissions.VOICE_MOVE_MEMBERS)
public static void disconnectCommand(CommandContext cc) throws CommandException {
    IUser user = UserUtil.findUser(cc.getMessage(), 12);
    if (user == null)
        throw new CommandArgumentException("The user you specified was unable to be found!");
    if (user.getVoiceStateForGuild(cc.getGuild()).getChannel() == null)
        throw new CommandStateException("The user you specified is not connected to a voice channel!");
    IVoiceChannel temp = cc.getGuild().createVoiceChannel("Disconnect");
    user.moveToVoiceChannel(temp);
    temp.delete();
    cc.getMessage().delete();
}
Also used : IUser(sx.blah.discord.handle.obj.IUser) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel) BotCommand(com.discordbolt.api.command.BotCommand)

Example 2 with CommandStateException

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

the class NowPlayingCommand method nowPlayingCommand.

@BotCommand(command = "nowplaying", aliases = { "np", "current", "playing" }, module = MusicModule.MODULE, description = "View what is currently playing", usage = "NowPlaying", allowedChannels = "music")
public static void nowPlayingCommand(CommandContext cc) throws CommandException {
    AudioTrack at = MusicModule.getVoiceManager().getNowPlaying(cc.getGuild());
    if (at == null)
        throw new CommandStateException("Nothing is currently playing. Play something with !Play");
    IMessage nowPlayingMessage = cc.replyWith(MusicModule.createPlayingEmbed(cc.getGuild(), MusicModule.getVoiceManager().getNowPlaying(cc.getGuild())));
    ChannelUtil.addReaction(nowPlayingMessage, new Emoji[] { EmojiManager.getForAlias(":black_right_pointing_double_triangle_with_vertical_bar:"), EmojiManager.getForAlias(":star:") });
    MusicModule.getVoiceManager().putNowPlayingMessage(nowPlayingMessage, MusicModule.getVoiceManager().getNowPlaying(cc.getGuild()));
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BotCommand(com.discordbolt.api.command.BotCommand)

Example 3 with CommandStateException

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

the class PlayCommand method playCommand.

@BotCommand(command = "play", module = MusicModule.MODULE, description = "Queue up the requested song", usage = "Play {URL}", allowedChannels = "music", minArgs = 1, maxArgs = 2)
public static void playCommand(CommandContext cc) throws CommandException {
    if (cc.getArgCount() == 1) {
        if (!MusicModule.getVoiceManager().isPaused(cc.getGuild()))
            throw new CommandStateException("I am not paused!");
        MusicModule.getVoiceManager().unpause(cc.getGuild(), cc.getAuthor());
    } else {
        MusicModule.getVoiceManager().queue(cc.getGuild(), cc.getAuthor(), cc.getArgument(1));
        cc.replyWith("Your song is now being queued up");
    }
}
Also used : CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 4 with CommandStateException

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

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

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