Search in sources :

Example 96 with Command

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

the class MarriageCommand method list.

@Command(value = "list", description = "Lists a users marriages")
@CommandId(270)
@Redirects({ "married" })
@Examples({ "marriage list", "marriage list @Shea#6653", "marriage list Shea" })
public void list(Sx4CommandEvent event, @Argument(value = "user", endless = true, nullDefault = true) Member member) {
    member = member == null ? event.getMember() : member;
    User user = member.getUser();
    Bson filter = Filters.or(Filters.eq("proposerId", user.getIdLong()), Filters.eq("partnerId", user.getIdLong()));
    List<Document> marriages = event.getMongo().getMarriages(filter, Projections.include("proposerId", "partnerId")).sort(Sorts.ascending("_id")).into(new ArrayList<>());
    if (marriages.isEmpty()) {
        event.replyFailure("That user is not married to anyone").queue();
        return;
    }
    StringJoiner joiner = new StringJoiner("\n");
    for (Document marriage : marriages) {
        long partnerId = marriage.getLong("partnerId");
        long otherId = partnerId == user.getIdLong() ? marriage.getLong("proposerId") : partnerId;
        User other = event.getShardManager().getUserById(otherId);
        joiner.add((other == null ? "Anonymous#0000" : other.getAsTag()) + " (" + otherId + ")");
    }
    EmbedBuilder embed = new EmbedBuilder().setAuthor(user.getName() + "'s Partners", null, user.getEffectiveAvatarUrl()).setDescription(joiner.toString()).setColor(member.getColorRaw());
    event.reply(embed.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) User(net.dv8tion.jda.api.entities.User) Document(org.bson.Document) StringJoiner(java.util.StringJoiner) Bson(org.bson.conversions.Bson) 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 97 with Command

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

the class WarnCommand method resetAfter.

@Command(value = "reset after", description = "The time it should take for warns to be taken away")
@CommandId(450)
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
@Examples({ "warn reset after 1 1 day", "warn reset after 3 5h 20s", "warn reset after 3 30d" })
public void resetAfter(Sx4CommandEvent event, @Argument(value = "amount") @Limit(min = 0) int amount, @Argument(value = "time", endless = true, nullDefault = true) Duration time) {
    if (time != null && time.toMinutes() < 5) {
        event.replyFailure("The duration has to be 5 minutes or above").queue();
        return;
    }
    if (amount != 0 && time == null) {
        event.reply("You need to provide a duration if attempts is more than 0").queue();
        return;
    }
    Bson update = amount == 0 ? Updates.unset("warn.reset") : Updates.set("warn.reset", new Document("amount", amount).append("after", time.toSeconds()));
    event.getMongo().updateGuildById(event.getGuild().getIdLong(), update).whenComplete((result, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        if (result.getModifiedCount() == 0) {
            event.replyFailure("Your warn reset configuration was already set to that").queue();
            return;
        }
        event.reply(amount == 0 ? "Users warns will no longer reset" + event.getConfig().getSuccessEmote() : String.format("Users warns will now reset **%d** time%s after `%s` %s", amount, amount == 1 ? "" : "s", TimeUtility.LONG_TIME_FORMATTER.parse(time.toSeconds()), event.getConfig().getSuccessEmote())).queue();
    });
}
Also used : Document(org.bson.Document) Bson(org.bson.conversions.Bson) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Example 98 with Command

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

the class WarnCommand method list.

@Command(value = "list", description = "Lists all the warned users in the server and how many warnings they have")
@CommandId(258)
@Examples({ "warn list" })
@BotPermissions(permissions = { Permission.MESSAGE_EMBED_LINKS })
public void list(Sx4CommandEvent event) {
    List<Bson> pipeline = List.of(Aggregates.match(Filters.eq("guildId", event.getGuild().getIdLong())), Aggregates.project(Projections.fields(Projections.include("userId"), Projections.computed("warnings", Operators.cond(Operators.or(Operators.isNull("$reset"), Operators.isNull("$warnings")), Operators.ifNull("$warnings", 0), Operators.max(0, Operators.subtract("$warnings", Operators.multiply(Operators.toInt(Operators.floor(Operators.divide(Operators.subtract(Operators.nowEpochSecond(), "$lastWarning"), "$reset.after"))), "$reset.amount"))))))), Aggregates.match(Filters.ne("warnings", 0)), Aggregates.sort(Sorts.descending("warnings")));
    event.getMongo().aggregateWarnings(pipeline).whenComplete((users, exception) -> {
        if (ExceptionUtility.sendExceptionally(event, exception)) {
            return;
        }
        if (users.isEmpty()) {
            event.replyFailure("There are no users with warnings in this server").queue();
            return;
        }
        PagedResult<Document> paged = new PagedResult<>(event.getBot(), users).setAuthor("Warned Users", null, event.getGuild().getIconUrl()).setIndexed(false).setDisplayFunction(data -> {
            long userId = data.getLong("userId");
            User user = event.getShardManager().getUserById(userId);
            return "`" + (user == null ? "Anonymous#0000 (" + userId + ")" : MarkdownSanitizer.escape(user.getAsTag())) + "` - Warning **#" + data.getInteger("warnings") + "**";
        });
        paged.execute(event);
    });
}
Also used : 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)

