Search in sources :

Example 6 with Action

use of com.sx4.bot.entities.mod.action.Action in project Sx4 by sx4-discord-bot.

the class ShipCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "first user") Member firstMember, @Argument(value = "second user", endless = true, nullDefault = true) Member secondMember) {
    User firstUser = firstMember.getUser();
    User secondUser = secondMember == null ? event.getAuthor() : secondMember.getUser();
    this.random.setSeed(firstUser.getIdLong() + secondUser.getIdLong());
    int percent = this.random.nextInt(100) + 1;
    String firstName = firstUser.getName(), secondName = secondUser.getName();
    String shipName = firstName.substring(0, (int) Math.ceil((double) firstName.length() / 2)) + secondName.substring((int) Math.ceil((double) secondName.length() / 2));
    String message = String.format("Ship Name: **%s**\nLove Percentage: **%d%%**", shipName, percent);
    Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("ship")).addQuery("first_image", firstUser.getEffectiveAvatarUrl()).addQuery("second_image", secondUser.getEffectiveAvatarUrl()).addQuery("percent", percent).build(event.getConfig().getImageWebserver());
    if (event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ATTACH_FILES)) {
        event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> {
            MessageAction action = ImageUtility.getImageMessage(event, response);
            if (response.isSuccessful()) {
                action.content(message);
            }
            action.queue();
        });
    } else {
        event.reply(message).queue();
    }
}
Also used : Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest) HttpCallback(com.sx4.bot.http.HttpCallback) ImageUtility(com.sx4.bot.utility.ImageUtility) Sx4Command(com.sx4.bot.core.Sx4Command) Permission(net.dv8tion.jda.api.Permission) Random(java.util.Random) Member(net.dv8tion.jda.api.entities.Member) User(net.dv8tion.jda.api.entities.User) ModuleCategory(com.sx4.bot.category.ModuleCategory) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) Argument(com.jockie.bot.core.argument.Argument) User(net.dv8tion.jda.api.entities.User) ImageRequest(com.sx4.bot.entities.image.ImageRequest) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) Request(okhttp3.Request) ImageRequest(com.sx4.bot.entities.image.ImageRequest)

Example 7 with Action

use of com.sx4.bot.entities.mod.action.Action in project Sx4 by sx4-discord-bot.

the class PremiumCommand method add.

