From 1eb7a53f7869c7e1a765f58338eaed376dabf058 Mon Sep 17 00:00:00 2001 From: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> Date: Thu, 15 Feb 2024 20:29:33 +0300 Subject: [PATCH] [Fix] NRE in automod audit logs (#2850) * fix nre * no breakings :( --- .../DataTypes/AutoModFlaggedMessageAuditLogData.cs | 10 +++++----- .../SocketAutoModFlaggedMessageAuditLogData.cs | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/AutoModFlaggedMessageAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/AutoModFlaggedMessageAuditLogData.cs index 5b0f13f8..160c3551 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/AutoModFlaggedMessageAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/AutoModFlaggedMessageAuditLogData.cs @@ -8,23 +8,23 @@ namespace Discord.Rest; /// public class AutoModFlaggedMessageAuditLogData : IAuditLogData { - internal AutoModFlaggedMessageAuditLogData(ulong channelId, string autoModRuleName, AutoModTriggerType autoModRuleTriggerType) + internal AutoModFlaggedMessageAuditLogData(ulong? channelId, string autoModRuleName, AutoModTriggerType autoModRuleTriggerType) { - ChannelId = channelId; + ChannelId = channelId ?? 0; AutoModRuleName = autoModRuleName; AutoModRuleTriggerType = autoModRuleTriggerType; } internal static AutoModFlaggedMessageAuditLogData Create(BaseDiscordClient discord, EntryModel entry, Model log) { - return new(entry.Options.ChannelId!.Value, entry.Options.AutoModRuleName, + return new(entry.Options.ChannelId, entry.Options.AutoModRuleName, entry.Options.AutoModRuleTriggerType!.Value); } /// - /// Gets the channel the message was sent in. + /// Gets the channel the message was sent in. Will be 0 if a user profile was flagged. /// - public ulong ChannelId { get; set; } + public ulong? ChannelId { get; set; } /// /// Gets the name of the auto moderation rule that got triggered. diff --git a/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketAutoModFlaggedMessageAuditLogData.cs b/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketAutoModFlaggedMessageAuditLogData.cs index e53f20d1..48408434 100644 --- a/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketAutoModFlaggedMessageAuditLogData.cs +++ b/src/Discord.Net.WebSocket/Entities/AuditLogs/DataTypes/SocketAutoModFlaggedMessageAuditLogData.cs @@ -7,21 +7,21 @@ namespace Discord.WebSocket; /// public class SocketAutoModFlaggedMessageAuditLogData : ISocketAuditLogData { - internal SocketAutoModFlaggedMessageAuditLogData(ulong channelId, string autoModRuleName, AutoModTriggerType autoModRuleTriggerType) + internal SocketAutoModFlaggedMessageAuditLogData(ulong? channelId, string autoModRuleName, AutoModTriggerType autoModRuleTriggerType) { - ChannelId = channelId; + ChannelId = channelId ?? 0; AutoModRuleName = autoModRuleName; AutoModRuleTriggerType = autoModRuleTriggerType; } internal static SocketAutoModFlaggedMessageAuditLogData Create(DiscordSocketClient discord, EntryModel entry) { - return new(entry.Options.ChannelId!.Value, entry.Options.AutoModRuleName, + return new(entry.Options.ChannelId, entry.Options.AutoModRuleName, entry.Options.AutoModRuleTriggerType!.Value); } /// - /// Gets the channel the message was sent in. + /// Gets the channel the message was sent in. Will be 0 if a user profile was flagged. /// public ulong ChannelId { get; set; }