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();
}
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();
});
}
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);
});
}
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();
});
}
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());
}
Aggregations