Drop consecutive duplicate messages from the gateway

This commit is contained in:
Ske 2020-05-06 23:48:45 +02:00
parent cde495cd3a
commit 356fb76cb2

View File

@ -48,6 +48,12 @@ namespace PluralKit.Bot
public async Task Handle(MessageCreateEventArgs evt)
{
// Drop the message if we've already received it.
// Gateway occasionally resends events for whatever reason and it can break stuff relying on IDs being unique
// Not a perfect fix since reordering could still break things but... it's good enough for now
// (was considering checking the order of the IDs but IDs aren't guaranteed to be *perfectly* in order, so that'd cause false positives)
// LastMessageCache is updated in RegisterMessageMetrics so the ordering here is correct.
if (_lastMessageCache.GetLastMessage(evt.Channel.Id) == evt.Message.Id) return;
RegisterMessageMetrics(evt);
// Ignore system messages (member joined, message pinned, etc)