Search in sources :

Example 36 with Or

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();
    });
}
Also used : MongoWriteException(com.mongodb.MongoWriteException) CompletionException(java.util.concurrent.CompletionException) Document(org.bson.Document) AuthorPermissions(com.sx4.bot.annotations.command.AuthorPermissions) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command) CommandId(com.sx4.bot.annotations.command.CommandId) Examples(com.sx4.bot.annotations.command.Examples)

Example 37 with Or

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));
        });
    });
}
Also used : Role(net.dv8tion.jda.api.entities.Role) UnmuteEvent(com.sx4.bot.events.mod.UnmuteEvent)

Example 38 with Or

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();
    });
}
Also used : ModAction(com.sx4.bot.entities.mod.action.ModAction) TimeAction(com.sx4.bot.entities.mod.action.TimeAction) Action(com.sx4.bot.entities.mod.action.Action) CompletionException(java.util.concurrent.CompletionException) TimeAction(com.sx4.bot.entities.mod.action.TimeAction) Warn(com.sx4.bot.entities.mod.action.Warn)

Example 39 with Or

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();
    });
}
Also used : Document(org.bson.Document) Bson(org.bson.conversions.Bson) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Example 40 with Or

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();
}
Also used : ModuleCategory(com.sx4.bot.category.ModuleCategory) PermissionUtility(com.sx4.bot.utility.PermissionUtility) Sx4Command(com.sx4.bot.core.Sx4Command) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) Permission(net.dv8tion.jda.api.Permission) Member(net.dv8tion.jda.api.entities.Member) EnumSet(java.util.EnumSet) Argument(com.jockie.bot.core.argument.Argument) Limit(com.sx4.bot.annotations.argument.Limit) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

Sx4Command (com.sx4.bot.core.Sx4Command)36 Command (com.jockie.bot.core.command.Command)25 Document (org.bson.Document)25 Argument (com.jockie.bot.core.argument.Argument)19 ModuleCategory (com.sx4.bot.category.ModuleCategory)19 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)19 Bson (org.bson.conversions.Bson)17 CommandId (com.sx4.bot.annotations.command.CommandId)16 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)16 Examples (com.sx4.bot.annotations.command.Examples)15 PagedResult (com.sx4.bot.paged.PagedResult)15 Permission (net.dv8tion.jda.api.Permission)15 Member (net.dv8tion.jda.api.entities.Member)13 List (java.util.List)12 CompletionException (java.util.concurrent.CompletionException)10 Option (com.jockie.bot.core.option.Option)8 Collectors (java.util.stream.Collectors)8 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)8 AlternativeOptions (com.sx4.bot.annotations.argument.AlternativeOptions)7 Operators (com.sx4.bot.database.mongo.model.Operators)7