mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
30 lines
921 B
C#
30 lines
921 B
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using CompatBot.Database;
|
|
using DSharpPlus;
|
|
using DSharpPlus.EventArgs;
|
|
|
|
namespace CompatBot.EventHandlers;
|
|
|
|
internal static class ThumbnailCacheMonitor
|
|
{
|
|
public static async Task OnMessageDeleted(DiscordClient _, MessageDeleteEventArgs args)
|
|
{
|
|
if (args.Channel.Id != Config.ThumbnailSpamId)
|
|
return;
|
|
|
|
if (string.IsNullOrEmpty(args.Message.Content))
|
|
return;
|
|
|
|
if (!args.Message.Attachments.Any())
|
|
return;
|
|
|
|
await using var db = new ThumbnailDb();
|
|
var thumb = db.Thumbnail.FirstOrDefault(i => i.ContentId == args.Message.Content);
|
|
if (thumb is { EmbeddableUrl: { Length: > 0 } url } && args.Message.Attachments.Any(a => a.Url == url))
|
|
{
|
|
thumb.EmbeddableUrl = null;
|
|
await db.SaveChangesAsync(Config.Cts.Token).ConfigureAwait(false);
|
|
}
|
|
}
|
|
} |