Example 99 with Command

use of com.jockie.bot.core.command.Command 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 100 with Command

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

the class AntiInviteCommand method toggle.

@Command(value = "toggle", description = "Toggle the state of anti-invite in the current server")
@CommandId(306)
@Examples({ "antiinvite toggle" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void toggle(Sx4CommandEvent event) {
    List<Bson> update = List.of(Operators.set("enabled", Operators.cond(Operators.or(Operators.extinct("$type"), Operators.exists("$enabled")), Operators.REMOVE, false)), Operators.setOnInsert("pattern", AntiRegexHandler.INVITE_REGEX), Operators.setOnInsert("type", RegexType.INVITE.getId()));
    Bson filter = Filters.and(Filters.eq("guildId", event.getGuild().getIdLong()), Filters.eq("regexId", AntiInviteCommand.REGEX_ID));
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().upsert(true).returnDocument(ReturnDocument.BEFORE).projection(Projections.include("enabled"));
    event.getMongo().findAndUpdateRegex(filter, update, options).thenCompose(data -> {
        event.replySuccess("Anti-Invite is now " + (data == null || !data.get("enabled", true) ? "enabled" : "disabled")).queue();
        if (data == null) {
            return event.getMongo().updateRegexTemplateById(AntiInviteCommand.REGEX_ID, Updates.inc("uses", 1L));
        } else {
            return CompletableFuture.completedFuture(null);
        }
    }).whenComplete(MongoDatabase.exceptionally());
}
Also used : HolderType(com.sx4.bot.entities.settings.HolderType) Document(org.bson.Document) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) MarkdownSanitizer(net.dv8tion.jda.api.utils.MarkdownSanitizer) Command(com.jockie.bot.core.command.Command) Permission(net.dv8tion.jda.api.Permission) MongoDatabase(com.sx4.bot.database.mongo.MongoDatabase) CommandId(com.sx4.bot.annotations.command.CommandId) ModAction(com.sx4.bot.entities.mod.action.ModAction) CompletableFuture(java.util.concurrent.CompletableFuture) TimedArgument(com.sx4.bot.entities.argument.TimedArgument) PagedResult(com.sx4.bot.paged.PagedResult) ArrayList(java.util.ArrayList) MatchAction(com.sx4.bot.entities.mod.auto.MatchAction) Bson(org.bson.conversions.Bson) Alternative(com.sx4.bot.entities.argument.Alternative) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) TimeUtility(com.sx4.bot.utility.TimeUtility) Duration(java.time.Duration) AlternativeOptions(com.sx4.bot.annotations.argument.AlternativeOptions) com.mongodb.client.model(com.mongodb.client.model) Argument(com.jockie.bot.core.argument.Argument) Limit(com.sx4.bot.annotations.argument.Limit) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) Operators(com.sx4.bot.database.mongo.model.Operators) Sx4Command(com.sx4.bot.core.Sx4Command) WhitelistType(com.sx4.bot.entities.management.WhitelistType) ModuleCategory(com.sx4.bot.category.ModuleCategory) AntiRegexHandler(com.sx4.bot.handlers.AntiRegexHandler) List(java.util.List) Examples(com.sx4.bot.annotations.command.Examples) ObjectId(org.bson.types.ObjectId) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) RegexType(com.sx4.bot.entities.mod.auto.RegexType) Collections(java.util.Collections) 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)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