fix: NullReferenceException in pin/unpin audit logs (#1780)

This commit is contained in:
NeKz
2021-03-10 20:07:19 +01:00
committed by GitHub
parent 6ac5ea1cbb
commit f794163ffa
2 changed files with 20 additions and 8 deletions

View File

@@ -18,9 +18,15 @@ namespace Discord.Rest
} }
internal static MessagePinAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) internal static MessagePinAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
{
RestUser user = null;
if (entry.TargetId.HasValue)
{ {
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
return new MessagePinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, RestUser.Create(discord, userInfo)); user = RestUser.Create(discord, userInfo);
}
return new MessagePinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, user);
} }
/// <summary> /// <summary>
@@ -38,10 +44,10 @@ namespace Discord.Rest
/// </returns> /// </returns>
public ulong ChannelId { get; } public ulong ChannelId { get; }
/// <summary> /// <summary>
/// Gets the user of the message that was pinned. /// Gets the user of the message that was pinned if available.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// A user object representing the user that created the pinned message. /// A user object representing the user that created the pinned message or <see langword="null"/>.
/// </returns> /// </returns>
public IUser Target { get; } public IUser Target { get; }
} }

View File

@@ -18,9 +18,15 @@ namespace Discord.Rest
} }
internal static MessageUnpinAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) internal static MessageUnpinAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
{
RestUser user = null;
if (entry.TargetId.HasValue)
{ {
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
return new MessageUnpinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, RestUser.Create(discord, userInfo)); user = RestUser.Create(discord, userInfo);
}
return new MessageUnpinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, user);
} }
/// <summary> /// <summary>
@@ -38,10 +44,10 @@ namespace Discord.Rest
/// </returns> /// </returns>
public ulong ChannelId { get; } public ulong ChannelId { get; }
/// <summary> /// <summary>
/// Gets the user of the message that was unpinned. /// Gets the user of the message that was unpinned if available.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// A user object representing the user that created the unpinned message. /// A user object representing the user that created the unpinned message or <see langword="null"/>.
/// </returns> /// </returns>
public IUser Target { get; } public IUser Target { get; }
} }