Search in sources :

Example 26 with Or

use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.

the class FishingRodCommand method shop.

@Command(value = "shop", description = "View all the fishing rods you are able to buy or craft")
@CommandId(379)
@Examples({ "fishing rod shop" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void shop(Sx4CommandEvent event) {
    List<Rod> rods = event.getBot().getEconomyManager().getItems(Rod.class);
    PagedResult<Rod> paged = new PagedResult<>(event.getBot(), rods).setPerPage(12).setCustomFunction(page -> {
        EmbedBuilder embed = new EmbedBuilder().setAuthor("Fishing Rod Shop", null, event.getSelfUser().getEffectiveAvatarUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setDescription("Fishing rods are a good way to gain some money").setFooter(PagedResult.DEFAULT_FOOTER_TEXT);
        page.forEach((rod, index) -> {
            List<ItemStack<CraftItem>> items = rod.getCraft();
            String craft = items.isEmpty() ? "None" : items.stream().map(ItemStack::toString).collect(Collectors.joining("\n"));
            embed.addField(rod.getName(), String.format("Price: $%,d\nCraft: %s\nDurability: %,d", rod.getPrice(), craft, rod.getMaxDurability()), true);
        });
        return new MessageBuilder().setEmbeds(embed.build());
    });
    paged.execute(event);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) Rod(com.sx4.bot.entities.economy.item.Rod) ItemStack(com.sx4.bot.entities.economy.item.ItemStack) PagedResult(com.sx4.bot.paged.PagedResult) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 27 with Or

use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.

the class AxeCommand method shop.

@Command(value = "shop", description = "View all the axes you are able to buy or craft")
@CommandId(388)
@Examples({ "axe shop" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void shop(Sx4CommandEvent event) {
    List<Axe> axes = event.getBot().getEconomyManager().getItems(Axe.class);
    PagedResult<Axe> paged = new PagedResult<>(event.getBot(), axes).setPerPage(12).setCustomFunction(page -> {
        EmbedBuilder embed = new EmbedBuilder().setAuthor("Axe Shop", null, event.getSelfUser().getEffectiveAvatarUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setDescription("Axes are a good way to get some wood for crafting").setFooter(PagedResult.DEFAULT_FOOTER_TEXT);
        page.forEach((axe, index) -> {
            List<ItemStack<CraftItem>> items = axe.getCraft();
            String craft = items.isEmpty() ? "None" : items.stream().map(ItemStack::toString).collect(Collectors.joining("\n"));
            embed.addField(axe.getName(), String.format("Price: $%,d\nCraft: %s\nDurability: %,d", axe.getPrice(), craft, axe.getMaxDurability()), true);
        });
        return new MessageBuilder().setEmbeds(embed.build());
    });
    paged.execute(event);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) ItemStack(com.sx4.bot.entities.economy.item.ItemStack) PagedResult(com.sx4.bot.paged.PagedResult) Axe(com.sx4.bot.entities.economy.item.Axe) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 28 with Or

use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.

the class PickaxeCommand method shop.

@Command(value = "shop", description = "View all the pickaxes you are able to buy or craft")
@CommandId(360)
@Examples({ "pickaxe shop" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void shop(Sx4CommandEvent event) {
    List<Pickaxe> pickaxes = event.getBot().getEconomyManager().getItems(Pickaxe.class);
    PagedResult<Pickaxe> paged = new PagedResult<>(event.getBot(), pickaxes).setPerPage(12).setCustomFunction(page -> {
        EmbedBuilder embed = new EmbedBuilder().setAuthor("Pickaxe Shop", null, event.getSelfUser().getEffectiveAvatarUrl()).setTitle("Page " + page.getPage() + "/" + page.getMaxPage()).setDescription("Pickaxes are a good way to gain some extra money aswell as some materials").setFooter(PagedResult.DEFAULT_FOOTER_TEXT);
        page.forEach((pickaxe, index) -> {
            List<ItemStack<CraftItem>> items = pickaxe.getCraft();
            String craft = items.isEmpty() ? "None" : items.stream().map(ItemStack::toString).collect(Collectors.joining("\n"));
            embed.addField(pickaxe.getName(), String.format("Price: $%,d\nCraft: %s\nDurability: %,d", pickaxe.getPrice(), craft, pickaxe.getMaxDurability()), true);
        });
        return new MessageBuilder().setEmbeds(embed.build());
    });
    paged.execute(event);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) Pickaxe(com.sx4.bot.entities.economy.item.Pickaxe) ItemStack(com.sx4.bot.entities.economy.item.ItemStack) PagedResult(com.sx4.bot.paged.PagedResult) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 29 with Or

use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.

the class AutoRoleCommand method add.

@Command(value = "add", description = "Add a role to be given when a user joins")
@CommandId(39)
@Examples({ "auto role add @Role", "auto role add Role", "auto role add 406240455622262784" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
public void add(Sx4CommandEvent event, @Argument(value = "role", endless = true) Role role) {
    if (role.isManaged()) {
        event.replyFailure("You cannot add a managed role as an auto role").queue();
        return;
    }
    if (role.isPublicRole()) {
        event.replyFailure("You cannot add the @everyone role as an auto role").queue();
        return;
    }
    if (!event.getSelfMember().canInteract(role)) {
        event.replyFailure("You cannot add an auto role higher or equal than my top role").queue();
        return;
    }
    if (!event.getMember().canInteract(role)) {
        event.replyFailure("You cannot give n auto role higher or equal than your top role").queue();
        return;
    }
    Document data = new Document("roleId", role.getIdLong()).append("guildId", event.getGuild().getIdLong());
    event.getMongo().insertAutoRole(data).whenComplete((result, exception) -> {
        Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
        if (cause instanceof MongoWriteException && ((MongoWriteException) cause).getError().getCategory() == ErrorCategory.DUPLICATE_KEY) {
            event.replyFailure("That role is already an auto role").queue();
            return;
        }
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        event.replySuccess("The role " + role.getAsMention() + " has been added as an auto role").queue();
    });
}
Also used : MongoWriteException(com.mongodb.MongoWriteException) CompletionException(java.util.concurrent.CompletionException) Document(org.bson.Document) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 30 with Or

use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.

the class AntiRegexCommand method formatters.

@Command(value = "formatters", aliases = { "format", "formatting" }, description = "Get all the formatters for anti regex you can use")
@CommandId(468)
@Examples({ "anti regex formatters" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void formatters(Sx4CommandEvent event) {
    EmbedBuilder embed = new EmbedBuilder().setAuthor("Anti-Regex Formatters", null, event.getSelfUser().getEffectiveAvatarUrl());
    FormatterManager manager = FormatterManager.getDefaultManager();
    StringJoiner content = new StringJoiner("\n");
    for (FormatterVariable<?> variable : manager.getVariables(User.class)) {
        content.add("`{user." + variable.getName() + "}` - " + variable.getDescription());
    }
    for (FormatterVariable<?> variable : manager.getVariables(TextChannel.class)) {
        content.add("`{channel." + variable.getName() + "}` - " + variable.getDescription());
    }
    content.add("`{regex.id}` - Gets the id of the regex");
    content.add("`{regex.action.name}` - Gets the mod action name if one is set");
    content.add("`{regex.action.exists}` - Returns true or false if an action exists");
    content.add("`{regex.attempts.current}` - Gets the current attempts for the user");
    content.add("`{regex.attempts.max}` - Gets the max attempts set for the anti regex");
    embed.setDescription(content.toString());
    event.reply(embed.build()).queue();
}
Also used : FormatterManager(com.sx4.bot.formatter.FormatterManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) StringJoiner(java.util.StringJoiner) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Aggregations

Sx4Command (com.sx4.bot.core.Sx4Command)36 Command (com.jockie.bot.core.command.Command)25 Document (org.bson.Document)25 Argument (com.jockie.bot.core.argument.Argument)19 ModuleCategory (com.sx4.bot.category.ModuleCategory)19 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)19 Bson (org.bson.conversions.Bson)17 CommandId (com.sx4.bot.annotations.command.CommandId)16 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)16 Examples (com.sx4.bot.annotations.command.Examples)15 PagedResult (com.sx4.bot.paged.PagedResult)15 Permission (net.dv8tion.jda.api.Permission)15 Member (net.dv8tion.jda.api.entities.Member)13 List (java.util.List)12 CompletionException (java.util.concurrent.CompletionException)10 Option (com.jockie.bot.core.option.Option)8 Collectors (java.util.stream.Collectors)8 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)8 AlternativeOptions (com.sx4.bot.annotations.argument.AlternativeOptions)7 Operators (com.sx4.bot.database.mongo.model.Operators)7