net.dv8tion.jda.api.events.guild.GuildUnbanEvent Java Examples

The following examples show how to use net.dv8tion.jda.api.events.guild.GuildUnbanEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GuildListener.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(@Nonnull GenericEvent event) {
    if (event instanceof GuildJoinEvent) {
        this.onGuildJoin((GuildJoinEvent) event);
    } else if (event instanceof GuildLeaveEvent) {
        this.onGuildLeave((GuildLeaveEvent) event);
    } else if (event instanceof GuildVoiceLeaveEvent) {
        this.onGuildVoiceLeave((GuildVoiceLeaveEvent) event);
    } else if (event instanceof GuildVoiceJoinEvent) {
        this.onGuildVoiceJoin((GuildVoiceJoinEvent) event);
    } else if (event instanceof GuildVoiceMoveEvent) {
        this.onGuildVoiceMove((GuildVoiceMoveEvent) event);
    } else if (event instanceof GuildBanEvent) {
        this.onGuildBan((GuildBanEvent) event);
    } else if (event instanceof GuildUnbanEvent) {
        this.onGuildUnban((GuildUnbanEvent) event);
    }
}
 
Example #2
Source File: DiscordBanListener.java    From DiscordSRV with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onGuildUnban(GuildUnbanEvent event) {
    UUID linkedUuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(event.getUser().getId());
    if (linkedUuid == null) {
        DiscordSRV.debug("Not handling unban for user " + event.getUser() + " because they didn't have a linked account");
        return;
    }

    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(linkedUuid);
    if (!offlinePlayer.hasPlayedBefore()) return;

    if (!DiscordSRV.config().getBoolean("BanSynchronizationDiscordToMinecraft")) {
        DiscordSRV.debug("Not handling unban for user " + event.getUser() + " because doing so is disabled in the config");
        return;
    }

    String playerName = offlinePlayer.getName();

    if (StringUtils.isNotBlank(playerName)) //this literally should not happen but intellij likes bitching about not null checking
        Bukkit.getBanList(BanList.Type.NAME).pardon(playerName);
}
 
Example #3
Source File: MemberListener.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onGuildUnban(GuildUnbanEvent event) {
    if (event.getUser().isBot() || !event.getGuild().getSelfMember().hasPermission(Permission.BAN_MEMBERS)) {
        return;
    }
    AuditActionBuilder actionBuilder = getAuditService().log(event.getGuild(), AuditActionType.MEMBER_UNBAN);
    LocalMember member = memberService.get(event.getGuild(), event.getUser());
    if (member != null) {
        actionBuilder.withTargetUser(member);
    } else {
        actionBuilder.withTargetUser(event.getUser());
    }
    moderationService.removeUnBanSchedule(event.getGuild().getId(), event.getUser().getId());
    actionBuilder.save();
}
 
Example #4
Source File: MantaroListener.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
private void logUnban(GuildUnbanEvent event) {
    try {
        String hour = df.format(new Date(System.currentTimeMillis()));
        GuildData data = MantaroData.db().getGuild(event.getGuild()).getData();
        String logChannel = data.getGuildLogChannel();
        if (logChannel != null) {
            TextChannel tc = event.getGuild().getTextChannelById(logChannel);
            if (tc != null) {
                String message;
                if (data.getUnbannedMemberLog() != null) {
                    message = new DynamicModifiers()
                            .set("hour", hour)
                            .mapEvent("event", event)
                            .mapUser("event.user", event.getUser())
                            .resolve(data.getUnbannedMemberLog());
                } else {
                    message = String.format(EmoteReference.WARNING + "`[%s]` %s#%s just got unbanned.", hour, event.getUser().getName(), event.getUser().getDiscriminator());
                }
                tc.sendMessage(message).queue();
                logTotal++;
            }
        }
    } catch (Exception e) {
        if (!(e instanceof NullPointerException) && !(e instanceof IllegalArgumentException)) {
            log.warn("Unexpected error while logging an unban.", e);
        }
    }
}
 
Example #5
Source File: GuildBanHandler.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    final long id = content.getLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(id))
        return id;

    DataObject userJson = content.getObject("user");
    GuildImpl guild = (GuildImpl) getJDA().getGuildById(id);
    if (guild == null)
    {
        getJDA().getEventCache().cache(EventCache.Type.GUILD, id, responseNumber, allContent, this::handle);
        EventCache.LOG.debug("Received Guild Member {} event for a Guild not yet cached.", JDALogger.getLazyString(() -> banned ? "Ban" : "Unban"));
        return null;
    }

    User user = getJDA().getEntityBuilder().createFakeUser(userJson);

    if (banned)
    {
        getJDA().handleEvent(
                new GuildBanEvent(
                        getJDA(), responseNumber,
                        guild, user));
    }
    else
    {
        getJDA().handleEvent(
                new GuildUnbanEvent(
                        getJDA(), responseNumber,
                        guild, user));
    }
    return null;
}
 
Example #6
Source File: GuildListener.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
private void onGuildUnban(GuildUnbanEvent event) {
    modLogBanUnban(ActionType.UNBAN, event.getUser(), event.getGuild());
}
 
Example #7
Source File: PunishmentListener.java    From Arraybot with Apache License 2.0 4 votes vote down vote up
/**
 * When a member is unbanned.
 * @param event The event.
 */
@Override
public void onGuildUnban(@NotNull GuildUnbanEvent event) {
    handlePunishment(event, event.getUser(), PunishmentType.BAN, null, true);
}