Search in sources :

Example 6 with Alternative

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

the class SelfRoleCommand method remove.

@Command(value = "delete", aliases = { "remove" }, description = "Delete a self role from the current server")
@CommandId(333)
@Examples({ "self role delete @Role", "self role delete Role", "self role delete all" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
public void remove(Sx4CommandEvent event, @Argument(value = "role | all", endless = true) @AlternativeOptions("all") Alternative<Role> option) {
    if (option.isAlternative()) {
        List<Button> buttons = List.of(Button.success("yes", "Yes"), Button.danger("no", "No"));
        event.reply(event.getAuthor().getName() + ", are you sure you want to delete every self role in the server?").setActionRow(buttons).submit().thenCompose(message -> {
            return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor())).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor())).onFailure(e -> ButtonUtility.handleButtonFailure(e, message)).setTimeout(60).start();
        }).whenComplete((e, exception) -> {
            Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
            if (cause instanceof CancelException) {
                GenericEvent cancelEvent = ((CancelException) cause).getEvent();
                if (cancelEvent != null) {
                    ((ButtonClickEvent) cancelEvent).reply("Cancelled " + event.getConfig().getSuccessEmote()).queue();
                }
                return;
            } else if (cause instanceof TimeoutException) {
                event.reply("Timed out :stopwatch:").queue();
                return;
            } else if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            event.getMongo().deleteManySelfRoles(Filters.eq("guildId", event.getGuild().getIdLong())).whenComplete((result, databaseException) -> {
                if (ExceptionUtility.sendExceptionally(event, databaseException)) {
                    return;
                }
                if (result.getDeletedCount() == 0) {
                    event.replyFailure("There are no self roles in this server").queue();
                    return;
                }
                e.reply("All self roles have been deleted " + event.getConfig().getSuccessEmote()).queue();
            });
        });
    } else {
        Role role = option.getValue();
        event.getMongo().deleteSelfRole(Filters.eq("roleId", role.getIdLong())).whenComplete((result, exception) -> {
            if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            event.replySuccess(role.getAsMention() + " is no longer a self role").queue();
        });
    }
}
Also used : Document(org.bson.Document) CancelException(com.sx4.bot.waiter.exception.CancelException) Command(com.jockie.bot.core.command.Command) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) MongoWriteException(com.mongodb.MongoWriteException) Permission(net.dv8tion.jda.api.Permission) Projections(com.mongodb.client.model.Projections) CommandId(com.sx4.bot.annotations.command.CommandId) PagedResult(com.sx4.bot.paged.PagedResult) ArrayList(java.util.ArrayList) Filters(com.mongodb.client.model.Filters) Alternative(com.sx4.bot.entities.argument.Alternative) ButtonUtility(com.sx4.bot.utility.ButtonUtility) Role(net.dv8tion.jda.api.entities.Role) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) 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) RestAction(net.dv8tion.jda.api.requests.RestAction) Argument(com.jockie.bot.core.argument.Argument) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) Sx4Command(com.sx4.bot.core.Sx4Command) CompletionException(java.util.concurrent.CompletionException) TimeoutException(com.sx4.bot.waiter.exception.TimeoutException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ModuleCategory(com.sx4.bot.category.ModuleCategory) List(java.util.List) Examples(com.sx4.bot.annotations.command.Examples) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) ErrorCategory(com.mongodb.ErrorCategory) Role(net.dv8tion.jda.api.entities.Role) Button(net.dv8tion.jda.api.interactions.components.Button) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) CompletionException(java.util.concurrent.CompletionException) CancelException(com.sx4.bot.waiter.exception.CancelException) Waiter(com.sx4.bot.waiter.Waiter) TimeoutException(com.sx4.bot.waiter.exception.TimeoutException) 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 7 with Alternative

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

the class PickaxeCommand method repair.

