discord-bot/CompatBot/EventHandlers/ThumbnailCacheMonitor.cs
13xforever 998c27c966 scrape only full game lists in PSN stores, also cache title names
new isssue detections for log parser
consistent reaction with emoji only / text when can't
ability to disable commands at runtime (fixes #56)
command to check for game updates
various other bugfixes
2018-08-05 20:54:36 +02:00

33 lines
1.0 KiB
C#

using System.Linq;
using System.Threading.Tasks;
using CompatBot.Database;
using DSharpPlus.EventArgs;
namespace CompatBot.EventHandlers
{
internal static class ThumbnailCacheMonitor
{
public static async Task OnMessageDeleted(MessageDeleteEventArgs args)
{
if (args.Channel.Id != Config.ThumbnailSpamId)
return;
if (string.IsNullOrEmpty(args.Message.Content))
return;
if (!args.Message.Attachments.Any())
return;
using (var db = new ThumbnailDb())
{
var thumb = db.Thumbnail.FirstOrDefault(i => i.ContentId == args.Message.Content);
if (thumb?.EmbeddableUrl is string url && !string.IsNullOrEmpty(url) && args.Message.Attachments.Any(a => a.Url == url))
{
thumb.EmbeddableUrl = null;
await db.SaveChangesAsync(Config.Cts.Token).ConfigureAwait(false);
}
}
}
}
}