From 356fb76cb24ec0db877aa2596933190e5cdaf3d5 Mon Sep 17 00:00:00 2001 From: Ske Date: Wed, 6 May 2020 23:48:45 +0200 Subject: [PATCH] Drop consecutive duplicate messages from the gateway --- PluralKit.Bot/Handlers/MessageCreated.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/Handlers/MessageCreated.cs b/PluralKit.Bot/Handlers/MessageCreated.cs index a46b1058..a9d99fa3 100644 --- a/PluralKit.Bot/Handlers/MessageCreated.cs +++ b/PluralKit.Bot/Handlers/MessageCreated.cs @@ -48,8 +48,14 @@ 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) var msg = evt.Message; if (msg.MessageType != MessageType.Default) return;