@Command(value = "add", description = "Make a server premium")
@CommandId(177)
@Examples({ "premium add", "premium add 31", "premium add 20 Sx4 | Support Server" })
@Premium
public void add(Sx4CommandEvent event, @Argument(value = "days") @DefaultNumber(31) @Limit(min = 1, max = 365) int days, @Argument(value = "server", endless = true, nullDefault = true) Guild guild) {
    if (guild == null) {
        guild = event.getGuild();
    }
    long guildId = guild.getIdLong();
    String guildName = guild.getName();
    int monthPrice = event.getConfig().getPremiumPrice();
    int price = (int) Math.round((monthPrice / (double) event.getConfig().getPremiumDays()) * days);
    long endAtPrior = event.getMongo().getGuildById(guildId, Projections.include("premium.endAt")).getEmbedded(List.of("premium", "endAt"), 0L);
    boolean hasPremium = endAtPrior != 0;
    MessageEmbed embed = new EmbedBuilder().setColor(event.getConfig().getOrange()).setAuthor("Premium", null, event.getAuthor().getEffectiveAvatarUrl()).setDescription(String.format("Buying %d day%s of premium will:\n\n• Make you unable to use this credit on the other version of the bot\n• Use **$%.2f** of your credit\n• %s %1$s day%2$s of premium to the server\n\n:warning: **This action cannot be reversed** :warning:", days, days == 1 ? "" : "s", price / 100D, hasPremium ? "Add an extra" : "Give")).build();
    List<Button> buttons = List.of(Button.success("confirm", "Confirm"), Button.danger("cancel", "Cancel"));
    event.reply(embed).setActionRow(buttons).submit().thenCompose(message -> {
        return new Waiter<>(event.getBot(), ButtonClickEvent.class).setPredicate(e -> ButtonUtility.handleButtonConfirmation(e, message, event.getAuthor(), "confirm")).setCancelPredicate(e -> ButtonUtility.handleButtonCancellation(e, message, event.getAuthor(), "cancel")).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("premium.credit", Operators.cond(Operators.gt(price, Operators.ifNull("$premium.credit", 0)), "$premium.credit", Operators.subtract("$premium.credit", price))));
        FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.BEFORE).projection(Projections.include("premium.credit")).upsert(true);
        event.getMongoMain().findAndUpdateUserById(event.getAuthor().getIdLong(), update, options).thenCompose(data -> {
            int credit = data == null ? 0 : data.getEmbedded(List.of("premium", "credit"), 0);
            if (price > credit) {
                e.reply("You do not have enough credit to buy premium for that long " + event.getConfig().getFailureEmote()).queue();
                return CompletableFuture.completedFuture(MongoDatabase.EMPTY_DOCUMENT);
            }
            List<Bson> guildUpdate = List.of(Operators.set("premium.endAt", Operators.add(TimeUnit.DAYS.toSeconds(days), Operators.ifNull("$premium.endAt", Operators.nowEpochSecond()))));
            FindOneAndUpdateOptions guildOptions = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.BEFORE).projection(Projections.include("premium.endAt")).upsert(true);
            return event.getMongo().findAndUpdateGuildById(guildId, guildUpdate, guildOptions);
        }).whenComplete((data, databaseException) -> {
            if (ExceptionUtility.sendExceptionally(event, databaseException) || (data != null && data.isEmpty())) {
                return;
            }
            long endAt = data == null ? 0L : data.getEmbedded(List.of("premium", "endAt"), 0L);
            e.replyFormat("**%s** now has premium for %s%d day%s %s", guildName, endAt == 0 ? "" : "another ", days, days == 1 ? "" : "s", event.getConfig().getSuccessEmote()).queue();
        });
    });
}
Also used : Document(org.bson.Document) CancelException(com.sx4.bot.waiter.exception.CancelException) MarkdownSanitizer(net.dv8tion.jda.api.utils.MarkdownSanitizer) Command(com.jockie.bot.core.command.Command) ButtonClickEvent(net.dv8tion.jda.api.events.interaction.ButtonClickEvent) MongoDatabase(com.sx4.bot.database.mongo.MongoDatabase) CommandId(com.sx4.bot.annotations.command.CommandId) CompletableFuture(java.util.concurrent.CompletableFuture) PagedResult(com.sx4.bot.paged.PagedResult) User(net.dv8tion.jda.api.entities.User) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson) Redirects(com.sx4.bot.annotations.command.Redirects) ButtonUtility(com.sx4.bot.utility.ButtonUtility) Guild(net.dv8tion.jda.api.entities.Guild) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) Button(net.dv8tion.jda.api.interactions.components.Button) Map(java.util.Map) Option(com.jockie.bot.core.option.Option) Waiter(com.sx4.bot.waiter.Waiter) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) com.mongodb.client.model(com.mongodb.client.model) ZoneOffset(java.time.ZoneOffset) Argument(com.jockie.bot.core.argument.Argument) Limit(com.sx4.bot.annotations.argument.Limit) Operators(com.sx4.bot.database.mongo.model.Operators) 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) Instant(java.time.Instant) Premium(com.sx4.bot.annotations.command.Premium) TimeUnit(java.util.concurrent.TimeUnit) ModuleCategory(com.sx4.bot.category.ModuleCategory) List(java.util.List) DefaultNumber(com.sx4.bot.annotations.argument.DefaultNumber) Examples(com.sx4.bot.annotations.command.Examples) OffsetDateTime(java.time.OffsetDateTime) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) DateTimeFormatter(java.time.format.DateTimeFormatter) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) Bson(org.bson.conversions.Bson) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) 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) Premium(com.sx4.bot.annotations.command.Premium) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 8 with Action

