Search in sources :

Example 6 with Command

use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.

the class FreeGamesCommand method platforms.

@Command(value = "platforms", description = "Select what platforms you want notifications from")
@CommandId(491)
@Examples({ "free games platforms #channel STEAM", "free games platforms STEAM EPIC_GAMES" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void platforms(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true) TextChannel channel, @Argument(value = "platforms") FreeGameType... types) {
    TextChannel effectiveChannel = channel == null ? event.getTextChannel() : channel;
    long raw = FreeGameType.getRaw(types);
    event.getMongo().updateFreeGameChannel(Filters.eq("channelId", effectiveChannel.getIdLong()), Updates.set("platforms", raw), new UpdateOptions()).whenComplete((result, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        if (result.getMatchedCount() == 0) {
            event.replyFailure("You do not have a free game channel in " + effectiveChannel.getAsMention()).queue();
            return;
        }
        if (result.getModifiedCount() == 0) {
            event.replyFailure("That free game channel already uses those platforms").queue();
            return;
        }
        event.replySuccess("That free game channel will now send notifications from those platforms").queue();
    });
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Example 7 with Command

use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.

the class FreeGamesCommand method toggle.

@Command(value = "toggle", description = "Enables/disables a free game channel")
@CommandId(484)
@Examples({ "free games toggle", "free games toggle #channel" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void toggle(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true, endless = true) TextChannel channel) {
    TextChannel effectiveChannel = channel == null ? event.getTextChannel() : channel;
    List<Bson> update = List.of(Operators.set("enabled", Operators.cond(Operators.exists("$enabled"), Operators.REMOVE, false)));
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().projection(Projections.include("enabled")).returnDocument(ReturnDocument.AFTER);
    event.getMongo().findAndUpdateFreeGameChannel(Filters.eq("channelId", effectiveChannel.getIdLong()), update, options).whenComplete((data, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        event.replySuccess("The free game channel in " + effectiveChannel.getAsMention() + " is now **" + (data.get("enabled", true) ? "enabled" : "disabled") + "**").queue();
    });
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) Bson(org.bson.conversions.Bson) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Example 8 with Command

use of com.jockie.bot.core.command.Command in project Sx4 by sx4-discord-bot.

the class FreeGamesCommand method add.

@Command(value = "add", description = "Add a channel to get free game notifications from Epic Games")
@CommandId(474)
@Examples({ "free games add", "free games add #channel" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
@Canary
public void add(Sx4CommandEvent event, @Argument(value = "channel", nullDefault = true, endless = true) TextChannel channel) {
    TextChannel effectiveChannel = channel == null ? event.getTextChannel() : channel;
    Document data = new Document("channelId", effectiveChannel.getIdLong()).append("guildId", event.getGuild().getIdLong());
    event.getMongo().insertFreeGameChannel(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("You already have a free games channel in " + effectiveChannel.getAsMention()).queue();
            return;
        }
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        event.replySuccess("Free game notifications will now be sent in " + effectiveChannel.getAsMention()).queue();
    });
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) MongoWriteException(com.mongodb.MongoWriteException) CompletionException(java.util.concurrent.CompletionException) Document(org.bson.Document) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Example 9 with Command

use of com.jockie.bot.core.command.Command 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) ReturnDocument(com.mongodb.client.model.ReturnDocument) 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 10 with Command

use of com.jockie.bot.core.command.Command 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) Command(com.jockie.bot.core.command.Command) Permission(net.dv8tion.jda.api.Permission) Projections(com.mongodb.client.model.Projections) CraftItem(com.sx4.bot.entities.economy.item.CraftItem) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) CommandId(com.sx4.bot.annotations.command.CommandId) Member(net.dv8tion.jda.api.entities.Member) PagedResult(com.sx4.bot.paged.PagedResult) User(net.dv8tion.jda.api.entities.User) ArrayList(java.util.ArrayList) Filters(com.mongodb.client.model.Filters) Bson(org.bson.conversions.Bson) Alternative(com.sx4.bot.entities.argument.Alternative) ItemStack(com.sx4.bot.entities.economy.item.ItemStack) Button(net.dv8tion.jda.api.interactions.components.buttons.Button) UpdateResult(com.mongodb.client.result.UpdateResult) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) Pickaxe(com.sx4.bot.entities.economy.item.Pickaxe) AlternativeOptions(com.sx4.bot.annotations.argument.AlternativeOptions) 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) ReturnDocument(com.mongodb.client.model.ReturnDocument) 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) CustomButtonId(com.sx4.bot.entities.interaction.CustomButtonId) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) ButtonType(com.sx4.bot.entities.interaction.ButtonType) Pickaxe(com.sx4.bot.entities.economy.item.Pickaxe) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) 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)

Aggregations

Command (com.jockie.bot.core.command.Command)178 Sx4Command (com.sx4.bot.core.Sx4Command)178 CommandId (com.sx4.bot.annotations.command.CommandId)118 Examples (com.sx4.bot.annotations.command.Examples)116 Document (org.bson.Document)113 Bson (org.bson.conversions.Bson)97 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)82 PagedResult (com.sx4.bot.paged.PagedResult)71 AuthorPermissions (com.sx4.bot.annotations.command.AuthorPermissions)59 Argument (com.jockie.bot.core.argument.Argument)53 ModuleCategory (com.sx4.bot.category.ModuleCategory)53 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)53 Permission (net.dv8tion.jda.api.Permission)52 BotPermissions (com.sx4.bot.annotations.command.BotPermissions)46 ExceptionUtility (com.sx4.bot.utility.ExceptionUtility)43 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)43 User (net.dv8tion.jda.api.entities.User)43 Operators (com.sx4.bot.database.mongo.model.Operators)41 Collectors (java.util.stream.Collectors)36 AlternativeOptions (com.sx4.bot.annotations.argument.AlternativeOptions)31