Fix NullReferenceError when HasValue is true but Value is null

This commit is contained in:
spiral 2021-03-25 18:02:44 +00:00 committed by GitHub
parent ffae424a6c
commit 66e483be6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,11 +5,7 @@ using Myriad.Types;
namespace PluralKit.Bot namespace PluralKit.Bot
{ {
// Doing things like this instead of enabling D.NET's message cache because the message cache is, let's face it, // TODO: Should this be moved to Myriad.Cache?
// not particularly efficient? It allocates a dictionary *and* a queue for every single channel (500k in prod!)
// whereas this is, worst case, one dictionary *entry* of a single ulong per channel, and one dictionary instance
// on the whole instance, total. Yeah, much more efficient.
// TODO: is this still needed after the D#+ migration?
public class LastMessageCacheService public class LastMessageCacheService
{ {
private readonly IDictionary<ulong, CachedMessage> _cache = new ConcurrentDictionary<ulong, CachedMessage>(); private readonly IDictionary<ulong, CachedMessage> _cache = new ConcurrentDictionary<ulong, CachedMessage>();
@ -34,8 +30,8 @@ namespace PluralKit.Bot
public CachedMessage(Message msg) public CachedMessage(Message msg)
{ {
mid = msg.Id; mid = msg.Id;
if (msg.ReferencedMessage.HasValue) if (msg.ReferencedMessage.Value != null)
referenced_message = msg.ReferencedMessage.Value.Id; referenced_message = msg.ReferencedMessage.Value.Id;
} }
} }
} }