use of com.sx4.bot.entities.mod.action.Action in project Sx4 by sx4-discord-bot.

the class AntiRegexHandler method handle.

public void handle(Message message) {
    Member member = message.getMember();
    if (member == null) {
        return;
    }
    User user = member.getUser();
    if (user.isBot()) {
        return;
    }
    Guild guild = message.getGuild();
    Member selfMember = guild.getSelfMember();
    TextChannel textChannel = message.getTextChannel();
    long guildId = guild.getIdLong(), userId = member.getIdLong(), channelId = textChannel.getIdLong();
    Category parent = textChannel.getParent();
    List<Role> roles = member.getRoles();
    String content = message.getContentRaw();
    List<Bson> guildPipeline = List.of(Aggregates.project(Projections.fields(Projections.computed("premium", Operators.lt(Operators.nowEpochSecond(), Operators.ifNull("$premium.endAt", 0L))), Projections.computed("guildId", "$_id"))), Aggregates.match(Filters.eq("guildId", guild.getIdLong())));
    List<Bson> pipeline = List.of(Aggregates.match(Filters.and(Filters.eq("guildId", guild.getIdLong()), Filters.exists("enabled", false))), Aggregates.group(null, Accumulators.push("regexes", Operators.ROOT)), Aggregates.unionWith("guilds", guildPipeline), Aggregates.group(null, Accumulators.max("premium", "$premium"), Accumulators.max("regexes", "$regexes")), Aggregates.project(Projections.computed("regexes", Operators.let(new Document("regexes", Operators.ifNull("$regexes", Collections.EMPTY_LIST)), Operators.cond(Operators.ifNull("$premium", false), "$$regexes", Operators.concatArrays(Operators.filter("$$regexes", Operators.ne("$$this.type", RegexType.REGEX.getId())), Operators.slice(Operators.filter("$$regexes", Operators.eq("$$this.type", RegexType.REGEX.getId())), 0, 3)))))));
    this.bot.getMongo().aggregateRegexes(pipeline).whenComplete((documents, exception) -> {
        if (documents.isEmpty()) {
            return;
        }
        Document data = documents.get(0);
        this.executor.submit(() -> {
            List<CompletableFuture<Document>> matches = new ArrayList<>();
            Regexes: for (Document regex : data.getList("regexes", Document.class)) {
                if (member.hasPermission(Permission.ADMINISTRATOR) && regex.getBoolean("admin", true)) {
                    continue;
                }
                List<Document> channels = regex.getList("whitelist", Document.class, Collections.emptyList());
                Document channel = channels.stream().filter(d -> (d.getInteger("type") == WhitelistType.CHANNEL.getId() && d.getLong("id") == channelId) || (d.getInteger("type") == WhitelistType.CATEGORY.getId() && parent != null && d.getLong("id") == parent.getIdLong())).min(Comparator.comparingInt(d -> d.getInteger("type", 0))).orElse(MongoDatabase.EMPTY_DOCUMENT);
                List<Document> holders = channel.getList("holders", Document.class, Collections.emptyList());
                for (Document holder : holders) {
                    long holderId = holder.getLong("id");
                    int type = holder.getInteger("type");
                    if (type == HolderType.USER.getType() && userId == holderId) {
                        continue Regexes;
                    } else if (type == HolderType.ROLE.getType() && (guildId == holderId || roles.stream().anyMatch(role -> role.getIdLong() == holderId))) {
                        continue Regexes;
                    }
                }
                RegexType type = RegexType.fromId(regex.getInteger("type"));
                Pattern pattern = type == RegexType.REGEX ? Pattern.compile(regex.getString("pattern")) : this.invitePattern;
                Matcher matcher;
                try {
                    matcher = this.executor.submit(() -> pattern.matcher(content)).get(2000, TimeUnit.MILLISECONDS);
                } catch (TimeoutException | InterruptedException | ExecutionException e) {
                    continue;
                }
                Set<String> codes = new HashSet<>();
                int matchCount = 0, totalCount = 0;
                while (matcher.find()) {
                    List<Document> groups = channel.getList("groups", Document.class, Collections.emptyList());
                    for (Document group : groups) {
                        List<String> strings = group.getList("strings", String.class, Collections.emptyList());
                        String match = matcher.group(group.getInteger("group"));
                        if (match != null && strings.contains(match)) {
                            matchCount++;
                        }
                    }
                    if (type == RegexType.INVITE) {
                        codes.add(matcher.group(1));
                    }
                    totalCount++;
                }
                if (matchCount == totalCount) {
                    continue;
                }
                CompletableFuture<Document> future;
                if (type == RegexType.INVITE) {
                    List<CompletableFuture<Invite>> futures = codes.stream().map(code -> Invite.resolve(message.getJDA(), code, true).submit()).collect(Collectors.toList());
                    List<Long> guilds = channel.getList("guilds", Long.class, Collections.emptyList());
                    future = FutureUtility.anyOf(futures, invite -> {
                        Invite.Guild inviteGuild = invite.getGuild();
                        return inviteGuild == null || (!guilds.contains(inviteGuild.getIdLong()) && inviteGuild.getIdLong() != guildId);
                    }).thenApply(invite -> invite == null ? null : regex);
                } else {
                    future = CompletableFuture.completedFuture(regex);
                }
                matches.add(future);
            }
            FutureUtility.anyOf(matches, Objects::nonNull).thenAccept(regex -> {
                if (regex == null) {
                    return;
                }
                ObjectId id = regex.getObjectId("_id");
                RegexType type = RegexType.fromId(regex.getInteger("type"));
                Document match = regex.get("match", MongoDatabase.EMPTY_DOCUMENT);
                long matchAction = match.get("action", MatchAction.ALL);
                Document mod = regex.get("mod", MongoDatabase.EMPTY_DOCUMENT);
                Document actionData = mod.get("action", Document.class);
                Action action = actionData == null ? null : Action.fromData(actionData);
                Document attempts = regex.get("attempts", MongoDatabase.EMPTY_DOCUMENT);
                int maxAttempts = attempts.get("amount", 3);
                if ((matchAction & MatchAction.DELETE_MESSAGE.getRaw()) == MatchAction.DELETE_MESSAGE.getRaw() && selfMember.hasPermission(textChannel, Permission.MESSAGE_MANAGE)) {
                    message.delete().queue();
                }
                Document reset = attempts.get("reset", Document.class);
                List<Bson> update = List.of(Operators.set("attempts", Operators.let(new Document("attempts", Operators.ifNull("$attempts", 0)), Operators.cond(Operators.exists("$reset"), Operators.max(1, Operators.add(1, Operators.subtract("$$attempts", Operators.multiply(Operators.toInt(Operators.floor(Operators.divide(Operators.subtract(Operators.nowEpochSecond(), "$lastAttempt"), "$reset.after"))), "$reset.amount")))), Operators.add("$$attempts", 1)))), Operators.set("lastAttempt", Operators.nowEpochSecond()), Operators.setOnInsert("guildId", guildId), reset == null ? Operators.unset("reset") : Operators.set("reset", reset));
                Bson filter = Filters.and(Filters.eq("userId", userId), Filters.eq("regexId", id));
                FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().upsert(true).projection(Projections.include("attempts")).returnDocument(ReturnDocument.AFTER);
                this.bot.getMongo().findAndUpdateRegexAttempt(filter, update, options).whenComplete((attemptsData, attemptsException) -> {
                    if (ExceptionUtility.sendErrorMessage(attemptsException)) {
                        return;
                    }
                    int currentAttempts = attemptsData.getInteger("attempts", 0);
                    String matchMessage = this.format(match.get("message", type.getDefaultMatchMessage()), user, textChannel, id, currentAttempts, maxAttempts, action);
                    String modMessage = this.format(mod.get("message", type.getDefaultModMessage()), user, textChannel, id, currentAttempts, maxAttempts, action);
                    boolean send = (matchAction & MatchAction.SEND_MESSAGE.getRaw()) == MatchAction.SEND_MESSAGE.getRaw() && selfMember.hasPermission(textChannel, Permission.MESSAGE_WRITE);
                    if (action != null && currentAttempts == maxAttempts) {
                        Reason reason = new Reason(String.format("Sent a message which matched regex `%s` %d time%s", id.toHexString(), maxAttempts, maxAttempts == 1 ? "" : "s"));
                        ModUtility.performAction(this.bot, action, member, selfMember, reason).thenCompose(result -> {
                            if (send) {
                                textChannel.sendMessage(modMessage).allowedMentions(EnumSet.allOf(Message.MentionType.class)).queue();
                            }
                            return this.bot.getMongo().deleteRegexAttempt(Filters.and(Filters.eq("userId", userId), Filters.eq("regexId", id)));
                        }).whenComplete((result, modException) -> {
                            Throwable cause = modException instanceof CompletionException ? modException.getCause() : modException;
                            if (cause instanceof ModException) {
                                textChannel.sendMessage(modException.getMessage() + " " + this.bot.getConfig().getFailureEmote()).queue();
                                return;
                            }
                            ExceptionUtility.sendExceptionally(textChannel, modException);
                        });
                        return;
                    }
                    if (send) {
                        textChannel.sendMessage(matchMessage).allowedMentions(EnumSet.allOf(Message.MentionType.class)).queue();
                    }
                });
            });
        });
    });
}
Also used : HolderType(com.sx4.bot.entities.settings.HolderType) Document(org.bson.Document) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) java.util(java.util) ModException(com.sx4.bot.exceptions.mod.ModException) Permission(net.dv8tion.jda.api.Permission) MongoDatabase(com.sx4.bot.database.mongo.MongoDatabase) MatchAction(com.sx4.bot.entities.mod.auto.MatchAction) Bson(org.bson.conversions.Bson) Matcher(java.util.regex.Matcher) Sx4(com.sx4.bot.core.Sx4) Reason(com.sx4.bot.entities.mod.Reason) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) com.mongodb.client.model(com.mongodb.client.model) FutureUtility(com.sx4.bot.utility.FutureUtility) Action(com.sx4.bot.entities.mod.action.Action) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) Operators(com.sx4.bot.database.mongo.model.Operators) GuildMessageUpdateEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent) java.util.concurrent(java.util.concurrent) ModUtility(com.sx4.bot.utility.ModUtility) WhitelistType(com.sx4.bot.entities.management.WhitelistType) Collectors(java.util.stream.Collectors) EventListener(net.dv8tion.jda.api.hooks.EventListener) StringFormatter(com.sx4.bot.formatter.StringFormatter) ObjectId(org.bson.types.ObjectId) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) RegexType(com.sx4.bot.entities.mod.auto.RegexType) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) RegexType(com.sx4.bot.entities.mod.auto.RegexType) MatchAction(com.sx4.bot.entities.mod.auto.MatchAction) Action(com.sx4.bot.entities.mod.action.Action) Matcher(java.util.regex.Matcher) ModException(com.sx4.bot.exceptions.mod.ModException) Document(org.bson.Document) Reason(com.sx4.bot.entities.mod.Reason) Bson(org.bson.conversions.Bson) Pattern(java.util.regex.Pattern) ObjectId(org.bson.types.ObjectId)

