Search in sources :

Example 16 with Reason

use of com.sx4.bot.entities.mod.Reason in project Sx4 by sx4-discord-bot.

the class UnbanCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "user") String userArgument, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason) {
    SearchUtility.getBan(event.getGuild(), userArgument).whenComplete((ban, exception) -> {
        if (ban == null) {
            event.replyFailure("I could not find that banned user").queue();
            return;
        }
        User user = ban.getUser();
        event.getGuild().unban(user).reason(ModUtility.getAuditReason(reason, event.getAuthor())).submit().whenComplete(($, unbanException) -> {
            if (unbanException instanceof ErrorResponseException && ((ErrorResponseException) unbanException).getErrorResponse() == ErrorResponse.UNKNOWN_BAN) {
                event.replyFailure("That user is not banned").queue();
                return;
            }
            event.replySuccess("**" + user.getAsTag() + "** has been unbanned").queue();
            event.getBot().getModActionManager().onModAction(new UnbanEvent(event.getMember(), user, reason));
            event.getBot().getTemporaryBanManager().removeBan(event.getGuild().getIdLong(), user.getIdLong(), false);
        });
    });
}
Also used : User(net.dv8tion.jda.api.entities.User) UnbanEvent(com.sx4.bot.events.mod.UnbanEvent) ErrorResponseException(net.dv8tion.jda.api.exceptions.ErrorResponseException)

Example 17 with Reason

use of com.sx4.bot.entities.mod.Reason 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 18 with Reason

use of com.sx4.bot.entities.mod.Reason 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 19 with Reason

use of com.sx4.bot.entities.mod.Reason in project Sx4 by sx4-discord-bot.

the class KickCommand 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 kick me, that is illegal").queue();
        return;
    }
    if (!event.getMember().canInteract(member)) {
        event.replyFailure("You cannot kick someone higher or equal than your top role").queue();
        return;
    }
    if (!event.getSelfMember().canInteract(member)) {
        event.replyFailure("I cannot kick someone higher or equal than my top role").queue();
        return;
    }
    member.kick().reason(ModUtility.getAuditReason(reason, event.getAuthor())).queue($ -> {
        event.replySuccess("**" + member.getUser().getAsTag() + "** has been kicked").queue();
        event.getBot().getModActionManager().onModAction(new KickEvent(event.getMember(), member.getUser(), reason));
    });
}
Also used : KickEvent(com.sx4.bot.events.mod.KickEvent)

Aggregations

Document (org.bson.Document)11 Bson (org.bson.conversions.Bson)10 Reason (com.sx4.bot.entities.mod.Reason)8 User (net.dv8tion.jda.api.entities.User)8 Member (net.dv8tion.jda.api.entities.Member)7 com.mongodb.client.model (com.mongodb.client.model)6 Operators (com.sx4.bot.database.mongo.model.Operators)6 Permission (net.dv8tion.jda.api.Permission)6 Guild (net.dv8tion.jda.api.entities.Guild)6 MongoDatabase (com.sx4.bot.database.mongo.MongoDatabase)5 CompletionException (java.util.concurrent.CompletionException)5 Role (net.dv8tion.jda.api.entities.Role)5 ErrorResponseException (net.dv8tion.jda.api.exceptions.ErrorResponseException)5 ObjectId (org.bson.types.ObjectId)5 Command (com.jockie.bot.core.command.Command)4 Sx4 (com.sx4.bot.core.Sx4)4 Action (com.sx4.bot.entities.mod.action.Action)4 List (java.util.List)4 Sx4Command (com.sx4.bot.core.Sx4Command)3 com.sx4.bot.entities.mod.action (com.sx4.bot.entities.mod.action)3