try to scan forwarded message

it will fail (because discord is great at api design), but at least we'll try
This commit is contained in:
13xforever 2025-02-18 09:42:09 +05:00
parent f0fffeca7e
commit e00eee4b60
No known key found for this signature in database
GPG Key ID: 2B2A36B482FE70C5
2 changed files with 23 additions and 1 deletions

View File

@ -13,6 +13,7 @@ using DSharpPlus.Entities;
using Microsoft.EntityFrameworkCore;
using NReco.Text;
using Microsoft.Extensions.Caching.Memory;
using NLog;
namespace CompatBot.Database.Providers;
@ -134,7 +135,21 @@ internal static class ContentFilter
return true;
}
#endif
if (message.Reference is {} refMsg)
{
try
{
var msg = await client.GetMessageAsync(refMsg.Channel, refMsg.Message.Id).ConfigureAwait(false);
if (msg is not null)
message = msg;
}
catch (Exception e)
{
Config.Log.Warn(e, "Failed to get message reference content");
}
}
var content = new StringBuilder(message.Content).AppendLine();
if (message.Attachments is not null)
foreach (var attachment in message.Attachments.Where(a => a is not null))

View File

@ -2,6 +2,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CompatBot.Commands.Attributes;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Converters;
using DSharpPlus.Entities;
@ -50,4 +51,10 @@ public static partial class CommandContextExtensions
return channel.GetMessageAsync(msgId);
return Task.FromResult((DiscordMessage?)null);
}
public static async Task<DiscordMessage?> GetMessageAsync(this DiscordClient client, DiscordChannel channel, ulong messageId)
{
return await channel.GetMessageAsync(messageId).ConfigureAwait(false);
}
}