#Help with BanType

1 messages · Page 1 of 1 (latest)

meager flicker
#

Good morning! I’m a bit confused — what does BanType.NULL mean?

hollow sun
#

Depends on where you're seeing it

#

BanType.NULL means the ban isn't a User ban and it isn't an IP ban

edgy nexus
#

It mostly same as would be "BanType.None", aka is not define what BanType used.

hollow sun
#

So an empty/null ban type of 0 is considered a User ban

edgy nexus
#

Yeah

meager flicker
#

And by the way, checking for .BanTypeNULL partly solves this, but then you have to struggle with the EventArgs, because when the value is NULL, almost all of them are NULL as well.

hollow sun
#

Oh well they sometimes do

#

In order to apply a new ban, the old one needs to be revoked

#

So if they have a ban, it does

#

It's odd to me that you're getting BanType.NULL

#

I'm not seeing how that would happen

meager flicker
# hollow sun I'm not seeing how that would happen

Look, in this situation both offline bans and unbans get processed.

    public override void   OnServerBanRevoked(BanRevokedEventArgs ev)  
    {  
        if (Config.UnbanLogChannelId == 0)  
            return;  
  
        if (!Client.TryGetOrAddChannel(Config.UnbanLogChannelId, out SocketTextChannel channel))  
        {  
            Logger.Error(  
                LoggingUtils.GenerateMissingChannelMessage("unban logs", Config.UnbanLogChannelId, Config.GuildId));  
            return;  
        }  
  
        TranslationBuilder builder = new TranslationBuilder()  
            .AddCustomReplacer("userid", ev.BanDetails.Id)  
            .AddCustomReplacer("adminid", ev.BanDetails.Issuer);  
  
        Translation.UnbanLogEmbed.SendToChannel(channel, builder);  
    }  
#

But in this situation, unbans aren't being detected, and offline bans also aren't being detected.

    public override void OnServerBanRevoked(BanRevokedEventArgs ev)
    {
        if (ev?.BanDetails == null)
        {
            Logger.Warn("OnServerBanRevoked: BanDetails is NULL (offline expire or API bug)");
            return;
        }

        if (Config?.UnbanLogChannelId == 0)
            return;

        if (ev.BanType == BanHandler.BanType.NULL)
            return;


        if (!Client.TryGetOrAddChannel(Config.UnbanLogChannelId, out SocketTextChannel channel) || channel == null)
            return;

        string reason = string.IsNullOrWhiteSpace(ev.BanDetails.Reason)
            ? "Not specified"
            : ev.BanDetails.Reason;

        TranslationBuilder builder = new TranslationBuilder()
        .AddCustomReplacer("userid", ev.BanDetails.Id ?? "Unknown")
        .AddCustomReplacer("reason", reason);

        if (Translation?.OfflineBanLogEmbed == null)
        {
            Logger.Warn("OfflineBanLogEmbed is NULL");
            return;
        }

        Translation.OfflineBanLogEmbed.SendToChannel(channel, builder);
    }

Maybe I'm misunderstanding something, but do you know how I can separate these two events and apply different logic for each of them?

hollow sun
#

Also, I think you're still misunderstanding

#

OnServerBanRevoked is not fired when an offline ban happens

#

It's fired when an unban happens / a ban is revoked

#

It just also happens that when you ban someone, if they have a pre-existing ban, that pre-existing ban is revoked before the new ban is added

hollow sun
#

The reason you've found that it only fires when an offline ban is issued is because if a player is online, then they don't have an active ban that needs to be revoked

#

This also means that not every offline ban triggers the BanRevoked event

#

It only triggers when the offline ban is overriding another ban that needs to be revoked

#

That's why LabAPI has separate events for it

#

BanIssued means a new ban happened

#

BanUpdated means an existing ban was overriden

meager flicker
hollow sun