use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.
the class SelfRoleCommand method add.
@Command(value = "add", description = "Add a self role that other users can give themselves to the current server")
@CommandId(332)
@Examples({ "self role add @Role", "self role add Role", "self role add 330400064541425664" })
@AuthorPermissions(permissions = { Permission.MANAGE_ROLES })
public void add(Sx4CommandEvent event, @Argument(value = "role", endless = true) Role role) {
if (role.isPublicRole()) {
event.replyFailure("You cannot give the @everyone role as a self role").queue();
return;
}
if (role.isManaged()) {
event.replyFailure("You cannot add a managed role as a self role").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("You cannot add a self role higher or equal than my top role").queue();
return;
}
if (!event.getMember().canInteract(role)) {
event.replyFailure("You cannot add a self role higher or equal than your top role").queue();
return;
}
Document data = new Document("roleId", role.getIdLong()).append("guildId", event.getGuild().getIdLong());
event.getMongo().insertSelfRole(data).whenComplete((result, exception) -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof MongoWriteException && ((MongoWriteException) cause).getError().getCategory() == ErrorCategory.DUPLICATE_KEY) {
event.replyFailure("That role is already a self role").queue();
return;
}
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.replySuccess(role.getAsMention() + " is now a self role").queue();
});
}
use of com.sx4.bot.entities.argument.Or in project Sx4 by sx4-discord-bot.
the class UnmuteCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") Member member, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
long roleId = event.getMongo().getGuildById(event.getGuild().getIdLong(), Projections.include("mute.roleId")).getEmbedded(List.of("mute", "roleId"), 0L);
Role role = roleId == 0L ? null : event.getGuild().getRoleById(roleId);
if (role == null || !member.getRoles().contains(role)) {
event.replyFailure("That user is not muted").queue();
return;
}
if (!event.getSelfMember().canInteract(role)) {
event.replyFailure("I am unable to unmute that user as the mute role is higher or equal than my top role").queue();
return;
}
event.getMongo().deleteMute(Filters.and(Filters.eq("userId", member.getIdLong()), Filters.eq("guildId", event.getGuild().getIdLong()))).whenComplete((result, exception) -> {
if (ExceptionUtility.sendExceptionally(event, exception)) {
return;
}
event.getGuild().removeRoleFromMember(member, role).reason(ModUtility.getAuditReason(reason, event.getAuthor())).queue($ -> {
event.replySuccess("**" + member.getUser().getAsTag() + "** has been unmuted").queue();
event.getBot().getMuteManager().deleteExecutor(event.getGuild().getIdLong(), member.getIdLong());
event.getBot().getModActionManager().onModAction(new UnmuteEvent(event.getMember(), member.getUser(), reason));
});
});
}
use of com.sx4.bot.entities.argument.Or 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();
});
}
use of com.sx4.bot.entities.argument.Or 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.entities.argument.Or in project Sx4 by sx4-discord-bot.
the class RenameCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user", nullDefault = true) Member member, @Argument(value = "nickname", endless = true, nullDefault = true) @Limit(max = 32) String nick) {
Member effectiveMember = member == null ? event.getMember() : member;
if (effectiveMember.getIdLong() != event.getMember().getIdLong() && !event.hasPermission(event.getMember(), Permission.NICKNAME_MANAGE)) {
event.replyFailure(PermissionUtility.formatMissingPermissions(EnumSet.of(Permission.NICKNAME_MANAGE))).queue();
return;
}
if (effectiveMember.getIdLong() != event.getMember().getIdLong() && !event.getMember().canInteract(effectiveMember)) {
event.replyFailure("You cannot change the nickname of someone higher or equal than your top role").queue();
return;
}
if (effectiveMember.getIdLong() != event.getSelfUser().getIdLong() && !event.getSelfMember().hasPermission(Permission.NICKNAME_MANAGE)) {
event.replyFailure(PermissionUtility.formatMissingPermissions(EnumSet.of(Permission.NICKNAME_MANAGE), "I am")).queue();
return;
}
if (effectiveMember.getIdLong() != event.getSelfUser().getIdLong() && !event.getSelfMember().canInteract(effectiveMember)) {
event.replyFailure("I cannot change the nickname of someone higher or equal than my top role").queue();
return;
}
event.getGuild().modifyNickname(effectiveMember, nick).flatMap($ -> event.replySuccess("Renamed " + effectiveMember.getAsMention() + " to **" + (nick == null ? effectiveMember.getEffectiveName() : nick) + "**")).queue();
}
Aggregations