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());
}
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.");
}
}
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());
}
}
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`");
}
}
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));
}
Aggregations