use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class BlacklistCommand method reset.
@Command(value = "reset", description = "Reset the blacklist for a specific role/user in a channel")
@CommandId(181)
@Examples({ "blacklist reset #channel", "blacklist reset all" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void reset(Sx4CommandEvent event, @Argument(value = "channel", endless = true) @AlternativeOptions("all") Alternative<TextChannel> option) {
List<Bson> update = List.of(Operators.set("holders", Operators.reduce(Operators.ifNull("$holders", Collections.EMPTY_LIST), Collections.EMPTY_LIST, Operators.concatArrays("$$value", Operators.cond(Operators.isEmpty(Operators.ifNull(Operators.first(Operators.map(List.of("$$this"), "$$holder.whitelisted", "holder")), Collections.EMPTY_LIST)), Collections.EMPTY_LIST, List.of(Operators.removeObject("$$this", "blacklisted")))))));
if (option.isAlternative()) {
event.getMongo().updateManyBlacklists(Filters.eq("guildId", event.getGuild().getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Nothing was blacklisted in this server").queue();
return;
}
event.replySuccess("Reset **" + result.getModifiedCount() + "** channels of their blacklist configurations").queue();
});
} else {
TextChannel channel = option.getValue();
event.getMongo().updateBlacklist(Filters.eq("channelId", channel.getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Nothing was blacklisted in that channel").queue();
return;
}
event.replySuccess("That channel no longer has any blacklists").queue();
});
}
}
use of com.sx4.bot.annotations.command.AuthorPermissions in project Sx4 by sx4-discord-bot.
the class WhitelistCommand method reset.
@Command(value = "reset", description = "Reset the whitelist for a specific role/user in a channel")
@CommandId(186)
@Examples({ "whitelist reset #channel", "whitelist reset all" })
@AuthorPermissions(permissions = { Permission.MANAGE_SERVER })
public void reset(Sx4CommandEvent event, @Argument(value = "channel | all", endless = true) @AlternativeOptions("all") Alternative<TextChannel> option) {
List<Bson> update = List.of(Operators.set("holders", Operators.reduce(Operators.ifNull("$holders", Collections.EMPTY_LIST), Collections.EMPTY_LIST, Operators.concatArrays("$$value", Operators.cond(Operators.isEmpty(Operators.ifNull(Operators.first(Operators.map(List.of("$$this"), "$$holder.blacklisted", "holder")), Collections.EMPTY_LIST)), Collections.EMPTY_LIST, List.of(Operators.removeObject("$$this", "whitelisted")))))));
if (option.isAlternative()) {
event.getMongo().updateManyBlacklists(Filters.eq("guildId", event.getGuild().getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Nothing was whitelisted in this server").queue();
return;
}
event.replySuccess("Reset **" + result.getModifiedCount() + "** channels of their whitelist configurations").queue();
});
} else {
TextChannel channel = option.getValue();
event.getMongo().updateBlacklist(Filters.eq("channelId", channel.getIdLong()), update, new UpdateOptions()).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
if (result.getModifiedCount() == 0) {
event.replyFailure("Nothing was whitelisted in that channel").queue();
return;
}
event.replySuccess("That channel no longer has any whitelists").queue();
});
}
}
use of com.sx4.bot.annotations.command.AuthorPermissions 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.sx4.bot.annotations.command.AuthorPermissions 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.AuthorPermissions 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