mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
Fix UnknownMember warning flood (#115)
If a user was muted using the `MuteRole` method and then banned, the UnknownMember warning will flood your logs when `DateTimeOffset.UtcNow > data.MutedUntil` becomes true, because there is no user in the server to unmute. --------- Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com>
This commit is contained in:
parent
1ab5a640a9
commit
f2db7f016c
1 changed files with 38 additions and 29 deletions
|
@ -80,8 +80,17 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
var failedResults = new List<Result>();
|
||||
var id = data.Id.ToSnowflake();
|
||||
|
||||
var punishmentsResult = await CheckMemberPunishmentsAsync(guildId, id, data, ct);
|
||||
failedResults.AddIfFailed(punishmentsResult);
|
||||
var autoUnbanResult = await TryAutoUnbanAsync(guildId, id, data, ct);
|
||||
failedResults.AddIfFailed(autoUnbanResult);
|
||||
|
||||
var guildMemberResult = await _guildApi.GetGuildMemberAsync(guildId, id, ct);
|
||||
if (!guildMemberResult.IsDefined(out var guildMember))
|
||||
{
|
||||
return failedResults.AggregateErrors();
|
||||
}
|
||||
|
||||
var autoUnmuteResult = await TryAutoUnmuteAsync(guildId, id, data, ct);
|
||||
failedResults.AddIfFailed(autoUnmuteResult);
|
||||
|
||||
if (defaultRole.Value is not 0 && !data.Roles.Contains(defaultRole.Value))
|
||||
{
|
||||
|
@ -90,12 +99,6 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
failedResults.AddIfFailed(addResult);
|
||||
}
|
||||
|
||||
var guildMemberResult = await _guildApi.GetGuildMemberAsync(guildId, id, ct);
|
||||
if (!guildMemberResult.IsDefined(out var guildMember))
|
||||
{
|
||||
return failedResults.AggregateErrors();
|
||||
}
|
||||
|
||||
if (!guildMember.User.IsDefined(out var user))
|
||||
{
|
||||
failedResults.AddIfFailed(new ArgumentNullError(nameof(guildMember.User)));
|
||||
|
@ -117,11 +120,14 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
return failedResults.AggregateErrors();
|
||||
}
|
||||
|
||||
private async Task<Result> CheckMemberPunishmentsAsync(
|
||||
private async Task<Result> TryAutoUnbanAsync(
|
||||
Snowflake guildId, Snowflake id, MemberData data, CancellationToken ct)
|
||||
{
|
||||
if (DateTimeOffset.UtcNow > data.BannedUntil)
|
||||
if (DateTimeOffset.UtcNow <= data.BannedUntil)
|
||||
{
|
||||
return Result.FromSuccess();
|
||||
}
|
||||
|
||||
var unbanResult = await _guildApi.RemoveGuildBanAsync(
|
||||
guildId, id, Messages.PunishmentExpired.EncodeHeader(), ct);
|
||||
if (unbanResult.IsSuccess)
|
||||
|
@ -132,8 +138,14 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
return unbanResult;
|
||||
}
|
||||
|
||||
if (DateTimeOffset.UtcNow > data.MutedUntil)
|
||||
private async Task<Result> TryAutoUnmuteAsync(
|
||||
Snowflake guildId, Snowflake id, MemberData data, CancellationToken ct)
|
||||
{
|
||||
if (DateTimeOffset.UtcNow <= data.MutedUntil)
|
||||
{
|
||||
return Result.FromSuccess();
|
||||
}
|
||||
|
||||
var unmuteResult = await _guildApi.ModifyGuildMemberAsync(
|
||||
guildId, id, roles: data.Roles.ConvertAll(r => r.ToSnowflake()),
|
||||
reason: Messages.PunishmentExpired.EncodeHeader(), ct: ct);
|
||||
|
@ -145,9 +157,6 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
return unmuteResult;
|
||||
}
|
||||
|
||||
return Result.FromSuccess();
|
||||
}
|
||||
|
||||
private async Task<Result> FilterNicknameAsync(Snowflake guildId, IUser user, IGuildMember member,
|
||||
CancellationToken ct)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue