Search in sources :

Example 16 with BotCommand

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

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

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

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

the class ListRoles method listRolesCommand.

@BotCommand(command = "ListRoles", module = "Administration", description = "List the roles of the guild and their ID.", usage = "ListRoles", permissions = Permissions.MANAGE_ROLES)
public static void listRolesCommand(CommandContext cc) {
    StringBuilder sb = new StringBuilder("```");
    for (IRole r : cc.getGuild().getRoles()) {
        sb.append(String.format("%-33s%-18s%n", r.getName(), r.getStringID()));
    }
    EmbedBuilder embed = new EmbedBuilder();
    embed.withAuthorName(cc.getGuild().getName() + "'s Roles");
    embed.withAuthorIcon(cc.getGuild().getIconURL());
    embed.withColor(36, 153, 153);
    embed.setLenient(true);
    embed.withFooterIcon(cc.getAuthor().getAvatarURL());
    embed.withFooterText("Requested by " + cc.getAuthor().getName());
    embed.appendDescription(sb.append("```").toString());
    embed.withTimestamp(System.currentTimeMillis());
    cc.replyWith(embed.build());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IRole(sx.blah.discord.handle.obj.IRole) BotCommand(com.discordbolt.api.command.BotCommand)

Example 20 with BotCommand

use of com.discordbolt.api.command.BotCommand 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)20 CommandStateException (com.discordbolt.api.command.exceptions.CommandStateException)12 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)11 Playlist (com.discordbolt.boltbot.modules.music.playlists.Playlist)9 IUser (sx.blah.discord.handle.obj.IUser)3 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)3 TagData (com.discordbolt.boltbot.system.mysql.data.persistent.TagData)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 CommandContext (com.discordbolt.api.command.CommandContext)1 CommandException (com.discordbolt.api.command.exceptions.CommandException)1 CommandPermissionException (com.discordbolt.api.command.exceptions.CommandPermissionException)1 MusicModule (com.discordbolt.boltbot.modules.music.MusicModule)1 UserData (com.discordbolt.boltbot.system.mysql.data.persistent.UserData)1 TimeUtil (com.discordbolt.boltbot.utils.TimeUtil)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)1 IMessage (sx.blah.discord.handle.obj.IMessage)1 IRole (sx.blah.discord.handle.obj.IRole)1 IVoiceChannel (sx.blah.discord.handle.obj.IVoiceChannel)1