Skip to content

Commit

Permalink
nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Sep 10, 2023
1 parent b4dcf77 commit dd8ef4b
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 91 deletions.
131 changes: 58 additions & 73 deletions DisCatSharp/Clients/DiscordClient.Dispatch.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions DisCatSharp/Clients/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ private DiscordScheduledEvent UpdateScheduledEvent(DiscordScheduledEvent schedul
/// <param name="guild">The guild to update.</param>
/// <param name="mbr">The member to update.</param>
/// <returns>The updated user.</returns>
private DiscordUser UpdateUser(DiscordUser usr, ulong? guildId, DiscordGuild guild, TransportMember? mbr)
private DiscordUser UpdateUser(DiscordUser usr, ulong? guildId, DiscordGuild? guild, TransportMember? mbr)
{
if (mbr != null)
{
Expand Down Expand Up @@ -1384,7 +1384,7 @@ private DiscordUser UpdateUser(DiscordUser usr, ulong? guildId, DiscordGuild gui

DiscordMember member = default;

if (intents.HasAllPrivilegedIntents() && !guild.IsLarge)
if (intents.HasAllPrivilegedIntents() && (!guild?.IsLarge ?? true))
return usr; // we have the necessary privileged intents, no need to worry about caching here unless guild is large.

if (guild?.MembersInternal.TryGetValue(usr.Id, out member) == false)
Expand All @@ -1394,7 +1394,7 @@ private DiscordUser UpdateUser(DiscordUser usr, ulong? guildId, DiscordGuild gui
}
else if (intents.HasIntent(DiscordIntents.GuildPresences) || this.Configuration.AlwaysCacheMembers) // we can attempt to update it if it's already in cache.
if (!intents.HasIntent(DiscordIntents.GuildMembers)) // no need to update if we already have the member events
_ = guild.MembersInternal.TryUpdate(usr.Id, (DiscordMember)usr, member);
_ = guild?.MembersInternal.TryUpdate(usr.Id, (DiscordMember)usr, member);
}
else if (!string.IsNullOrEmpty(usr.Username)) // check if not a skeleton user
_ = this.UserCache.AddOrUpdate(usr.Id, usr, (id, old) =>
Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp/Entities/Message/DiscordMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public IReadOnlyList<DiscordChannel>? MentionedChannels
=> this._mentionedChannelsLazy?.Value;

[JsonIgnore]
internal List<DiscordChannel> MentionedChannelsInternal;
internal List<DiscordChannel>? MentionedChannelsInternal;

[JsonIgnore]
private readonly Lazy<IReadOnlyList<DiscordChannel>>? _mentionedChannelsLazy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class MessageBulkDeleteEventArgs : DiscordEventArgs
/// <summary>
/// Gets the guild in which the deletion occurred.
/// </summary>
public DiscordGuild Guild { get; internal set; }
public DiscordGuild? Guild { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="MessageBulkDeleteEventArgs"/> class.
Expand Down
6 changes: 3 additions & 3 deletions DisCatSharp/EventArgs/Message/MessageCreateEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ public DiscordUser Author
/// <summary>
/// Gets the collection of mentioned users.
/// </summary>
public IReadOnlyList<DiscordUser> MentionedUsers { get; internal set; }
public IReadOnlyList<DiscordUser>? MentionedUsers { get; internal set; }

/// <summary>
/// Gets the collection of mentioned roles.
/// </summary>
public IReadOnlyList<DiscordRole> MentionedRoles { get; internal set; }
public IReadOnlyList<DiscordRole>? MentionedRoles { get; internal set; }

/// <summary>
/// Gets the collection of mentioned channels.
/// </summary>
public IReadOnlyList<DiscordChannel> MentionedChannels { get; internal set; }
public IReadOnlyList<DiscordChannel>? MentionedChannels { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="MessageCreateEventArgs"/> class.
Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp/EventArgs/Message/MessageDeleteEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MessageDeleteEventArgs : DiscordEventArgs
/// <summary>
/// Gets the guild this message belonged to.
/// </summary>
public DiscordGuild Guild { get; internal set; }
public DiscordGuild? Guild { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="MessageDeleteEventArgs"/> class.
Expand Down
10 changes: 5 additions & 5 deletions DisCatSharp/EventArgs/Message/MessageUpdateEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MessageUpdateEventArgs : DiscordEventArgs
/// <summary>
/// Gets the message before it got updated. This property will be null if the message was not cached.
/// </summary>
public DiscordMessage MessageBefore { get; internal set; }
public DiscordMessage? MessageBefore { get; internal set; }

/// <summary>
/// Gets the channel this message belongs to.
Expand All @@ -51,7 +51,7 @@ public DiscordChannel Channel
/// <summary>
/// Gets the guild this message belongs to.
/// </summary>
public DiscordGuild Guild
public DiscordGuild? Guild
=> this.Channel.Guild;

/// <summary>
Expand All @@ -69,17 +69,17 @@ public DiscordUser Author
/// <summary>
/// Gets the collection of mentioned users.
/// </summary>
public IReadOnlyList<DiscordUser> MentionedUsers { get; internal set; }
public IReadOnlyList<DiscordUser>? MentionedUsers { get; internal set; }

/// <summary>
/// Gets the collection of mentioned roles.
/// </summary>
public IReadOnlyList<DiscordRole> MentionedRoles { get; internal set; }
public IReadOnlyList<DiscordRole>? MentionedRoles { get; internal set; }

/// <summary>
/// Gets the collection of mentioned channels.
/// </summary>
public IReadOnlyList<DiscordChannel> MentionedChannels { get; internal set; }
public IReadOnlyList<DiscordChannel>? MentionedChannels { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="MessageUpdateEventArgs"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class MessageReactionAddEventArgs : DiscordEventArgs
/// <summary>
/// Gets the guild in which the reaction was added.
/// </summary>
public DiscordGuild Guild { get; internal set; }
public DiscordGuild? Guild { get; internal set; }

/// <summary>
/// Gets the emoji used for this reaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class MessageReactionRemoveEventArgs : DiscordEventArgs
/// <summary>
/// Gets the guild in which the reaction was deleted.
/// </summary>
public DiscordGuild Guild { get; internal set; }
public DiscordGuild? Guild { get; internal set; }

/// <summary>
/// Gets the emoji used for this reaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public DiscordChannel Channel
/// <summary>
/// Gets the guild in which the reactions were cleared.
/// </summary>
public DiscordGuild Guild
=> this.Channel.Guild;
public DiscordGuild? Guild { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="MessageReactionsClearEventArgs"/> class.
Expand Down

0 comments on commit dd8ef4b

Please sign in to comment.