use of com.sx4.bot.annotations.command.Examples 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);
});
}
use of com.sx4.bot.annotations.command.Examples 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();
});
}
use of com.sx4.bot.annotations.command.Examples 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());
}
use of com.sx4.bot.annotations.command.Examples in project Sx4 by sx4-discord-bot.
the class AntiRegexCommand method set.
@Command(value = "set", description = "Sets the amount of attempts a user has for an anti regex")
@CommandId(460)
@Examples({ "anti regex set 5f023782ef9eba03390a740c @Shea#6653 0", "anti regex set 5f023782ef9eba03390a740c Shea 3", "anti regex set 5f023782ef9eba03390a740c 402557516728369153 2" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void set(Sx4CommandEvent event, @Argument(value = "id") ObjectId id, @Argument(value = "user") Member member, @Argument(value = "attempts") int attempts) {
Bson filter = Filters.and(Filters.eq("regexId", 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("I could not find that anti regex").queue();
return;
}
if (data.getInteger("attempts") == attempts) {
event.replyFailure("That users attempts were already set to that").queue();
return;
}
event.replySuccess("**" + member.getUser().getAsTag() + "** has had their attempts set to **" + attempts + "**").queue();
});
}
use of com.sx4.bot.annotations.command.Examples 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();
}
Aggregations