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

View file

@ -17,8 +17,12 @@ class MessageCachingSubservice {
private Task DiscordClient_MessageReceived(SocketMessage arg)
=> AddOrUpdateCacheItemAsync(arg, false);
private Task DiscordClient_MessageUpdated(Cacheable<IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3)
=> AddOrUpdateCacheItemAsync(arg2, true);
private Task DiscordClient_MessageUpdated(Cacheable<IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3) {
// 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) {
if (!Common.Utilities.IsValidUserMessage(arg, out _)) return;