From bf80dd09884ea778acf694c1537005f3a13b46c2 Mon Sep 17 00:00:00 2001 From: spiral Date: Fri, 14 Jan 2022 15:29:15 -0500 Subject: [PATCH] refactor: don't get user from cache in ReactionAdded --- PluralKit.Bot/Handlers/ReactionAdded.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/PluralKit.Bot/Handlers/ReactionAdded.cs b/PluralKit.Bot/Handlers/ReactionAdded.cs index 3c46e9c6..b67ac832 100644 --- a/PluralKit.Bot/Handlers/ReactionAdded.cs +++ b/PluralKit.Bot/Handlers/ReactionAdded.cs @@ -49,17 +49,14 @@ public class ReactionAdded: IEventHandler private async ValueTask TryHandleProxyMessageReactions(MessageReactionAddEvent evt) { - // Sometimes we get events from users that aren't in the user cache - // We just ignore all of those for now, should be quite rare... - if (!(await _cache.TryGetUser(evt.UserId) is User user)) - return; - // ignore any reactions added by *us* if (evt.UserId == await _cache.GetOwnUser()) return; // Ignore reactions from bots (we can't DM them anyway) - if (user.Bot) return; + // note: this used to get from cache since this event does not contain Member in DMs + // but we aren't able to get DMs from bots anyway, so it's not really needed + if (evt.GuildId != null && evt.Member.User.Bot) return; var channel = await _cache.GetChannel(evt.ChannelId); @@ -146,10 +143,12 @@ public class ReactionAdded: IEventHandler { // Can only delete your own message // (except in DMs, where msg will be null) - // todo: don't try to delete the user's messages if (msg != null && msg.AuthorId != evt.UserId) return; + // todo: don't try to delete the user's own messages in DMs + // this is hard since we don't have the message author object, but it happens infrequently enough to not really care about the 403s, I guess? + try { await _rest.DeleteMessage(evt.ChannelId, evt.MessageId);