Search in sources :

Example 36 with CommandId

use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.

the class PickaxeCommand method info.

@Command(value = "info", aliases = { "information" }, description = "View information on a users pickaxe")
@CommandId(362)
@Examples({ "pickaxe info", "pickaxe info @Shea#6653", "pickaxe info Shea" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void info(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
    Member effectiveMember = member == null ? event.getMember() : member;
    User user = member == null ? event.getAuthor() : effectiveMember.getUser();
    Bson filter = Filters.and(Filters.eq("userId", effectiveMember.getIdLong()), Filters.eq("item.type", ItemType.PICKAXE.getId()));
    Document data = event.getMongo().getItem(filter, Projections.include("item"));
    if (data == null) {
        event.replyFailure("That user does not have a pickaxe").queue();
        return;
    }
    Pickaxe pickaxe = Pickaxe.fromData(event.getBot().getEconomyManager(), data.get("item", Document.class));
    EmbedBuilder embed = new EmbedBuilder().setAuthor(user.getName() + "'s " + pickaxe.getName(), null, user.getEffectiveAvatarUrl()).setColor(effectiveMember.getColorRaw()).setThumbnail("https://emojipedia-us.s3.amazonaws.com/thumbs/120/twitter/131/pick_26cf.png").addField("Durability", pickaxe.getDurability() + "/" + pickaxe.getMaxDurability(), false).addField("Current Price", String.format("$%,d", pickaxe.getCurrentPrice()), false).addField("Price", String.format("$%,d", pickaxe.getPrice()), false).addField("Yield", String.format("$%,d to $%,d", pickaxe.getMinYield(), pickaxe.getMaxYield()), false).addField("Multiplier", NumberUtility.DEFAULT_DECIMAL_FORMAT.format(pickaxe.getMultiplier()), false);
    event.reply(embed.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) User(net.dv8tion.jda.api.entities.User) Pickaxe(com.sx4.bot.entities.economy.item.Pickaxe) Document(org.bson.Document) Member(net.dv8tion.jda.api.entities.Member) Bson(org.bson.conversions.Bson) 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 37 with CommandId

use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.

the class PickaxeCommand method upgrades.

@Command(value = "upgrades", description = "View all the upgrades you can use on a pickaxe")
@CommandId(428)
@Examples({ "pickaxe upgrades" })
public void upgrades(Sx4CommandEvent event) {
    EnumSet<Upgrade> upgrades = Upgrade.getUpgrades(ItemType.PICKAXE);
    PagedResult<Upgrade> paged = new PagedResult<>(event.getBot(), Arrays.asList(upgrades.toArray(Upgrade[]::new))).setPerPage(3).setCustomFunction(page -> {
        EmbedBuilder embed = new EmbedBuilder().setTitle("Pickaxe Upgrades");
        page.forEach((upgrade, index) -> embed.addField(upgrade.getName(), upgrade.getDescription(), false));
        return new MessageBuilder().setEmbeds(embed.build());
    });
    paged.execute(event);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) Upgrade(com.sx4.bot.entities.economy.upgrade.Upgrade) PagedResult(com.sx4.bot.paged.PagedResult) 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 38 with CommandId

use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.

the class PickaxeCommand method upgrade.

@Command(value = "upgrade", description = "Upgrade your pickaxe by a certain attribute")
@CommandId(427)
@Examples({ "pickaxe upgrade money", "pickaxe upgrade multiplier 10", "pickaxe upgrade durability 5" })
public void upgrade(Sx4CommandEvent event, @Argument(value = "upgrade") Upgrade upgrade, @Argument(value = "upgrades") @DefaultNumber(1) @Limit(min = 1, max = 100) int upgrades) {
    if (!upgrade.containsType(ItemType.PICKAXE)) {
        event.replyFailure("You can not use that upgrade on a pickaxe").queue();
        return;
    }
    event.getMongo().withTransaction(session -> {
        Document data = event.getMongo().getItems().find(session, Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.type", ItemType.PICKAXE.getId()))).first();
        if (data == null) {
            event.replyFailure("You do not have a pickaxe").queue();
            session.abortTransaction();
            return null;
        }
        Document item = data.get("item", Document.class);
        Pickaxe defaultPickaxe = event.getBot().getEconomyManager().getItemById(item.getInteger("id"), Pickaxe.class);
        Pickaxe pickaxe = new Pickaxe(item, defaultPickaxe);
        int currentUpgrades = pickaxe.getUpgrades();
        long price = 0;
        for (int i = 0; i < upgrades; i++) {
            price += Math.round(0.015D * defaultPickaxe.getPrice() * currentUpgrades++ + 0.025D * defaultPickaxe.getPrice());
        }
        UpdateResult result = event.getMongo().getUsers().updateOne(session, Filters.eq("_id", event.getAuthor().getIdLong()), List.of(EconomyUtility.decreaseBalanceUpdate(price)));
        if (result.getModifiedCount() == 0) {
            event.replyFormat("You do not have **$%,d** %s", price, event.getConfig().getFailureEmote()).queue();
            session.abortTransaction();
            return null;
        }
        List<Bson> update = new ArrayList<>();
        update.add(Operators.set("item.upgrades", Operators.add(Operators.ifNull("$item.upgrades", 0), upgrades)));
        update.add(Operators.set("item.price", Operators.add("$item.price", Math.round(defaultPickaxe.getPrice() * 0.015D) * upgrades)));
        if (upgrade == Upgrade.MONEY) {
            int increase = (int) Math.round(defaultPickaxe.getMinYield() * upgrade.getValue()) * upgrades;
            update.add(Operators.set("item.minYield", Operators.add("$item.minYield", increase)));
            update.add(Operators.set("item.maxYield", Operators.add("$item.maxYield", increase)));
        } else if (upgrade == Upgrade.DURABILITY) {
            int increase = (int) upgrade.getValue() * upgrades;
            update.add(Operators.set("item.durability", Operators.add("$item.durability", increase)));
            update.add(Operators.set("item.maxDurability", Operators.add("$item.maxDurability", increase)));
        } else if (upgrade == Upgrade.MULTIPLIER) {
            double increase = defaultPickaxe.getMultiplier() * upgrade.getValue() * upgrades;
            update.add(Operators.set("item.multiplier", Operators.add("$item.multiplier", increase)));
        }
        event.getMongo().getItems().updateOne(session, Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.id", pickaxe.getId())), update);
        return String.format("You just upgraded %s %d time%s for your `%s` for **$%,d**", upgrade.getName().toLowerCase(), upgrades, (upgrades == 1 ? "" : "s"), pickaxe.getName(), price);
    }).whenComplete((message, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception) || message == null) {
            return;
        }
        event.replySuccess(message).queue();
    });
}
Also used : Document(org.bson.Document) EconomyUtility(com.sx4.bot.utility.EconomyUtility) Arrays(java.util.Arrays) CancelException(com.sx4.bot.waiter.exception.CancelException) Command(com.jockie.bot.core.command.Command) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) Permission(net.dv8tion.jda.api.Permission) CraftItem(com.sx4.bot.entities.economy.item.CraftItem) CommandId(com.sx4.bot.annotations.command.CommandId) CompletableFuture(java.util.concurrent.CompletableFuture) Member(net.dv8tion.jda.api.entities.Member) PagedResult(com.sx4.bot.paged.PagedResult) User(net.dv8tion.jda.api.entities.User) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson) Alternative(com.sx4.bot.entities.argument.Alternative) ItemStack(com.sx4.bot.entities.economy.item.ItemStack) ButtonUtility(com.sx4.bot.utility.ButtonUtility) UpdateResult(com.mongodb.client.result.UpdateResult) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) Pickaxe(com.sx4.bot.entities.economy.item.Pickaxe) Button(net.dv8tion.jda.api.interactions.components.Button) AlternativeOptions(com.sx4.bot.annotations.argument.AlternativeOptions) Waiter(com.sx4.bot.waiter.Waiter) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) com.mongodb.client.model(com.mongodb.client.model) BotPermissions(com.sx4.bot.annotations.command.BotPermissions) EnumSet(java.util.EnumSet) Argument(com.jockie.bot.core.argument.Argument) Limit(com.sx4.bot.annotations.argument.Limit) Upgrade(com.sx4.bot.entities.economy.upgrade.Upgrade) Operators(com.sx4.bot.database.mongo.model.Operators) ItemType(com.sx4.bot.entities.economy.item.ItemType) Sx4Command(com.sx4.bot.core.Sx4Command) NumberUtility(com.sx4.bot.utility.NumberUtility) CompletionException(java.util.concurrent.CompletionException) TimeoutException(com.sx4.bot.waiter.exception.TimeoutException) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Collectors(java.util.stream.Collectors) ModuleCategory(com.sx4.bot.category.ModuleCategory) List(java.util.List) DefaultNumber(com.sx4.bot.annotations.argument.DefaultNumber) Examples(com.sx4.bot.annotations.command.Examples) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) Pickaxe(com.sx4.bot.entities.economy.item.Pickaxe) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.bson.Document) UpdateResult(com.mongodb.client.result.UpdateResult) 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 39 with CommandId

