Fix issues when handling 'bad' message update data

See comment in MessageCachingSubservice.
This commit is contained in:
Noi 2022-07-27 22:02:17 -07:00
parent bbe0a84532
commit 8317f09b04
2 changed files with 13 additions and 5 deletions

View file

@ -29,8 +29,12 @@ internal class RegexModerator : RegexbotModule {
} }
private Task DiscordClient_MessageReceived(SocketMessage arg) => ReceiveIncomingMessage(arg); private Task DiscordClient_MessageReceived(SocketMessage arg) => ReceiveIncomingMessage(arg);
private Task DiscordClient_MessageUpdated(Cacheable<Discord.IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3) private Task DiscordClient_MessageUpdated(Cacheable<Discord.IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3) {
=> ReceiveIncomingMessage(arg2); // Ignore embed edits (see comment in MessageCachingSubservice)
if (!arg2.EditedTimestamp.HasValue) return Task.CompletedTask;
return ReceiveIncomingMessage(arg2);
}
/// <summary> /// <summary>
/// Does initial message checking before further processing. /// Does initial message checking before further processing.

View file

@ -17,8 +17,12 @@ class MessageCachingSubservice {
private Task DiscordClient_MessageReceived(SocketMessage arg) private Task DiscordClient_MessageReceived(SocketMessage arg)
=> AddOrUpdateCacheItemAsync(arg, false); => AddOrUpdateCacheItemAsync(arg, false);
private Task DiscordClient_MessageUpdated(Cacheable<IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3) private Task DiscordClient_MessageUpdated(Cacheable<IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3) {
=> AddOrUpdateCacheItemAsync(arg2, true); // This event is fired also when a link preview embed is added to a message. In those situations, the message's edited timestamp
// remains null, in addition to having other unusual and unexpected properties. We are not interested in these.
if (!arg2.EditedTimestamp.HasValue) return Task.CompletedTask;
return AddOrUpdateCacheItemAsync(arg2, true);
}
private async Task AddOrUpdateCacheItemAsync(SocketMessage arg, bool isUpdate) { private async Task AddOrUpdateCacheItemAsync(SocketMessage arg, bool isUpdate) {
if (!Common.Utilities.IsValidUserMessage(arg, out _)) return; if (!Common.Utilities.IsValidUserMessage(arg, out _)) return;