Example 9 with Action

use of com.sx4.bot.entities.mod.action.Action in project Sx4 by sx4-discord-bot.

the class AntiInviteCommand method attempts.

/*@Command(value="set", description="Sets the amount of attempts a user has")
	@CommandId(459)
	@Examples({"antiinvite set @Shea#6653 0", "antiinvite set Shea 3", "antiinvite set 402557516728369153 2"})
	@AuthorPermissions(permissions={Permission.MANAGE_SERVER})
	public void set(Sx4CommandEvent event, @Argument(value="user") Member member, @Argument(value="attempts") int attempts) {
		Bson filter = Filters.and(Filters.eq("regexId", AntiInviteCommand.REGEX_ID), Filters.eq("userId", member.getIdLong()), Filters.eq("guildId", event.getGuild().getIdLong()));

		CompletableFuture<Document> future;
		if (attempts == 0) {
			future = event.getMongo().findAndDeleteRegexAttempt(filter);
		} else {
			FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().projection(Projections.include("attempts")).returnDocument(ReturnDocument.BEFORE).upsert(true);
			future = event.getMongo().findAndUpdateRegexAttempt(filter, Updates.set("attempts", attempts), options);
		}

		future.whenComplete((data, exception) -> {
			if (ExceptionUtility.sendExceptionally(event, exception)) {
				return;
			}

			if (data == null) {
				event.replyFailure("You do not have anti-invite setup").queue();
				return;
			}

			if (data.getInteger("attempts") == attempts) {
				event.replyFailure("That users attempts were already set to that").queue();
				return;
			}

			if (attempts == 0) {
				event.getBot().getAntiRegexManager().clearAttempts(AntiInviteCommand.REGEX_ID, member.getIdLong());
			} else {
				event.getBot().getAntiRegexManager().setAttempts(AntiInviteCommand.REGEX_ID, member.getIdLong(), attempts);
			}

			event.replySuccess("**" + member.getUser().getAsTag() + "** has had their attempts set to **" + attempts + "**").queue();
		});
	}*/
