fix(bot): use LastMessageCache for reproxy latest message check

(thanks spiral for catching this lmao)
This commit is contained in:
Iris System 2022-08-27 18:57:57 +12:00
parent d9fe78bdf2
commit e23b1048c9

View File

@ -35,10 +35,12 @@ public class ProxiedMessage
private readonly DiscordApiClient _rest; private readonly DiscordApiClient _rest;
private readonly WebhookExecutorService _webhookExecutor; private readonly WebhookExecutorService _webhookExecutor;
private readonly ProxyService _proxy; private readonly ProxyService _proxy;
private readonly LastMessageCacheService _lastMessageCache;
public ProxiedMessage(EmbedService embeds, public ProxiedMessage(EmbedService embeds,
DiscordApiClient rest, IMetrics metrics, ModelRepository repo, ProxyService proxy, DiscordApiClient rest, IMetrics metrics, ModelRepository repo, ProxyService proxy,
WebhookExecutorService webhookExecutor, LogChannelService logChannel, IDiscordCache cache) WebhookExecutorService webhookExecutor, LogChannelService logChannel, IDiscordCache cache,
LastMessageCacheService lastMessageCache)
{ {
_embeds = embeds; _embeds = embeds;
_rest = rest; _rest = rest;
@ -48,6 +50,7 @@ public class ProxiedMessage
// _cache = cache; // _cache = cache;
_metrics = metrics; _metrics = metrics;
_proxy = proxy; _proxy = proxy;
_lastMessageCache = lastMessageCache;
} }
public async Task ReproxyMessage(Context ctx) public async Task ReproxyMessage(Context ctx)
@ -188,10 +191,9 @@ public class ProxiedMessage
throw new PKError(error); throw new PKError(error);
} }
var latestMessages = await _rest.GetChannelMessages(msg.Message.Channel, 2); var isLatestMessage = _lastMessageCache.GetLastMessage(ctx.Message.ChannelId)?.Current.Id == ctx.Message.Id
var isLatestMessage = latestMessages.LastOrDefault()?.Id == ctx.Message.Id ? _lastMessageCache.GetLastMessage(ctx.Message.ChannelId)?.Previous?.Id == msg.Message.Mid
? latestMessages.FirstOrDefault()?.Id == msg.Message.Mid : _lastMessageCache.GetLastMessage(ctx.Message.ChannelId)?.Current.Id == msg.Message.Mid;
: latestMessages.LastOrDefault()?.Id == msg.Message.Mid;
var msgTimestamp = DiscordUtils.SnowflakeToInstant(msg.Message.Mid); var msgTimestamp = DiscordUtils.SnowflakeToInstant(msg.Message.Mid);
if (isReproxy && !isLatestMessage) if (isReproxy && !isLatestMessage)