fix message edit embed, ignore pk;edit triggers
This commit is contained in:
parent
8231c57bdf
commit
7ea945b427
6 changed files with 63 additions and 15 deletions
|
|
@ -4,6 +4,7 @@ using Catalogger.Backend.Database.Queries;
|
|||
using Catalogger.Backend.Extensions;
|
||||
using Catalogger.Backend.Services;
|
||||
using Humanizer;
|
||||
using Microsoft.VisualBasic;
|
||||
using NodaTime;
|
||||
using Remora.Discord.API;
|
||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||
|
|
@ -11,6 +12,7 @@ using Remora.Discord.API.Abstractions.Objects;
|
|||
using Remora.Discord.API.Objects;
|
||||
using Remora.Discord.Extensions.Embeds;
|
||||
using Remora.Discord.Gateway.Responders;
|
||||
using Remora.Rest.Core;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Catalogger.Backend.Bot.Responders;
|
||||
|
|
@ -22,15 +24,18 @@ public class MessageDeleteResponder(
|
|||
WebhookExecutorService webhookExecutor,
|
||||
ChannelCacheService channelCache,
|
||||
UserCacheService userCache,
|
||||
IClock clock) : IResponder<IMessageDelete>
|
||||
IClock clock,
|
||||
PluralkitApiService pluralkitApi) : IResponder<IMessageDelete>
|
||||
{
|
||||
private readonly ILogger _logger = logger.ForContext<MessageDeleteResponder>();
|
||||
|
||||
private static bool MaybePkProxyTrigger(Snowflake id) => id.Timestamp > DateTimeOffset.Now - 1.Minutes();
|
||||
|
||||
public async Task<Result> RespondAsync(IMessageDelete ev, CancellationToken ct = default)
|
||||
{
|
||||
if (!ev.GuildID.IsDefined()) return Result.Success;
|
||||
|
||||
if (ev.ID.Timestamp < DateTimeOffset.Now - 1.Minutes())
|
||||
if (MaybePkProxyTrigger(ev.ID))
|
||||
{
|
||||
_logger.Debug(
|
||||
"Deleted message {MessageId} is less than 1 minute old, delaying 5 seconds to give PK time to catch up",
|
||||
|
|
@ -59,6 +64,20 @@ public class MessageDeleteResponder(
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
// Check if the message is an edit trigger message.
|
||||
// If it is, the API will return a valid message for its ID, but the ID won't match either `Id` or `Original`.
|
||||
// (We also won't have any system/member information stored for it)
|
||||
if (msg is { System: null, Member: null } && MaybePkProxyTrigger(ev.ID) && false)
|
||||
{
|
||||
// TODO: remove the "false" if/when the API is updated to actually return this :neofox_woozy:
|
||||
var pkMsg = await pluralkitApi.GetPluralKitMessageAsync(ev.ID.Value, ct);
|
||||
if (pkMsg != null && pkMsg.Id != ev.ID.Value && pkMsg.Original != ev.ID.Value)
|
||||
{
|
||||
_logger.Debug("Deleted message {MessageId} is a `pk;edit` message, ignoring", ev.ID);
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
|
||||
logChannel = webhookExecutor.GetLogChannel(guild, LogChannelType.MessageDelete, ev.ChannelID, msg.UserId);
|
||||
if (logChannel == null) return Result.Success;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue