use of com.sx4.bot.entities.mod.action.Warn 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.entities.mod.action.Warn in project Sx4 by sx4-discord-bot.
the class WarnCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") Member member, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
if (member.getIdLong() == event.getSelfUser().getIdLong()) {
event.replyFailure("You cannot warn me, that is illegal").queue();
return;
}
if (!event.getMember().canInteract(member)) {
event.replyFailure("You cannot warn someone higher or equal than your top role").queue();
return;
}
ModUtility.warn(event.getBot(), member, event.getMember(), reason).whenComplete((warning, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause != null) {
event.replyFailure(cause.getMessage()).queue();
return;
}
Warn warn = warning.getWarning();
Action action = warn.getAction();
event.replyFormat("**%s** has received a %s%s (%s warning) " + event.getConfig().getSuccessEmote(), member.getUser().getAsTag(), action.getModAction().getName().toLowerCase(), action instanceof TimeAction ? " for " + TimeUtility.LONG_TIME_FORMATTER.parse(((TimeAction) action).getDuration()) : "", NumberUtility.getSuffixed(warn.getNumber())).queue();
});
}
Aggregations