@Command(value = "attempts", description = "Sets the amount of attempts needed for the mod action to execute")
@CommandId(307)
@Examples({ "antiinvite attempts 3", "antiinvite attempts 1" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void attempts(Sx4CommandEvent event, @Argument(value = "attempts") @Limit(min = 1) int attempts) {
    Bson filter = Filters.and(Filters.eq("regexId", AntiInviteCommand.REGEX_ID), Filters.eq("guildId", event.getGuild().getIdLong()));
    event.getMongo().updateRegex(filter, Updates.set("attempts.amount", attempts)).whenComplete((result, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        if (result.getMatchedCount() == 0) {
            event.replyFailure("You do not have anti-invite setup").queue();
            return;
        }
        if (result.getModifiedCount() == 0) {
            event.replyFailure("Your attempts where already set to that").queue();
            return;
        }
        event.replySuccess("Attempts to a mod action have been set to **" + attempts + "**").queue();
    });
}
Also used : 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 Action

use of com.sx4.bot.entities.mod.action.Action 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)9 Permission (net.dv8tion.jda.api.Permission)8 Document (org.bson.Document)8 Bson (org.bson.conversions.Bson)8 User (net.dv8tion.jda.api.entities.User)7 Argument (com.jockie.bot.core.argument.Argument)6 Command (com.jockie.bot.core.command.Command)6 CommandId (com.sx4.bot.annotations.command.CommandId)6 ModuleCategory (com.sx4.bot.category.ModuleCategory)6 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)6 com.mongodb.client.model (com.mongodb.client.model)5 Examples (com.sx4.bot.annotations.command.Examples)5 Operators (com.sx4.bot.database.mongo.model.Operators)5 List (java.util.List)5 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)5 AuthorPermissions (com.sx4.bot.annotations.command.AuthorPermissions)4 MongoDatabase (com.sx4.bot.database.mongo.MongoDatabase)4 Action (com.sx4.bot.entities.mod.action.Action)4 PagedResult (com.sx4.bot.paged.PagedResult)4 Reason (com.sx4.bot.entities.mod.Reason)3