From 4581b402aa5d9ec6d27d6cf579d57436df939a23 Mon Sep 17 00:00:00 2001 From: neroduckale <100025711+neroduckale@users.noreply.github.com> Date: Sun, 17 Dec 2023 22:02:50 +0500 Subject: [PATCH] Do not log messages edited by bots (#202) If the author of the edited message is a bot, then Octobot won't log the edit --- src/Responders/MessageEditedResponder.cs | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Responders/MessageEditedResponder.cs b/src/Responders/MessageEditedResponder.cs index 16f7af4..c7426d2 100644 --- a/src/Responders/MessageEditedResponder.cs +++ b/src/Responders/MessageEditedResponder.cs @@ -36,18 +36,22 @@ public class MessageEditedResponder : IResponder public async Task RespondAsync(IMessageUpdate gatewayEvent, CancellationToken ct = default) { + if (!gatewayEvent.ID.IsDefined(out var messageId)) + { + return new ArgumentNullError(nameof(gatewayEvent.ID)); + } + + if (!gatewayEvent.ChannelID.IsDefined(out var channelId)) + { + return new ArgumentNullError(nameof(gatewayEvent.ChannelID)); + } + if (!gatewayEvent.GuildID.IsDefined(out var guildId)) { return Result.FromSuccess(); } - var cfg = await _guildData.GetSettings(guildId, ct); - if (GuildSettings.PrivateFeedbackChannel.Get(cfg).Empty()) - { - return Result.FromSuccess(); - } - - if (!gatewayEvent.Content.IsDefined(out var newContent)) + if (gatewayEvent.Author.IsDefined(out var author) && author.IsBot.OrDefault(false)) { return Result.FromSuccess(); } @@ -57,14 +61,15 @@ public class MessageEditedResponder : IResponder return Result.FromSuccess(); // The message wasn't actually edited } - if (!gatewayEvent.ChannelID.IsDefined(out var channelId)) + if (!gatewayEvent.Content.IsDefined(out var newContent)) { - return new ArgumentNullError(nameof(gatewayEvent.ChannelID)); + return Result.FromSuccess(); } - if (!gatewayEvent.ID.IsDefined(out var messageId)) + var cfg = await _guildData.GetSettings(guildId, ct); + if (GuildSettings.PrivateFeedbackChannel.Get(cfg).Empty()) { - return new ArgumentNullError(nameof(gatewayEvent.ID)); + return Result.FromSuccess(); } var cacheKey = new KeyHelpers.MessageCacheKey(channelId, messageId);