Resolve NRE at get audit for Deleted User (#2304)
This commit is contained in:
@@ -18,12 +18,15 @@ namespace Discord.Rest
|
|||||||
internal static BanAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
internal static BanAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
||||||
{
|
{
|
||||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
return new BanAuditLogData(RestUser.Create(discord, userInfo));
|
return new BanAuditLogData((userInfo != null) ? RestUser.Create(discord, userInfo) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user that was banned.
|
/// Gets the user that was banned.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the user is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user object representing the banned user.
|
/// A user object representing the banned user.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -18,12 +18,15 @@ namespace Discord.Rest
|
|||||||
internal static BotAddAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
internal static BotAddAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
||||||
{
|
{
|
||||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
return new BotAddAuditLogData(RestUser.Create(discord, userInfo));
|
return new BotAddAuditLogData((userInfo != null) ? RestUser.Create(discord, userInfo) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the bot that was added.
|
/// Gets the bot that was added.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the bot is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user object representing the bot.
|
/// A user object representing the bot.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Discord.Rest
|
|||||||
{
|
{
|
||||||
var inviterId = inviterIdModel.NewValue.ToObject<ulong>(discord.ApiClient.Serializer);
|
var inviterId = inviterIdModel.NewValue.ToObject<ulong>(discord.ApiClient.Serializer);
|
||||||
var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId);
|
var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId);
|
||||||
inviter = RestUser.Create(discord, inviterInfo);
|
inviter = (inviterInfo != null) ? RestUser.Create(discord, inviterInfo) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new InviteCreateAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses);
|
return new InviteCreateAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses);
|
||||||
@@ -76,6 +76,9 @@ namespace Discord.Rest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user that created this invite if available.
|
/// Gets the user that created this invite if available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the user is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user that created this invite or <see langword="null"/>.
|
/// A user that created this invite or <see langword="null"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Discord.Rest
|
|||||||
{
|
{
|
||||||
var inviterId = inviterIdModel.OldValue.ToObject<ulong>(discord.ApiClient.Serializer);
|
var inviterId = inviterIdModel.OldValue.ToObject<ulong>(discord.ApiClient.Serializer);
|
||||||
var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId);
|
var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId);
|
||||||
inviter = RestUser.Create(discord, inviterInfo);
|
inviter = (inviterInfo != null) ? RestUser.Create(discord, inviterInfo) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new InviteDeleteAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses);
|
return new InviteDeleteAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses);
|
||||||
@@ -76,6 +76,9 @@ namespace Discord.Rest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user that created this invite if available.
|
/// Gets the user that created this invite if available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the user is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user that created this invite or <see langword="null"/>.
|
/// A user that created this invite or <see langword="null"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Model = Discord.API.AuditLog;
|
using Model = Discord.API.AuditLog;
|
||||||
using EntryModel = Discord.API.AuditLogEntry;
|
using EntryModel = Discord.API.AuditLogEntry;
|
||||||
@@ -18,12 +18,15 @@ namespace Discord.Rest
|
|||||||
internal static KickAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
internal static KickAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
||||||
{
|
{
|
||||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
return new KickAuditLogData(RestUser.Create(discord, userInfo));
|
return new KickAuditLogData((userInfo != null) ? RestUser.Create(discord, userInfo) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user that was kicked.
|
/// Gets the user that was kicked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the user is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user object representing the kicked user.
|
/// A user object representing the kicked user.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Discord.Rest
|
|||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
var user = RestUser.Create(discord, userInfo);
|
RestUser user = (userInfo != null) ? RestUser.Create(discord, userInfo) : null;
|
||||||
|
|
||||||
return new MemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), user);
|
return new MemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace Discord.Rest
|
|||||||
newMute = muteModel?.NewValue?.ToObject<bool>(discord.ApiClient.Serializer);
|
newMute = muteModel?.NewValue?.ToObject<bool>(discord.ApiClient.Serializer);
|
||||||
|
|
||||||
var targetInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var targetInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
var user = RestUser.Create(discord, targetInfo);
|
RestUser user = (targetInfo != null) ? RestUser.Create(discord, targetInfo) : null;
|
||||||
|
|
||||||
var before = new MemberInfo(oldNick, oldDeaf, oldMute);
|
var before = new MemberInfo(oldNick, oldDeaf, oldMute);
|
||||||
var after = new MemberInfo(newNick, newDeaf, newMute);
|
var after = new MemberInfo(newNick, newDeaf, newMute);
|
||||||
@@ -44,6 +44,9 @@ namespace Discord.Rest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user that the changes were performed on.
|
/// Gets the user that the changes were performed on.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the user is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user object representing the user who the changes were performed on.
|
/// A user object representing the user who the changes were performed on.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Linq;
|
|||||||
|
|
||||||
using Model = Discord.API.AuditLog;
|
using Model = Discord.API.AuditLog;
|
||||||
using EntryModel = Discord.API.AuditLogEntry;
|
using EntryModel = Discord.API.AuditLogEntry;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Discord.Rest
|
namespace Discord.Rest
|
||||||
{
|
{
|
||||||
@@ -20,7 +21,7 @@ namespace Discord.Rest
|
|||||||
internal static MessageDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
internal static MessageDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
||||||
{
|
{
|
||||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
return new MessageDeleteAuditLogData(entry.Options.ChannelId.Value, entry.Options.Count.Value, RestUser.Create(discord, userInfo));
|
return new MessageDeleteAuditLogData(entry.Options.ChannelId.Value, entry.Options.Count.Value, userInfo != null ? RestUser.Create(discord, userInfo) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,6 +42,9 @@ namespace Discord.Rest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user of the messages that were deleted.
|
/// Gets the user of the messages that were deleted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the user is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user object representing the user that created the deleted messages.
|
/// A user object representing the user that created the deleted messages.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Discord.Rest
|
|||||||
if (entry.TargetId.HasValue)
|
if (entry.TargetId.HasValue)
|
||||||
{
|
{
|
||||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
user = RestUser.Create(discord, userInfo);
|
user = (userInfo != null) ? RestUser.Create(discord, userInfo) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MessagePinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, user);
|
return new MessagePinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, user);
|
||||||
@@ -46,6 +46,9 @@ namespace Discord.Rest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user of the message that was pinned if available.
|
/// Gets the user of the message that was pinned if available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the user is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user object representing the user that created the pinned message or <see langword="null"/>.
|
/// A user object representing the user that created the pinned message or <see langword="null"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Discord.Rest
|
|||||||
if (entry.TargetId.HasValue)
|
if (entry.TargetId.HasValue)
|
||||||
{
|
{
|
||||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
user = RestUser.Create(discord, userInfo);
|
user = (userInfo != null) ? RestUser.Create(discord, userInfo) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MessageUnpinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, user);
|
return new MessageUnpinAuditLogData(entry.Options.MessageId.Value, entry.Options.ChannelId.Value, user);
|
||||||
@@ -46,6 +46,9 @@ namespace Discord.Rest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user of the message that was unpinned if available.
|
/// Gets the user of the message that was unpinned if available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be <see langword="null"/> if the user is a 'Deleted User#....' because Discord does send user data for deleted users.
|
||||||
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A user object representing the user that created the unpinned message or <see langword="null"/>.
|
/// A user object representing the user that created the unpinned message or <see langword="null"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Model = Discord.API.AuditLog;
|
using Model = Discord.API.AuditLog;
|
||||||
using EntryModel = Discord.API.AuditLogEntry;
|
using EntryModel = Discord.API.AuditLogEntry;
|
||||||
@@ -18,7 +18,7 @@ namespace Discord.Rest
|
|||||||
internal static UnbanAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
internal static UnbanAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
|
||||||
{
|
{
|
||||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId);
|
||||||
return new UnbanAuditLogData(RestUser.Create(discord, userInfo));
|
return new UnbanAuditLogData((userInfo != null) ? RestUser.Create(discord, userInfo) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user