From 01a73ad5745b03e8fd378a11412905beef1b22f0 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Sun, 24 Sep 2023 13:03:42 +0200 Subject: [PATCH] Revert "Merge remote-tracking branch 'origin/main' into cleanup/nullability-and-other-things" This reverts commit ca9f0a7373e71f2c9cdb544f8d004eb0287f3286, reversing changes made to 36f2a6b37c8baa7b3857834620d3f1187036d021. --- .../Entities/Guild/DiscordGuild.AuditLog.cs | 639 +++++++++++++----- 1 file changed, 464 insertions(+), 175 deletions(-) diff --git a/DisCatSharp/Entities/Guild/DiscordGuild.AuditLog.cs b/DisCatSharp/Entities/Guild/DiscordGuild.AuditLog.cs index e3c780d3f..e414aaf3d 100644 --- a/DisCatSharp/Entities/Guild/DiscordGuild.AuditLog.cs +++ b/DisCatSharp/Entities/Guild/DiscordGuild.AuditLog.cs @@ -29,28 +29,32 @@ public partial class DiscordGuild /// A collection of requested audit log entries. /// Thrown when the client does not have the permission. /// Thrown when Discord is unable to process the request. - public async Task> GetAuditLogsAsync(int? limit = null, DiscordMember byMember = null, AuditLogActionType? actionType = null) + public async Task> GetAuditLogsAsync( + int? limit = null, DiscordMember? byMember = null, AuditLogActionType? actionType = null + ) { var alrs = new List(); - int ac = 1, tc = 0, rmn = 100; + int ac = 1, tc = 0; var last = 0ul; while (ac > 0) { - rmn = limit != null ? limit.Value - tc : 100; + var rmn = limit != null ? limit.Value - tc : 100; rmn = Math.Min(100, rmn); if (rmn <= 0) break; - var alr = await this.Discord.ApiClient.GetAuditLogsAsync(this.Id, rmn, null, last == 0 ? null : last, byMember?.Id, (int?)actionType).ConfigureAwait(false); + var alr = await this.Discord.ApiClient + .GetAuditLogsAsync(this.Id, rmn, null, last == 0 ? null : last, byMember?.Id, + (int?)actionType).ConfigureAwait(false); ac = alr.Entries.Count; tc += ac; - if (ac > 0) - { - last = alr.Entries[alr.Entries.Count - 1].Id; - alrs.Add(alr); - } + if (ac <= 0) + continue; + + last = alr.Entries[^1].Id; + alrs.Add(alr); } - var auditLogResult = await this.ProcessAuditLog(alrs).ConfigureAwait(false); + var auditLogResult = await this.ProcessAuditLogAsync(alrs).ConfigureAwait(false); return auditLogResult; } @@ -59,7 +63,7 @@ public async Task> GetAuditLogsAsync(int? li /// /// A list of raw audit log objects. /// The processed audit log list as readonly. - internal async Task> ProcessAuditLog(List auditLogApiResult) + internal async Task> ProcessAuditLogAsync(List auditLogApiResult) { List amr = new(); if (auditLogApiResult.Any(ar => ar.Users != null && ar.Users.Any())) @@ -80,7 +84,10 @@ internal async Task> ProcessAuditLog(List { old.Username = xu.Username; @@ -118,7 +125,15 @@ internal async Task> ProcessAuditLog(List ams = new(); Dictionary amd = new(); if (amr.Any()) - ams = amr.Select(xau => this.MembersInternal != null && this.MembersInternal.TryGetValue(xau.Id, out var member) ? member : new() { Discord = this.Discord, Id = xau.Id, GuildId = this.Id }).ToList(); + ams = amr.Select(xau => this.MembersInternal != null && + this.MembersInternal.TryGetValue(xau.Id, out var member) + ? member + : new() + { + Discord = this.Discord, + Id = xau.Id, + GuildId = this.Id + }).ToList(); if (ams.Any()) amd = ams.ToDictionary(xm => xm.Id, xm => xm); @@ -134,7 +149,18 @@ internal async Task> ProcessAuditLog(List xh.Id, xh => xh); - var amh = ahr.Select(xah => whs.TryGetValue(xah.Id, out var webhook) ? webhook : new() { Discord = this.Discord, Name = xah.Name, Id = xah.Id, AvatarHash = xah.AvatarHash, ChannelId = xah.ChannelId, GuildId = xah.GuildId, Token = xah.Token }); + var amh = ahr.Select(xah => whs.TryGetValue(xah.Id, out var webhook) + ? webhook + : new() + { + Discord = this.Discord, + Name = xah.Name, + Id = xah.Id, + AvatarHash = xah.AvatarHash, + ChannelId = xah.ChannelId, + GuildId = xah.GuildId, + Token = xah.Token + }); ahd = amh.ToDictionary(xh => xh.Id, xh => xh); } @@ -163,13 +189,25 @@ internal async Task> ProcessAuditLog(List GetChannelChange() { - ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, + out t1); + ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, + out t2); return new() { - Before = this.GetChannel(t1) ?? new DiscordChannel { Id = t1, Discord = this.Discord, GuildId = this.Id }, - After = this.GetChannel(t2) ?? new DiscordChannel { Id = t1, Discord = this.Discord, GuildId = this.Id } + Before = this.GetChannel(t1) ?? new DiscordChannel + { + Id = t1, + Discord = this.Discord, + GuildId = this.Id + }, + After = this.GetChannel(t2) ?? new DiscordChannel + { + Id = t1, + Discord = this.Discord, + GuildId = this.Id + } }; } @@ -186,16 +224,26 @@ PropertyChange GetChannelChange() case "owner_id": entrygld.OwnerChange = new() { - Before = this.MembersInternal != null && this.MembersInternal.TryGetValue(xc.OldValueUlong, out var oldMember) ? oldMember : await this.GetMemberAsync(xc.OldValueUlong).ConfigureAwait(false), - After = this.MembersInternal != null && this.MembersInternal.TryGetValue(xc.NewValueUlong, out var newMember) ? newMember : await this.GetMemberAsync(xc.NewValueUlong).ConfigureAwait(false) + Before = this.MembersInternal != null && + this.MembersInternal.TryGetValue(xc.OldValueUlong, out var oldMember) + ? oldMember + : await this.GetMemberAsync(xc.OldValueUlong).ConfigureAwait(false), + After = this.MembersInternal != null && + this.MembersInternal.TryGetValue(xc.NewValueUlong, out var newMember) + ? newMember + : await this.GetMemberAsync(xc.NewValueUlong).ConfigureAwait(false) }; break; case "icon_hash": entrygld.IconChange = new() { - Before = xc.OldValueString != null ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.ICONS}/{this.Id}/{xc.OldValueString}.webp" : null, - After = xc.OldValueString != null ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.ICONS}/{this.Id}/{xc.NewValueString}.webp" : null + Before = xc.OldValueString != null + ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.ICONS}/{this.Id}/{xc.OldValueString}.webp" + : null, + After = xc.OldValueString != null + ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.ICONS}/{this.Id}/{xc.NewValueString}.webp" + : null }; break; @@ -234,8 +282,12 @@ PropertyChange GetChannelChange() case "splash_hash": entrygld.SplashChange = new() { - Before = xc.OldValueString != null ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.SPLASHES}/{this.Id}/{xc.OldValueString}.webp?size=2048" : null, - After = xc.NewValueString != null ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.SPLASHES}/{this.Id}/{xc.NewValueString}.webp?size=2048" : null + Before = xc.OldValueString != null + ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.SPLASHES}/{this.Id}/{xc.OldValueString}.webp?size=2048" + : null, + After = xc.NewValueString != null + ? $"{DiscordDomain.GetDomain(CoreDomain.DiscordCdn).Url}{Endpoints.SPLASHES}/{this.Id}/{xc.NewValueString}.webp?size=2048" + : null }; break; @@ -293,10 +345,13 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in guild update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in guild update: {Key} - this should be reported to library developers", + xc.Key); break; } } + break; case AuditLogActionType.ChannelCreate: @@ -304,12 +359,16 @@ PropertyChange GetChannelChange() case AuditLogActionType.ChannelUpdate: entry = new DiscordAuditLogChannelEntry { - Target = this.GetChannel(xac.TargetId.Value) ?? new DiscordChannel { Id = xac.TargetId.Value, Discord = this.Discord, GuildId = this.Id } + Target = this.GetChannel(xac.TargetId.Value) ?? new DiscordChannel + { + Id = xac.TargetId.Value, + Discord = this.Discord, + GuildId = this.Id + } }; var entrychn = entry as DiscordAuditLogChannelEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "name": @@ -321,8 +380,10 @@ PropertyChange GetChannelChange() break; case "type": - p1 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entrychn.TypeChange = new() { @@ -342,16 +403,32 @@ PropertyChange GetChannelChange() case "permission_overwrites": var olds = xc.OldValues?.OfType() ?.Select(xjo => xjo.ToObject()) - ?.Select(xo => { xo.Discord = this.Discord; return xo; }); + ?.Select(xo => + { + xo.Discord = this.Discord; + return xo; + }); var news = xc.NewValues?.OfType() ?.Select(xjo => xjo.ToObject()) - ?.Select(xo => { xo.Discord = this.Discord; return xo; }); + ?.Select(xo => + { + xo.Discord = this.Discord; + return xo; + }); entrychn.OverwriteChange = new() { - Before = olds != null ? new ReadOnlyCollection(new List(olds)) : null, - After = news != null ? new ReadOnlyCollection(new List(news)) : null + Before = olds != null + ? new + ReadOnlyCollection< + DiscordOverwrite>(new List(olds)) + : null, + After = news != null + ? new + ReadOnlyCollection< + DiscordOverwrite>(new List(news)) + : null }; break; @@ -413,25 +490,39 @@ PropertyChange GetChannelChange() case "available_tags": var oldTags = xc.OldValues?.OfType() ?.Select(xjo => xjo.ToObject()) - ?.Select(xo => { xo.Discord = this.Discord; return xo; }); + ?.Select(xo => + { + xo.Discord = this.Discord; + return xo; + }); var newTags = xc.NewValues?.OfType() ?.Select(xjo => xjo.ToObject()) - ?.Select(xo => { xo.Discord = this.Discord; return xo; }); + ?.Select(xo => + { + xo.Discord = this.Discord; + return xo; + }); entrychn.AvailableTagsChange = new() { - Before = oldTags != null ? new List(new List(oldTags)) : null, - After = newTags != null ? new List(new List(newTags)) : null + Before = oldTags != null + ? new List(new List(oldTags)) + : null, + After = newTags != null + ? new List(new List(newTags)) + : null }; break; default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in channel update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in channel update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; case AuditLogActionType.OverwriteCreate: @@ -439,18 +530,20 @@ PropertyChange GetChannelChange() case AuditLogActionType.OverwriteUpdate: entry = new DiscordAuditLogOverwriteEntry { - Target = this.GetChannel(xac.TargetId.Value)?.PermissionOverwrites.FirstOrDefault(xo => xo.Id == xac.Options.Id), + Target = this.GetChannel(xac.TargetId.Value)?.PermissionOverwrites + .FirstOrDefault(xo => xo.Id == xac.Options.Id), Channel = this.GetChannel(xac.TargetId.Value) }; var entryovr = entry as DiscordAuditLogOverwriteEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "deny": - p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entryovr.DenyChange = new() { @@ -460,8 +553,10 @@ PropertyChange GetChannelChange() break; case "allow": - p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entryovr.AllowChange = new() { @@ -479,8 +574,10 @@ PropertyChange GetChannelChange() break; case "id": - p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entryovr.TargetIdChange = new() { @@ -491,16 +588,25 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in overwrite update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in overwrite update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; case AuditLogActionType.Kick: entry = new DiscordAuditLogKickEntry { - Target = amd.TryGetValue(xac.TargetId.Value, out var kickMember) ? kickMember : new() { Id = xac.TargetId.Value, Discord = this.Discord, GuildId = this.Id } + Target = amd.TryGetValue(xac.TargetId.Value, out var kickMember) + ? kickMember + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord, + GuildId = this.Id + } }; break; @@ -516,7 +622,14 @@ PropertyChange GetChannelChange() case AuditLogActionType.Unban: entry = new DiscordAuditLogBanEntry { - Target = amd.TryGetValue(xac.TargetId.Value, out var unbanMember) ? unbanMember : new() { Id = xac.TargetId.Value, Discord = this.Discord, GuildId = this.Id } + Target = amd.TryGetValue(xac.TargetId.Value, out var unbanMember) + ? unbanMember + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord, + GuildId = this.Id + } }; break; @@ -524,12 +637,18 @@ PropertyChange GetChannelChange() case AuditLogActionType.MemberRoleUpdate: entry = new DiscordAuditLogMemberUpdateEntry { - Target = amd.TryGetValue(xac.TargetId.Value, out var roleUpdMember) ? roleUpdMember : new() { Id = xac.TargetId.Value, Discord = this.Discord, GuildId = this.Id } + Target = amd.TryGetValue(xac.TargetId.Value, out var roleUpdMember) + ? roleUpdMember + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord, + GuildId = this.Id + } }; var entrymbu = entry as DiscordAuditLogMemberUpdateEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "nick": @@ -564,19 +683,25 @@ PropertyChange GetChannelChange() break; case "$add": - entrymbu.AddedRoles = new ReadOnlyCollection(xc.NewValues.Select(xo => (ulong)xo["id"]).Select(this.GetRole).ToList()); + entrymbu.AddedRoles = + new ReadOnlyCollection(xc.NewValues.Select(xo => (ulong)xo["id"]) + .Select(this.GetRole).ToList()); break; case "$remove": - entrymbu.RemovedRoles = new ReadOnlyCollection(xc.NewValues.Select(xo => (ulong)xo["id"]).Select(this.GetRole).ToList()); + entrymbu.RemovedRoles = + new ReadOnlyCollection(xc.NewValues.Select(xo => (ulong)xo["id"]) + .Select(this.GetRole).ToList()); break; default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in member update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in member update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; case AuditLogActionType.RoleCreate: @@ -584,12 +709,15 @@ PropertyChange GetChannelChange() case AuditLogActionType.RoleUpdate: entry = new DiscordAuditLogRoleUpdateEntry { - Target = this.GetRole(xac.TargetId.Value) ?? new DiscordRole { Id = xac.TargetId.Value, Discord = this.Discord } + Target = this.GetRole(xac.TargetId.Value) ?? new DiscordRole + { + Id = xac.TargetId.Value, + Discord = this.Discord + } }; var entryrol = entry as DiscordAuditLogRoleUpdateEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "name": @@ -601,8 +729,10 @@ PropertyChange GetChannelChange() break; case "color": - p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t3); - p2 = int.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t4); + p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t3); + p2 = int.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t4); entryrol.ColorChange = new() { @@ -623,15 +753,15 @@ PropertyChange GetChannelChange() entryrol.PositionChange = new() { Before = xc.OldValue != null ? (int?)(long)xc.OldValue : null, - After = xc.NewValue != null ? (int?)(long)xc.NewValue : null, + After = xc.NewValue != null ? (int?)(long)xc.NewValue : null }; break; case "mentionable": entryrol.MentionableChange = new() { - Before = xc.OldValue != null ? (bool?)xc.OldValue : null, - After = xc.NewValue != null ? (bool?)xc.NewValue : null + Before = (bool?)xc.OldValue, + After = (bool?)xc.NewValue }; break; @@ -653,10 +783,12 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in role update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in role update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; case AuditLogActionType.InviteCreate: @@ -678,12 +810,13 @@ PropertyChange GetChannelChange() var entryinv = entry as DiscordAuditLogInviteEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "max_age": - p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t3); - p2 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t4); + p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t3); + p2 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t4); entryinv.MaxAgeChange = new() { @@ -705,30 +838,62 @@ PropertyChange GetChannelChange() case "temporary": entryinv.TemporaryChange = new() { - Before = xc.OldValue != null ? (bool?)xc.OldValue : null, - After = xc.NewValue != null ? (bool?)xc.NewValue : null + Before = (bool?)xc.OldValue, + After = (bool?)xc.NewValue }; break; case "inviter_id": - p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entryinv.InviterChange = new() { - Before = amd.TryGetValue(t1, out var propBeforeMember) ? propBeforeMember : new() { Id = t1, Discord = this.Discord, GuildId = this.Id }, - After = amd.TryGetValue(t2, out var propAfterMember) ? propAfterMember : new() { Id = t1, Discord = this.Discord, GuildId = this.Id }, + Before = amd.TryGetValue(t1, out var propBeforeMember) + ? propBeforeMember + : new() + { + Id = t1, + Discord = this.Discord, + GuildId = this.Id + }, + After = amd.TryGetValue(t2, out var propAfterMember) + ? propAfterMember + : new() + { + Id = t1, + Discord = this.Discord, + GuildId = this.Id + } }; break; case "channel_id": - p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entryinv.ChannelChange = new() { - Before = p1 ? this.GetChannel(t1) ?? new DiscordChannel { Id = t1, Discord = this.Discord, GuildId = this.Id } : null, - After = p2 ? this.GetChannel(t2) ?? new DiscordChannel { Id = t1, Discord = this.Discord, GuildId = this.Id } : null + Before = p1 + ? this.GetChannel(t1) ?? new DiscordChannel + { + Id = t1, + Discord = this.Discord, + GuildId = this.Id + } + : null, + After = p2 + ? this.GetChannel(t2) ?? new DiscordChannel + { + Id = t1, + Discord = this.Discord, + GuildId = this.Id + } + : null }; var ch = entryinv.ChannelChange.Before ?? entryinv.ChannelChange.After; @@ -738,13 +903,15 @@ PropertyChange GetChannelChange() Discord = this.Discord, Id = p1 ? t1 : t2, Name = ch?.Name, - Type = cht != null ? cht.Value : ChannelType.Unknown + Type = cht ?? ChannelType.Unknown }; break; case "uses": - p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t3); - p2 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t4); + p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t3); + p2 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t4); entryinv.UsesChange = new() { @@ -754,8 +921,10 @@ PropertyChange GetChannelChange() break; case "max_uses": - p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t3); - p2 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t4); + p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t3); + p2 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t4); entryinv.MaxUsesChange = new() { @@ -765,13 +934,13 @@ PropertyChange GetChannelChange() break; // TODO: Add changes for target application - default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in invite update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in invite update: {Key} - this should be reported to library developers", + xc.Key); break; } - } entryinv.Target = inv; break; @@ -781,17 +950,24 @@ PropertyChange GetChannelChange() case AuditLogActionType.WebhookUpdate: entry = new DiscordAuditLogWebhookEntry { - Target = ahd.TryGetValue(xac.TargetId.Value, out var webhook) ? webhook : new() { Id = xac.TargetId.Value, Discord = this.Discord } + Target = ahd.TryGetValue(xac.TargetId.Value, out var webhook) + ? webhook + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord + } }; var entrywhk = entry as DiscordAuditLogWebhookEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "application_id": // ??? - p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entrywhk.IdChange = new() { @@ -809,19 +985,37 @@ PropertyChange GetChannelChange() break; case "channel_id": - p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entrywhk.ChannelChange = new() { - Before = p1 ? this.GetChannel(t1) ?? new DiscordChannel { Id = t1, Discord = this.Discord, GuildId = this.Id } : null, - After = p2 ? this.GetChannel(t2) ?? new DiscordChannel { Id = t1, Discord = this.Discord, GuildId = this.Id } : null + Before = p1 + ? this.GetChannel(t1) ?? new DiscordChannel + { + Id = t1, + Discord = this.Discord, + GuildId = this.Id + } + : null, + After = p2 + ? this.GetChannel(t2) ?? new DiscordChannel + { + Id = t1, + Discord = this.Discord, + GuildId = this.Id + } + : null }; break; case "type": // ??? - p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t3); - p2 = int.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t4); + p1 = int.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t3); + p2 = int.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t4); entrywhk.TypeChange = new() { @@ -840,10 +1034,12 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in webhook update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in webhook update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; case AuditLogActionType.EmojiCreate: @@ -851,12 +1047,17 @@ PropertyChange GetChannelChange() case AuditLogActionType.EmojiUpdate: entry = new DiscordAuditLogEmojiEntry { - Target = this.EmojisInternal.TryGetValue(xac.TargetId.Value, out var target) ? target : new() { Id = xac.TargetId.Value, Discord = this.Discord } + Target = this.EmojisInternal.TryGetValue(xac.TargetId.Value, out var target) + ? target + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord + } }; var entryemo = entry as DiscordAuditLogEmojiEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "name": @@ -869,10 +1070,12 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in emote update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in emote update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; case AuditLogActionType.StageInstanceCreate: @@ -880,12 +1083,17 @@ PropertyChange GetChannelChange() case AuditLogActionType.StageInstanceUpdate: entry = new DiscordAuditLogStageEntry { - Target = this.StageInstancesInternal.TryGetValue(xac.TargetId.Value, out var stage) ? stage : new() { Id = xac.TargetId.Value, Discord = this.Discord } + Target = this.StageInstancesInternal.TryGetValue(xac.TargetId.Value, out var stage) + ? stage + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord + } }; var entrysta = entry as DiscordAuditLogStageEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "topic": @@ -898,10 +1106,12 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in stage instance update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in stage instance update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; case AuditLogActionType.StickerCreate: @@ -909,12 +1119,17 @@ PropertyChange GetChannelChange() case AuditLogActionType.StickerUpdate: entry = new DiscordAuditLogStickerEntry { - Target = this.StickersInternal.TryGetValue(xac.TargetId.Value, out var sticker) ? sticker : new() { Id = xac.TargetId.Value, Discord = this.Discord } + Target = this.StickersInternal.TryGetValue(xac.TargetId.Value, out var sticker) + ? sticker + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord + } }; var entrysti = entry as DiscordAuditLogStickerEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "name": @@ -949,7 +1164,7 @@ PropertyChange GetChannelChange() entrysti.AvailabilityChange = new() { Before = (bool?)xc.OldValue, - After = (bool?)xc.NewValue, + After = (bool?)xc.NewValue }; break; case "asset": @@ -967,8 +1182,10 @@ PropertyChange GetChannelChange() }; break; case "type": - p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t5); - p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t6); + p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t5); + p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t6); entrysti.TypeChange = new() { Before = p1 ? (StickerType?)t5 : null, @@ -976,8 +1193,10 @@ PropertyChange GetChannelChange() }; break; case "format_type": - p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t5); - p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t6); + p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t5); + p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t6); entrysti.FormatChange = new() { Before = p1 ? (StickerFormat?)t5 : null, @@ -987,13 +1206,13 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in sticker update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in sticker update: {Key} - this should be reported to library developers", + xc.Key); break; } - } - break; - + break; case AuditLogActionType.MessageDelete: case AuditLogActionType.MessageBulkDelete: @@ -1004,18 +1223,26 @@ PropertyChange GetChannelChange() if (xac.Options != null) { - entrymsg.Channel = this.GetChannel(xac.Options.ChannelId) ?? new DiscordChannel { Id = xac.Options.ChannelId, Discord = this.Discord, GuildId = this.Id }; + entrymsg.Channel = this.GetChannel(xac.Options.ChannelId) ?? new DiscordChannel + { + Id = xac.Options.ChannelId, + Discord = this.Discord, + GuildId = this.Id + }; entrymsg.MessageCount = xac.Options.Count; } if (entrymsg.Channel != null) - { - entrymsg.Target = this.Discord is DiscordClient dc - && dc.MessageCache != null - && dc.MessageCache.TryGet(xm => xm.Id == xac.TargetId.Value && xm.ChannelId == entrymsg.Channel.Id, out var msg) + entrymsg.Target = this.Discord is DiscordClient { MessageCache: not null } dc + && dc.MessageCache + .TryGet(xm => xm.Id == xac.TargetId.Value && xm.ChannelId == entrymsg.Channel.Id, + out var msg) ? msg - : new() { Discord = this.Discord, Id = xac.TargetId.Value }; - } + : new() + { + Discord = this.Discord, + Id = xac.TargetId.Value + }; break; } @@ -1026,24 +1253,36 @@ PropertyChange GetChannelChange() var entrypin = entry as DiscordAuditLogMessagePinEntry; - if (this.Discord is not DiscordClient dc) - { - break; - } + if (this.Discord is not DiscordClient dc) break; if (xac.Options != null) { DiscordMessage message = default; - dc.MessageCache?.TryGet(x => x.Id == xac.Options.MessageId && x.ChannelId == xac.Options.ChannelId, out message); + dc.MessageCache + ?.TryGet(x => x.Id == xac.Options.MessageId && x.ChannelId == xac.Options.ChannelId, + out message); - entrypin.Channel = this.GetChannel(xac.Options.ChannelId) ?? new DiscordChannel { Id = xac.Options.ChannelId, Discord = this.Discord, GuildId = this.Id }; - entrypin.Message = message ?? new DiscordMessage { Id = xac.Options.MessageId, Discord = this.Discord }; + entrypin.Channel = this.GetChannel(xac.Options.ChannelId) ?? new DiscordChannel + { + Id = xac.Options.ChannelId, + Discord = this.Discord, + GuildId = this.Id + }; + entrypin.Message = message ?? new DiscordMessage + { + Id = xac.Options.MessageId, + Discord = this.Discord + }; } if (xac.TargetId.HasValue) { dc.UserCache.TryGetValue(xac.TargetId.Value, out var user); - entrypin.Target = user ?? new DiscordUser { Id = user.Id, Discord = this.Discord }; + entrypin.Target = user ?? new DiscordUser + { + Id = user.Id, + Discord = this.Discord + }; } break; @@ -1053,13 +1292,14 @@ PropertyChange GetChannelChange() { entry = new DiscordAuditLogBotAddEntry(); - if (!(this.Discord is DiscordClient dc && xac.TargetId.HasValue)) - { - break; - } + if (!(this.Discord is DiscordClient dc && xac.TargetId.HasValue)) break; dc.UserCache.TryGetValue(xac.TargetId.Value, out var bot); - (entry as DiscordAuditLogBotAddEntry).TargetBot = bot ?? new DiscordUser { Id = xac.TargetId.Value, Discord = this.Discord }; + (entry as DiscordAuditLogBotAddEntry).TargetBot = bot ?? new DiscordUser + { + Id = xac.TargetId.Value, + Discord = this.Discord + }; break; } @@ -1067,15 +1307,17 @@ PropertyChange GetChannelChange() case AuditLogActionType.MemberMove: entry = new DiscordAuditLogMemberMoveEntry(); - if (xac.Options == null) - { - break; - } + if (xac.Options == null) break; var moveentry = entry as DiscordAuditLogMemberMoveEntry; moveentry.UserCount = xac.Options.Count; - moveentry.Channel = this.GetChannel(xac.Options.ChannelId) ?? new DiscordChannel { Id = xac.Options.ChannelId, Discord = this.Discord, GuildId = this.Id }; + moveentry.Channel = this.GetChannel(xac.Options.ChannelId) ?? new DiscordChannel + { + Id = xac.Options.ChannelId, + Discord = this.Discord, + GuildId = this.Id + }; break; case AuditLogActionType.MemberDisconnect: @@ -1092,7 +1334,6 @@ PropertyChange GetChannelChange() var integentry = entry as DiscordAuditLogIntegrationEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "type": @@ -1126,10 +1367,12 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in integration update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in integration update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; case AuditLogActionType.ThreadCreate: @@ -1137,12 +1380,17 @@ PropertyChange GetChannelChange() case AuditLogActionType.ThreadUpdate: entry = new DiscordAuditLogThreadEntry { - Target = this.ThreadsInternal.TryGetValue(xac.TargetId.Value, out var thread) ? thread : new() { Id = xac.TargetId.Value, Discord = this.Discord } + Target = this.ThreadsInternal.TryGetValue(xac.TargetId.Value, out var thread) + ? thread + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord + } }; var entrythr = entry as DiscordAuditLogThreadEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "name": @@ -1154,8 +1402,10 @@ PropertyChange GetChannelChange() break; case "type": - p1 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t1); - p2 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t2); + p1 = ulong.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t1); + p2 = ulong.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t2); entrythr.TypeChange = new() { @@ -1167,30 +1417,32 @@ PropertyChange GetChannelChange() case "archived": entrythr.ArchivedChange = new() { - Before = xc.OldValue != null ? (bool?)xc.OldValue : null, - After = xc.NewValue != null ? (bool?)xc.NewValue : null + Before = (bool?)xc.OldValue, + After = (bool?)xc.NewValue }; break; case "locked": entrythr.LockedChange = new() { - Before = xc.OldValue != null ? (bool?)xc.OldValue : null, - After = xc.NewValue != null ? (bool?)xc.NewValue : null + Before = (bool?)xc.OldValue, + After = (bool?)xc.NewValue }; break; case "invitable": entrythr.InvitableChange = new() { - Before = xc.OldValue != null ? (bool?)xc.OldValue : null, - After = xc.NewValue != null ? (bool?)xc.NewValue : null + Before = (bool?)xc.OldValue, + After = (bool?)xc.NewValue }; break; case "auto_archive_duration": - p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t5); - p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t6); + p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t5); + p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t6); entrythr.AutoArchiveDurationChange = new() { @@ -1209,24 +1461,30 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in thread update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in thread update: {Key} - this should be reported to library developers", + xc.Key); break; } - } - break; + break; case AuditLogActionType.GuildScheduledEventCreate: case AuditLogActionType.GuildScheduledEventDelete: case AuditLogActionType.GuildScheduledEventUpdate: entry = new DiscordAuditLogGuildScheduledEventEntry { - Target = this.ScheduledEventsInternal.TryGetValue(xac.TargetId.Value, out var scheduledEvent) ? scheduledEvent : new() { Id = xac.TargetId.Value, Discord = this.Discord } + Target = this.ScheduledEventsInternal.TryGetValue(xac.TargetId.Value, out var scheduledEvent) + ? scheduledEvent + : new() + { + Id = xac.TargetId.Value, + Discord = this.Discord + } }; var entryse = entry as DiscordAuditLogGuildScheduledEventEntry; foreach (var xc in xac.Changes) - { switch (xc.Key.ToLowerInvariant()) { case "channel_id": @@ -1262,8 +1520,10 @@ PropertyChange GetChannelChange() break; case "entity_type": - p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t5); - p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t6); + p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t5); + p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t6); entryse.EntityTypeChange = new() { @@ -1273,8 +1533,10 @@ PropertyChange GetChannelChange() break; case "status": - p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t5); - p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, CultureInfo.InvariantCulture, out t6); + p1 = long.TryParse(xc.OldValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t5); + p2 = long.TryParse(xc.NewValue as string, NumberStyles.Integer, + CultureInfo.InvariantCulture, out t6); entryse.StatusChange = new() { @@ -1285,10 +1547,12 @@ PropertyChange GetChannelChange() default: if (this.Discord.Configuration.ReportMissingFields) - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown key in scheduled event update: {Key} - this should be reported to library developers", xc.Key); + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown key in scheduled event update: {Key} - this should be reported to library developers", + xc.Key); break; } - } + break; // TODO: Handle ApplicationCommandPermissionUpdate @@ -1324,7 +1588,10 @@ PropertyChange GetChannelChange() break; default: - this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, "Unknown audit log action type: {Key} - this should be reported to library developers", (int)xac.ActionType); + if (this.Discord.Configuration.ReportMissingFields) + this.Discord.Logger.LogWarning(LoggerEvents.AuditLog, + "Unknown audit log action type: {Key} - this should be reported to library developers", + (int)xac.ActionType); break; } @@ -1333,16 +1600,38 @@ PropertyChange GetChannelChange() entry.ActionCategory = xac.ActionType switch { - AuditLogActionType.ChannelCreate or AuditLogActionType.EmojiCreate or AuditLogActionType.InviteCreate or AuditLogActionType.OverwriteCreate or AuditLogActionType.RoleCreate or AuditLogActionType.WebhookCreate or AuditLogActionType.IntegrationCreate or AuditLogActionType.StickerCreate or AuditLogActionType.StageInstanceCreate or AuditLogActionType.ThreadCreate or AuditLogActionType.GuildScheduledEventCreate or AuditLogActionType.AutoModerationRuleCreate or AuditLogActionType.OnboardingQuestionCreate or AuditLogActionType.ServerGuideCreate => AuditLogActionCategory.Create, - AuditLogActionType.ChannelDelete or AuditLogActionType.EmojiDelete or AuditLogActionType.InviteDelete or AuditLogActionType.MessageDelete or AuditLogActionType.MessageBulkDelete or AuditLogActionType.OverwriteDelete or AuditLogActionType.RoleDelete or AuditLogActionType.WebhookDelete or AuditLogActionType.IntegrationDelete or AuditLogActionType.StickerDelete or AuditLogActionType.StageInstanceDelete or AuditLogActionType.ThreadDelete or AuditLogActionType.GuildScheduledEventDelete or AuditLogActionType.AutoModerationRuleDelete => AuditLogActionCategory.Delete, - AuditLogActionType.ChannelUpdate or AuditLogActionType.EmojiUpdate or AuditLogActionType.InviteUpdate or AuditLogActionType.MemberRoleUpdate or AuditLogActionType.MemberUpdate or AuditLogActionType.OverwriteUpdate or AuditLogActionType.RoleUpdate or AuditLogActionType.WebhookUpdate or AuditLogActionType.IntegrationUpdate or AuditLogActionType.StickerUpdate or AuditLogActionType.StageInstanceUpdate or AuditLogActionType.ThreadUpdate or AuditLogActionType.GuildScheduledEventUpdate or AuditLogActionType.AutoModerationRuleUpdate or AuditLogActionType.OnboardingQuestionUpdate or AuditLogActionType.OnboardingUpdate or AuditLogActionType.ServerGuideUpdate or AuditLogActionType.VoiceChannelStatusUpdate => AuditLogActionCategory.Update, - _ => AuditLogActionCategory.Other, + AuditLogActionType.ChannelCreate or AuditLogActionType.EmojiCreate or AuditLogActionType.InviteCreate + or AuditLogActionType.OverwriteCreate or AuditLogActionType.RoleCreate + or AuditLogActionType.WebhookCreate or AuditLogActionType.IntegrationCreate + or AuditLogActionType.StickerCreate or AuditLogActionType.StageInstanceCreate + or AuditLogActionType.ThreadCreate or AuditLogActionType.GuildScheduledEventCreate + or AuditLogActionType.AutoModerationRuleCreate or AuditLogActionType.OnboardingQuestionCreate + or AuditLogActionType.ServerGuideCreate => AuditLogActionCategory.Create, + AuditLogActionType.ChannelDelete or AuditLogActionType.EmojiDelete or AuditLogActionType.InviteDelete + or AuditLogActionType.MessageDelete or AuditLogActionType.MessageBulkDelete + or AuditLogActionType.OverwriteDelete or AuditLogActionType.RoleDelete + or AuditLogActionType.WebhookDelete or AuditLogActionType.IntegrationDelete + or AuditLogActionType.StickerDelete or AuditLogActionType.StageInstanceDelete + or AuditLogActionType.ThreadDelete or AuditLogActionType.GuildScheduledEventDelete + or AuditLogActionType.AutoModerationRuleDelete => AuditLogActionCategory.Delete, + AuditLogActionType.ChannelUpdate or AuditLogActionType.EmojiUpdate or AuditLogActionType.InviteUpdate + or AuditLogActionType.MemberRoleUpdate or AuditLogActionType.MemberUpdate + or AuditLogActionType.OverwriteUpdate or AuditLogActionType.RoleUpdate + or AuditLogActionType.WebhookUpdate or AuditLogActionType.IntegrationUpdate + or AuditLogActionType.StickerUpdate or AuditLogActionType.StageInstanceUpdate + or AuditLogActionType.ThreadUpdate or AuditLogActionType.GuildScheduledEventUpdate + or AuditLogActionType.AutoModerationRuleUpdate or AuditLogActionType.OnboardingQuestionUpdate + or AuditLogActionType.OnboardingUpdate or AuditLogActionType.ServerGuideUpdate + or AuditLogActionType.VoiceChannelStatusUpdate => AuditLogActionCategory.Update, + _ => AuditLogActionCategory.Other }; entry.Discord = this.Discord; entry.ActionType = xac.ActionType; entry.Id = xac.Id; entry.Reason = xac.Reason; - entry.UserResponsible = amd.Any() && amd.TryGetValue(xac.UserId, out var resp) ? resp : this.MembersInternal[xac.UserId]; + entry.UserResponsible = amd.Any() && amd.TryGetValue(xac.UserId, out var resp) + ? resp + : this.MembersInternal[xac.UserId]; entries.Add(entry); }