Search in sources :

Example 1 with UnbanEvent

use of com.sx4.bot.events.mod.UnbanEvent in project Sx4 by sx4-discord-bot.

the class TemporaryBanManager method removeBanAndGet.

public DeleteOneModel<Document> removeBanAndGet(long guildId, long userId, boolean automatic) {
    ShardManager shardManager = this.bot.getShardManager();
    Guild guild = shardManager.getGuildById(guildId);
    if (guild == null) {
        return null;
    }
    User user = shardManager.getUserById(userId);
    Member member = user == null ? null : guild.getMember(user);
    if (automatic && member == null) {
        guild.unban(User.fromId(userId)).reason("Ban length served").queue();
    }
    if (automatic) {
        Reason reason = new Reason("Ban length served");
        UnbanEvent event = new UnbanEvent(guild.getSelfMember(), user == null ? UserReference.fromId(userId) : user, reason);
        this.bot.getModActionManager().onModAction(event);
    }
    this.deleteExecutor(guildId, userId);
    return new DeleteOneModel<>(Filters.and(Filters.eq("guildId", guildId), Filters.eq("userId", userId)));
}
Also used : User(net.dv8tion.jda.api.entities.User) UnbanEvent(com.sx4.bot.events.mod.UnbanEvent) ShardManager(net.dv8tion.jda.api.sharding.ShardManager) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member) Reason(com.sx4.bot.entities.mod.Reason)

Example 2 with UnbanEvent

use of com.sx4.bot.events.mod.UnbanEvent 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)

Aggregations

UnbanEvent (com.sx4.bot.events.mod.UnbanEvent)2 User (net.dv8tion.jda.api.entities.User)2 Reason (com.sx4.bot.entities.mod.Reason)1 Guild (net.dv8tion.jda.api.entities.Guild)1 Member (net.dv8tion.jda.api.entities.Member)1 ErrorResponseException (net.dv8tion.jda.api.exceptions.ErrorResponseException)1 ShardManager (net.dv8tion.jda.api.sharding.ShardManager)1