From eab1cb1645d5e7c656c2c800a33077d02705029a Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 20 Sep 2020 21:49:52 +0200 Subject: [PATCH] Ignore self-messages --- PluralKit.Bot/Handlers/MessageCreated.cs | 1 + PluralKit.Bot/Handlers/MessageEdited.cs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/Handlers/MessageCreated.cs b/PluralKit.Bot/Handlers/MessageCreated.cs index 9ed335da..2bb13201 100644 --- a/PluralKit.Bot/Handlers/MessageCreated.cs +++ b/PluralKit.Bot/Handlers/MessageCreated.cs @@ -50,6 +50,7 @@ namespace PluralKit.Bot public async Task Handle(MessageCreateEventArgs evt) { + if (evt.Author?.Id == _client.CurrentUser?.Id) return; if (evt.Message.MessageType != MessageType.Default) return; if (IsDuplicateMessage(evt.Message)) return; diff --git a/PluralKit.Bot/Handlers/MessageEdited.cs b/PluralKit.Bot/Handlers/MessageEdited.cs index 935190fc..a407f2dc 100644 --- a/PluralKit.Bot/Handlers/MessageEdited.cs +++ b/PluralKit.Bot/Handlers/MessageEdited.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using App.Metrics; +using DSharpPlus; using DSharpPlus.EventArgs; using PluralKit.Core; @@ -16,18 +17,22 @@ namespace PluralKit.Bot private readonly IDatabase _db; private readonly ModelRepository _repo; private readonly IMetrics _metrics; + private readonly DiscordShardedClient _client; - public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db, IMetrics metrics, ModelRepository repo) + public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db, IMetrics metrics, ModelRepository repo, DiscordShardedClient client) { _lastMessageCache = lastMessageCache; _proxy = proxy; _db = db; _metrics = metrics; _repo = repo; + _client = client; } public async Task Handle(MessageUpdateEventArgs evt) { + if (evt.Author?.Id == _client.CurrentUser?.Id) return; + // Edit message events sometimes arrive with missing data; double-check it's all there if (evt.Message.Content == null || evt.Author == null || evt.Channel.Guild == null) return;