Search in sources :

Example 1 with TagData

use of com.discordbolt.boltbot.system.mysql.data.persistent.TagData in project BoltBot by DiscordBolt.

the class TagModule method tagEditCommand.

@BotCommand(command = { "tag", "edit" }, description = "Edits a Tag", usage = "Tag edit [tag]", module = "Tag Module", minArgs = 4, maxArgs = 100)
public static void tagEditCommand(CommandContext cc) throws CommandException {
    Optional<TagData> tag = TagData.getById(cc.getGuild().getLongID(), cc.getArgument(2));
    if (!tag.isPresent())
        throw new CommandStateException("That tag does not exist!");
    if (tag.get().getUserId() != cc.getAuthor().getLongID())
        throw new CommandPermissionException("You do not have permission to edit this tag!");
    tag.get().setContent(cc.combineArgs(3, cc.getArgCount() - 1));
    cc.replyWith("Successfully updated your tag. Use `" + getTagPrefix(cc.getGuild()) + tag.get().getName() + "` to view it.");
}
Also used : CommandPermissionException(com.discordbolt.api.command.exceptions.CommandPermissionException) TagData(com.discordbolt.boltbot.system.mysql.data.persistent.TagData) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) BotCommand(com.discordbolt.api.command.BotCommand)

Example 2 with TagData

use of com.discordbolt.boltbot.system.mysql.data.persistent.TagData 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)

Aggregations

BotCommand (com.discordbolt.api.command.BotCommand)2 CommandStateException (com.discordbolt.api.command.exceptions.CommandStateException)2 TagData (com.discordbolt.boltbot.system.mysql.data.persistent.TagData)2 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)1 CommandPermissionException (com.discordbolt.api.command.exceptions.CommandPermissionException)1