Search in sources :

Example 1 with CommandArgumentException

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

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

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

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

the class SeenModule method seenCommand.

@BotCommand(command = "seen", module = "Seen Module", description = "See when the user was last online.", usage = "Seen [User]", minArgs = 2, maxArgs = 100)
public static void seenCommand(CommandContext cc) throws CommandException {
    IUser searchUser = UserUtil.findUser(cc.getMessage(), cc.getMessageContent().indexOf(' ') + 1);
    String name = cc.getMessageContent().substring(cc.getMessageContent().indexOf(' ') + 1, cc.getMessageContent().length());
    if (searchUser == null)
        throw new CommandArgumentException("Sorry, I could not find '" + name + "'.");
    Optional<UserData> userData = UserData.getById(searchUser.getLongID());
    if (!userData.isPresent() || userData.get().getLastStatusChange() == null)
        throw new CommandArgumentException("Sorry, I could not find \"" + name + "\".");
    cc.replyWith(searchUser.getName() + " has been " + userData.get().getStatus().name().replace("dnd", "do not disturb").toLowerCase() + " since " + format(userData.get().getLastStatusChange()) + '.');
}
Also used : UserData(com.discordbolt.boltbot.system.mysql.data.persistent.UserData) IUser(sx.blah.discord.handle.obj.IUser) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 5 with CommandArgumentException

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

Aggregations

BotCommand (com.discordbolt.api.command.BotCommand)10 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)10 CommandStateException (com.discordbolt.api.command.exceptions.CommandStateException)4 Playlist (com.discordbolt.boltbot.modules.music.playlists.Playlist)4 IUser (sx.blah.discord.handle.obj.IUser)2 TagData (com.discordbolt.boltbot.system.mysql.data.persistent.TagData)1 UserData (com.discordbolt.boltbot.system.mysql.data.persistent.UserData)1 Matcher (java.util.regex.Matcher)1 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)1 IVoiceChannel (sx.blah.discord.handle.obj.IVoiceChannel)1