@Command(value = "repair", description = "Repair your current pickaxe with the material it is made from")
@CommandId(363)
@Examples({ "pickaxe repair 10", "pickaxe repair all" })
public void repair(Sx4CommandEvent event, @Argument(value = "durability") @AlternativeOptions("all") Alternative<Integer> option) {
    Bson filter = Filters.and(Filters.eq("userId", event.getAuthor().getIdLong()), Filters.eq("item.type", ItemType.PICKAXE.getId()));
    Document data = event.getMongo().getItem(filter, Projections.include("item"));
    if (data == null) {
        event.replyFailure("You do not have a pickaxe").queue();
        return;
    }
    Pickaxe pickaxe = Pickaxe.fromData(event.getBot().getEconomyManager(), data.get("item", Document.class));
    CraftItem item = pickaxe.getRepairItem();
    if (item == null) {
        event.replyFailure("That pickaxe is not repairable").queue();
        return;
    }
    int maxDurability = pickaxe.getMaxDurability() - pickaxe.getDurability();
    if (maxDurability <= 0) {
        event.replyFailure("Your pickaxe is already at full durability").queue();
        return;
    }
    int durability;
    if (option.isAlternative()) {
        durability = maxDurability;
    } else {
        int amount = option.getValue();
        if (amount > maxDurability) {
            event.reply("You can only repair your pickaxe by **" + maxDurability + "** durability :no_entry:").queue();
            return;
        }
        durability = amount;
    }
    int itemCount = (int) Math.ceil((((double) pickaxe.getPrice() / item.getPrice()) / pickaxe.getMaxDurability()) * durability);
    List<Button> buttons = List.of(Button.success("yes", "Yes"), Button.danger("no", "No"));
    event.reply("It will cost you `" + itemCount + " " + item.getName() + "` to repair your pickaxe by **" + durability + "** durability, are you sure you want to repair it?").setActionRow(buttons).submit().thenCompose(message -> {
        return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor())).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor())).onFailure(e -> ButtonUtility.handleButtonFailure(e, message)).setTimeout(60).start();
    }).whenComplete((e, exception) -> {
        Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
        if (cause instanceof CancelException) {
            GenericEvent cancelEvent = ((CancelException) cause).getEvent();
            if (cancelEvent != null) {
                ((ButtonClickEvent) cancelEvent).reply("Cancelled " + event.getConfig().getSuccessEmote()).queue();
            }
            return;
        } else if (cause instanceof TimeoutException) {
            event.reply("Timed out :stopwatch:").queue();
            return;
        } else if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        List<Bson> update = List.of(Operators.set("amount", Operators.let(new Document("amount", Operators.ifNull("$amount", 0L)), Operators.cond(Operators.lte(itemCount, "$$amount"), Operators.subtract("$$amount", itemCount), "$$amount"))));
        event.getMongo().updateItem(Filters.and(Filters.eq("item.id", item.getId()), Filters.eq("userId", event.getAuthor().getIdLong())), update, new UpdateOptions()).thenCompose(result -> {
            if (result.getMatchedCount() == 0 || result.getModifiedCount() == 0) {
                e.reply("You do not have `" + itemCount + " " + item.getName() + "` " + event.getConfig().getFailureEmote()).queue();
                return CompletableFuture.completedFuture(null);
            }
            List<Bson> itemUpdate = List.of(Operators.set("item.durability", Operators.cond(Operators.eq("$item.durability", pickaxe.getDurability()), Operators.add("$item.durability", durability), "$item.durability")));
            return event.getMongo().updateItem(Filters.and(Filters.eq("item.id", pickaxe.getId()), Filters.eq("userId", event.getAuthor().getIdLong())), itemUpdate, new UpdateOptions());
        }).whenComplete((result, databaseException) -> {
            if (ExceptionUtility.sendExceptionally(event, databaseException) || result == null) {
                return;
            }
            if (result.getMatchedCount() == 0) {
                e.reply("You no longer have that pickaxe " + event.getConfig().getFailureEmote()).queue();
                return;
            }
            if (result.getMatchedCount() == 0) {
                e.reply("The durability of your pickaxe has changed " + event.getConfig().getFailureEmote()).queue();
                return;
            }
            e.reply("You just repaired your pickaxe by **" + durability + "** durability " + event.getConfig().getSuccessEmote()).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) Document(org.bson.Document) CraftItem(com.sx4.bot.entities.economy.item.CraftItem) Bson(org.bson.conversions.Bson) Button(net.dv8tion.jda.api.interactions.components.Button) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) List(java.util.List) CancelException(com.sx4.bot.waiter.exception.CancelException) Waiter(com.sx4.bot.waiter.Waiter) TimeoutException(com.sx4.bot.waiter.exception.TimeoutException) 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 8 with Alternative

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

the class MarriageCommand method remove.

@Command(value = "remove", description = "Divorce someone you are currently married to")
@CommandId(269)
@Redirects({ "divorce" })
@Examples({ "marriage remove @Shea#6653", "marriage remove Shea", "marriage remove all" })
public void remove(Sx4CommandEvent event, @Argument(value = "user | all", endless = true, nullDefault = true) @AlternativeOptions("all") Alternative<Member> option) {
    User author = event.getAuthor();
    if (option == null) {
        Bson filter = Filters.or(Filters.eq("proposerId", author.getIdLong()), Filters.eq("partnerId", author.getIdLong()));
        List<Document> marriages = event.getMongo().getMarriages(filter, Projections.include("proposerId", "partnerId")).into(new ArrayList<>());
        if (marriages.isEmpty()) {
            event.replyFailure("You are not married to anyone").queue();
            return;
        }
        List<Long> userIds = marriages.stream().map(marriage -> {
            long partnerId = marriage.getLong("partnerId");
            return partnerId == author.getIdLong() ? marriage.getLong("proposerId") : partnerId;
        }).collect(Collectors.toList());
        PagedResult<Long> paged = new PagedResult<>(event.getBot(), userIds).setAuthor("Divorce", null, author.getEffectiveAvatarUrl()).setTimeout(60).setDisplayFunction(userId -> {
            User other = event.getShardManager().getUserById(userId);
            return (other == null ? "Anonymous#0000" : other.getAsTag()) + " (" + userId + ")";
        });
        paged.onTimeout(() -> event.reply("Timed out :stopwatch:").queue());
        paged.onSelect(select -> {
            long userId = select.getSelected();
            Bson deleteFilter = Filters.or(Filters.and(Filters.eq("proposerId", userId), Filters.eq("partnerId", author.getIdLong())), Filters.and(Filters.eq("proposerId", author.getIdLong()), Filters.eq("partnerId", userId)));
            event.getMongo().deleteMarriage(deleteFilter).whenComplete((result, exception) -> {
                if (ExceptionUtility.sendExceptionally(event, exception)) {
                    return;
                }
                User user = event.getShardManager().getUserById(userId);
                event.replySuccess("You are no longer married to **" + (user == null ? "Anonymous#0000" : user.getAsTag()) + "**").queue();
            });
        });
        paged.execute(event);
    } else if (option.isAlternative()) {
        List<Button> buttons = List.of(Button.success("yes", "Yes"), Button.danger("no", "No"));
        event.reply(author.getName() + ", are you sure you want to divorce everyone you are currently married to?").setActionRow(buttons).submit().thenCompose(message -> {
            return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor())).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor())).onFailure(e -> ButtonUtility.handleButtonFailure(e, message)).setTimeout(60).start();
        }).whenComplete((e, exception) -> {
            Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
            if (cause instanceof CancelException) {
                GenericEvent cancelEvent = ((CancelException) cause).getEvent();
                if (cancelEvent != null) {
                    ((ButtonClickEvent) cancelEvent).reply("Cancelled " + event.getConfig().getSuccessEmote()).queue();
                }
                return;
            } else if (cause instanceof TimeoutException) {
                event.reply("Timed out :stopwatch:").queue();
                return;
            } else if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            Bson filter = Filters.or(Filters.eq("proposerId", author.getIdLong()), Filters.eq("partnerId", author.getIdLong()));
            event.getMongo().deleteManyMarriages(filter).whenComplete((result, databaseException) -> {
                if (ExceptionUtility.sendExceptionally(event, databaseException)) {
                    return;
                }
                if (result.getDeletedCount() == 0) {
                    e.reply("You are not married to anyone " + event.getConfig().getFailureEmote()).queue();
                    return;
                }
                e.reply("You are no longer married to anyone " + event.getConfig().getSuccessEmote()).queue();
            });
        });
    } else {
        Member member = option.getValue();
        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())));
        event.getMongo().deleteMarriage(filter).whenComplete((result, exception) -> {
            if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            if (result.getDeletedCount() == 0) {
                event.replyFailure("You are not married to that user").queue();
                return;
            }
            event.replySuccess("You are no longer married to **" + member.getUser().getAsTag() + "**").queue();
        });
    }
}
Also used : Document(org.bson.Document) CancelException(com.sx4.bot.waiter.exception.CancelException) Command(com.jockie.bot.core.command.Command) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) Projections(com.mongodb.client.model.Projections) Cooldown(com.jockie.bot.core.command.Command.Cooldown) 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) Redirects(com.sx4.bot.annotations.command.Redirects) Alternative(com.sx4.bot.entities.argument.Alternative) ButtonUtility(com.sx4.bot.utility.ButtonUtility) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) 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) ZoneOffset(java.time.ZoneOffset) EnumSet(java.util.EnumSet) Argument(com.jockie.bot.core.argument.Argument) Message(net.dv8tion.jda.api.entities.Message) Sx4Command(com.sx4.bot.core.Sx4Command) Updates(com.mongodb.client.model.Updates) CooldownMessage(com.sx4.bot.annotations.command.CooldownMessage) CompletionException(java.util.concurrent.CompletionException) TimeoutException(com.sx4.bot.waiter.exception.TimeoutException) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ModuleCategory(com.sx4.bot.category.ModuleCategory) List(java.util.List) Examples(com.sx4.bot.annotations.command.Examples) OffsetDateTime(java.time.OffsetDateTime) Sorts(com.mongodb.client.model.Sorts) DateTimeFormatter(java.time.format.DateTimeFormatter) StringJoiner(java.util.StringJoiner) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) User(net.dv8tion.jda.api.entities.User) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) Document(org.bson.Document) Bson(org.bson.conversions.Bson) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) CompletionException(java.util.concurrent.CompletionException) ArrayList(java.util.ArrayList) List(java.util.List) CancelException(com.sx4.bot.waiter.exception.CancelException) Member(net.dv8tion.jda.api.entities.Member) TimeoutException(com.sx4.bot.waiter.exception.TimeoutException) Redirects(com.sx4.bot.annotations.command.Redirects) 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 9 with Alternative

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

