#Help with BanType
1 messages · Page 1 of 1 (latest)
Depends on where you're seeing it
BanType.NULL means the ban isn't a User ban and it isn't an IP ban
It mostly same as would be "BanType.None", aka is not define what BanType used.
It's odd that BanType.NULL is -1 and not 0
So an empty/null ban type of 0 is considered a User ban
Yeah
I just noticed that the OnServerBanRevoked handler is triggered both when a person is unbanned and when an offline ban via oban is applied.
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.
Offline bans invoke the BanRevoked handler?
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
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?
What console output do you get when using this code vs the other code?
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
This logic happens whenever a ban is issued
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
That explains a lot, I guess I just got confused. Thanks!
Yeah all good man!