Search in sources :

Example 6 with CommandArgumentException

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

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

the class QueueCommand method queueRemoveCommand.

@BotCommand(command = { "queue", "remove" }, module = MusicModule.MODULE, description = "Remove a song from the queue", usage = "Queue remove [number]", allowedChannels = "music", args = 3)
public static void queueRemoveCommand(CommandContext cc) throws CommandException {
    if (!cc.getArgument(2).matches("^-?\\d+$"))
        throw new CommandArgumentException("\"" + cc.getArgument(2) + "\" is not a valid song number.");
    int songIndex = Integer.parseInt(cc.getArgument(2));
    if (songIndex < 1 || songIndex > MusicModule.getVoiceManager().getQueue(cc.getGuild()).size() + 1)
        throw new CommandArgumentException("\"" + cc.getArgument(2) + "\" is not a valid song number.");
    if (songIndex == 1) {
        // just skip
        MusicModule.getVoiceManager().skip(cc.getGuild(), cc.getAuthor(), true, 1);
        cc.replyWith("Song #1: \"" + MusicModule.getVoiceManager().getNowPlaying(cc.getGuild()).getInfo().title + "\" has been removed from the queue.");
    } else {
        MusicModule.getVoiceManager().dequeue(cc.getGuild(), cc.getAuthor(), MusicModule.getVoiceManager().getQueue(cc.getGuild()).get(songIndex - 2).getInfo().identifier);
        cc.replyWith("Song #" + (songIndex) + ": \"" + MusicModule.getVoiceManager().getQueue(cc.getGuild()).get(songIndex - 2).getInfo().title + "\" has been removed from the queue.");
    }
}
Also used : CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 8 with CommandArgumentException

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

the class TagModule method tagAddCommand.

@BotCommand(command = { "tag", "add" }, description = "Adds a Tag", usage = "Tag add [tag]", module = "Tag Module", minArgs = 4, maxArgs = 100)
public static void tagAddCommand(CommandContext cc) throws CommandException {
    try {
        TagData tagData = TagData.create(cc.getGuild().getLongID(), cc.getAuthor().getLongID(), cc.getArgument(2), cc.combineArgs(3, cc.getArgCount() - 1));
        cc.replyWith("Successfully registered your new tag. Use `" + getTagPrefix(cc.getGuild()) + tagData.getName() + "` to view it.");
    } catch (IllegalStateException e) {
        throw new CommandStateException("That tag already exists! Please choose a different tag");
    } catch (IllegalArgumentException e) {
        throw new CommandArgumentException(e.getMessage());
    }
}
Also used : TagData(com.discordbolt.boltbot.system.mysql.data.persistent.TagData) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 9 with CommandArgumentException

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

the class StreamAnnouncer method onCommand.

@BotCommand(command = { "twitch", "announce" }, description = "Enable or disable announcing when you go live.", usage = "Twitch announce true/false", module = "AAAAAAAAAA", args = 3)
public static void onCommand(CommandContext cc) throws CommandException {
    if (cc.getArgument(2).equalsIgnoreCase("true")) {
        UserData.getOrCreate(cc.getAuthor()).setAnnounceStreamingStatus(true);
        cc.replyWith("Enabled announcing of your stream!");
    } else if (cc.getArgument(2).equalsIgnoreCase("false")) {
        UserData.getOrCreate(cc.getAuthor()).setAnnounceStreamingStatus(false);
        cc.replyWith("Disabled annoucing your stream.");
    } else {
        throw new CommandArgumentException("Third argument must be `true` or `false`");
    }
}
Also used : CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 10 with CommandArgumentException

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

the class DiceModule method rollCommand.

@BotCommand(command = "roll", module = "Dice Module", description = "Roll a die!", usage = "Roll [#d##]", args = 2)
public static void rollCommand(CommandContext cc) throws CommandArgumentException {
    Matcher m = DIE_PATTERN.matcher(cc.getArgument(1));
    if (!m.matches()) {
        cc.replyWith("Your die was not formatted correctly. !Roll #d##");
        return;
    }
    int numDice = Integer.valueOf(Optional.ofNullable(m.group(1)).orElse("1"));
    int numSides = Integer.valueOf(Optional.ofNullable(m.group(2)).orElseThrow(() -> new CommandArgumentException("Your die was not formatted correctly. !Roll #d##")));
    if (numDice < 1 || numSides <= 1 || numDice > 100 || numSides > 100) {
        cc.replyWith("Your die has an invalid number of sides.");
        return;
    }
    if (cc.getChannel().getTopic().toLowerCase().contains("--print-rolls")) {
        EmbedObject embed = getDieEmbed(numDice, numSides);
        cc.replyWith(embed.title);
        cc.replyWith(embed);
    } else
        cc.replyWith(getDieEmbed(numDice, numSides));
}
Also used : Matcher(java.util.regex.Matcher) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) 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