the class BlacklistCommand method reset.

@Command(value = "reset", description = "Reset the blacklist for a specific role/user in a channel")
@CommandId(181)
@Examples({ "blacklist reset #channel", "blacklist reset all" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void reset(Sx4CommandEvent event, @Argument(value = "channel", endless = true) @AlternativeOptions("all") Alternative<TextChannel> option) {
    List<Bson> update = List.of(Operators.set("holders", Operators.reduce(Operators.ifNull("$holders", Collections.EMPTY_LIST), Collections.EMPTY_LIST, Operators.concatArrays("$$value", Operators.cond(Operators.isEmpty(Operators.ifNull(Operators.first(Operators.map(List.of("$$this"), "$$holder.whitelisted", "holder")), Collections.EMPTY_LIST)), Collections.EMPTY_LIST, List.of(Operators.removeObject("$$this", "blacklisted")))))));
    if (option.isAlternative()) {
        event.getMongo().updateManyBlacklists(Filters.eq("guildId", event.getGuild().getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
            if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            if (result.getModifiedCount() == 0) {
                event.replyFailure("Nothing was blacklisted in this server").queue();
                return;
            }
            event.replySuccess("Reset **" + result.getModifiedCount() + "** channels of their blacklist configurations").queue();
        });
    } else {
        TextChannel channel = option.getValue();
        event.getMongo().updateBlacklist(Filters.eq("channelId", channel.getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
            if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            if (result.getModifiedCount() == 0) {
                event.replyFailure("Nothing was blacklisted in that channel").queue();
                return;
            }
            event.replySuccess("That channel no longer has any blacklists").queue();
        });
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) Bson(org.bson.conversions.Bson) 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 10 with Alternative

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

the class WhitelistCommand method reset.

@Command(value = "reset", description = "Reset the whitelist for a specific role/user in a channel")
@CommandId(186)
@Examples({ "whitelist reset #channel", "whitelist reset all" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void reset(Sx4CommandEvent event, @Argument(value = "channel | all", endless = true) @AlternativeOptions("all") Alternative<TextChannel> option) {
    List<Bson> update = List.of(Operators.set("holders", Operators.reduce(Operators.ifNull("$holders", Collections.EMPTY_LIST), Collections.EMPTY_LIST, Operators.concatArrays("$$value", Operators.cond(Operators.isEmpty(Operators.ifNull(Operators.first(Operators.map(List.of("$$this"), "$$holder.blacklisted", "holder")), Collections.EMPTY_LIST)), Collections.EMPTY_LIST, List.of(Operators.removeObject("$$this", "whitelisted")))))));
    if (option.isAlternative()) {
        event.getMongo().updateManyBlacklists(Filters.eq("guildId", event.getGuild().getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
            if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            if (result.getModifiedCount() == 0) {
                event.replyFailure("Nothing was whitelisted in this server").queue();
                return;
            }
            event.replySuccess("Reset **" + result.getModifiedCount() + "** channels of their whitelist configurations").queue();
        });
    } else {
        TextChannel channel = option.getValue();
        event.getMongo().updateBlacklist(Filters.eq("channelId", channel.getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
            if (ExceptionUtility.sendExceptionally(event, exception)) {
                return;
            }
            if (result.getModifiedCount() == 0) {
                event.replyFailure("Nothing was whitelisted in that channel").queue();
                return;
            }
            event.replySuccess("That channel no longer has any whitelists").queue();
        });
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) Bson(org.bson.conversions.Bson) 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)

Aggregations

Command (com.jockie.bot.core.command.Command)24 Sx4Command (com.sx4.bot.core.Sx4Command)24 Bson (org.bson.conversions.Bson)21 CommandId (com.sx4.bot.annotations.command.CommandId)16 Examples (com.sx4.bot.annotations.command.Examples)16 Document (org.bson.Document)15 Argument (com.jockie.bot.core.argument.Argument)14 AlternativeOptions (com.sx4.bot.annotations.argument.AlternativeOptions)14 ModuleCategory (com.sx4.bot.category.ModuleCategory)14 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)14 Alternative (com.sx4.bot.entities.argument.Alternative)14 PagedResult (com.sx4.bot.paged.PagedResult)13 Permission (net.dv8tion.jda.api.Permission)13 Waiter (com.sx4.bot.waiter.Waiter)12 CancelException (com.sx4.bot.waiter.exception.CancelException)12 TimeoutException (com.sx4.bot.waiter.exception.TimeoutException)12 List (java.util.List)12 CompletionException (java.util.concurrent.CompletionException)12 GenericEvent (net.dv8tion.jda.api.events.GenericEvent)12 ButtonClickEvent (net.dv8tion.jda.api.events.interaction.ButtonClickEvent)12