From e23b1048c9ace82bdb9436915a1b4157c89eff9d Mon Sep 17 00:00:00 2001 From: Iris System Date: Sat, 27 Aug 2022 18:57:57 +1200 Subject: [PATCH] fix(bot): use LastMessageCache for reproxy latest message check (thanks spiral for catching this lmao) --- PluralKit.Bot/Commands/Message.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/PluralKit.Bot/Commands/Message.cs b/PluralKit.Bot/Commands/Message.cs index 5c1c4b42..efe5dd85 100644 --- a/PluralKit.Bot/Commands/Message.cs +++ b/PluralKit.Bot/Commands/Message.cs @@ -35,10 +35,12 @@ public class ProxiedMessage private readonly DiscordApiClient _rest; private readonly WebhookExecutorService _webhookExecutor; private readonly ProxyService _proxy; + private readonly LastMessageCacheService _lastMessageCache; public ProxiedMessage(EmbedService embeds, DiscordApiClient rest, IMetrics metrics, ModelRepository repo, ProxyService proxy, - WebhookExecutorService webhookExecutor, LogChannelService logChannel, IDiscordCache cache) + WebhookExecutorService webhookExecutor, LogChannelService logChannel, IDiscordCache cache, + LastMessageCacheService lastMessageCache) { _embeds = embeds; _rest = rest; @@ -48,6 +50,7 @@ public class ProxiedMessage // _cache = cache; _metrics = metrics; _proxy = proxy; + _lastMessageCache = lastMessageCache; } public async Task ReproxyMessage(Context ctx) @@ -188,10 +191,9 @@ public class ProxiedMessage throw new PKError(error); } - var latestMessages = await _rest.GetChannelMessages(msg.Message.Channel, 2); - var isLatestMessage = latestMessages.LastOrDefault()?.Id == ctx.Message.Id - ? latestMessages.FirstOrDefault()?.Id == msg.Message.Mid - : latestMessages.LastOrDefault()?.Id == msg.Message.Mid; + var isLatestMessage = _lastMessageCache.GetLastMessage(ctx.Message.ChannelId)?.Current.Id == ctx.Message.Id + ? _lastMessageCache.GetLastMessage(ctx.Message.ChannelId)?.Previous?.Id == msg.Message.Mid + : _lastMessageCache.GetLastMessage(ctx.Message.ChannelId)?.Current.Id == msg.Message.Mid; var msgTimestamp = DiscordUtils.SnowflakeToInstant(msg.Message.Mid); if (isReproxy && !isLatestMessage)