use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.

the class ShopCommand method list.

@Command(value = "list", description = "View what items the bot has")
@CommandId(455)
@Examples({ "shop list" })
public void list(Sx4CommandEvent event) {
    List<Bson> pipeline = List.of(Aggregates.match(Filters.and(Filters.eq("userId", event.getSelfUser().getIdLong()), Filters.ne("amount", 0))), Aggregates.project(Projections.fields(Projections.computed("name", "$item.name"), Projections.computed("type", "$item.type"), Projections.include("item", "amount"))), Aggregates.sort(Sorts.descending("amount")));
    event.getMongo().aggregateItems(pipeline).whenComplete((items, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        EmbedBuilder embed = new EmbedBuilder().setAuthor("Shop List", null, event.getSelfUser().getEffectiveAvatarUrl()).setColor(event.getSelfMember().getColorRaw());
        if (items.isEmpty()) {
            event.replyFailure("That user does not have any items").queue();
            return;
        }
        Map<ItemType, StringJoiner> types = new HashMap<>();
        for (Document item : items) {
            ItemType type = ItemType.fromId(item.getInteger("type"));
            ItemStack<?> stack = new ItemStack<>(event.getBot().getEconomyManager(), item);
            types.compute(type, (key, value) -> (value == null ? new StringJoiner("\n") : value).add(stack.toString()));
        }
        types.forEach((type, joiner) -> embed.addField(type.getName(), joiner.toString(), true));
        event.reply(embed.build()).queue();
    });
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Document(org.bson.Document) Bson(org.bson.conversions.Bson) 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 40 with CommandId

use of com.sx4.bot.annotations.command.CommandId in project Sx4 by sx4-discord-bot.

the class MarriageCommand method info.

@Command(value = "info", description = "Get info on a marriage with one of your partners")
@CommandId(272)
@Examples({ "marriage info @Shea#6653", "marriage info Shea", "marriage info 402557516728369153" })
public void info(Sx4CommandEvent event, @Argument(value = "user", endless = true) Member member) {
    User author = event.getAuthor();
    Bson filter = Filters.or(Filters.and(Filters.eq("proposerId", member.getIdLong()), Filters.eq("partnerId", author.getIdLong())), Filters.and(Filters.eq("proposerId", author.getIdLong()), Filters.eq("partnerId", member.getIdLong())));
    Document marriage = event.getMongo().getMarriage(filter, Projections.include("proposerId"));
    if (marriage == null) {
        event.replyFailure("You are not married to that user").queue();
        return;
    }
    EmbedBuilder embed = new EmbedBuilder().setAuthor(author.getName() + " \u2764\uFE0F " + member.getUser().getName(), null, author.getEffectiveAvatarUrl()).addField("Proposer", author.getIdLong() == marriage.getLong("proposerId") ? author.getAsTag() : member.getUser().getAsTag(), false).addField("Marriage Time", OffsetDateTime.ofInstant(Instant.ofEpochSecond(marriage.getObjectId("_id").getTimestamp()), ZoneOffset.UTC).format(this.formatter), false);
    event.reply(embed.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) User(net.dv8tion.jda.api.entities.User) Document(org.bson.Document) Bson(org.bson.conversions.Bson) 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

Command (com.jockie.bot.core.command.Command)146 Sx4Command (com.sx4.bot.core.Sx4Command)146 CommandId (com.sx4.bot.annotations.command.CommandId)103 Examples (com.sx4.bot.annotations.command.Examples)101 Document (org.bson.Document)100 Bson (org.bson.conversions.Bson)87 PagedResult (com.sx4.bot.paged.PagedResult)69 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)69 Argument (com.jockie.bot.core.argument.Argument)50 ModuleCategory (com.sx4.bot.category.ModuleCategory)50 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)50 User (net.dv8tion.jda.api.entities.User)50 AuthorPermissions (com.sx4.bot.annotations.command.AuthorPermissions)48 Permission (net.dv8tion.jda.api.Permission)48 BotPermissions (com.sx4.bot.annotations.command.BotPermissions)42 Operators (com.sx4.bot.database.mongo.model.Operators)40 ExceptionUtility (com.sx4.bot.utility.ExceptionUtility)40 CompletionException (java.util.concurrent.CompletionException)38 TextChannel (net.dv8tion.jda.api.entities.TextChannel)38 AlternativeOptions (com.sx4.bot.annotations.argument.AlternativeOptions)37