From e49f2850c65d1211b5d1fdbcfae3716ef3dfb7df Mon Sep 17 00:00:00 2001 From: Ske Date: Wed, 4 Mar 2020 18:32:14 +0100 Subject: [PATCH] Add support for Vanessa log cleaning --- PluralKit.Bot/Services/LoggerCleanService.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/PluralKit.Bot/Services/LoggerCleanService.cs b/PluralKit.Bot/Services/LoggerCleanService.cs index 9b8ecd97..06d035c9 100644 --- a/PluralKit.Bot/Services/LoggerCleanService.cs +++ b/PluralKit.Bot/Services/LoggerCleanService.cs @@ -25,6 +25,7 @@ namespace PluralKit.Bot private static Regex _mantaroRegex = new Regex("Message \\(?ID:? (\\d{17,19})\\)? created by .* in channel .* was deleted\\."); private static Regex _pancakeRegex = new Regex("Message from <@(\\d{17,19})> deleted in"); private static Regex _unbelievaboatRegex = new Regex("Message ID: (\\d{17,19})"); + private static Regex _vanessaRegex = new Regex("Message sent by <@!?(\\d{17,19})> deleted in"); private static readonly Dictionary _bots = new[] { @@ -42,6 +43,7 @@ namespace PluralKit.Bot new LoggerBot("blargbot", 134133271750639616, ExtractBlargBot), new LoggerBot("Mantaro", 213466096718708737, ExtractMantaro), new LoggerBot("UnbelievaBoat", 292953664492929025, ExtractUnbelievaBoat, webhookName: "UnbelievaBoat"), + new LoggerBot("Vanessa", 310261055060443136, fuzzyExtractFunc: ExtractVanessa), }.ToDictionary(b => b.Id); private static readonly Dictionary _botsByWebhookName = _bots.Values @@ -242,6 +244,18 @@ namespace PluralKit.Bot var match = _unbelievaboatRegex.Match(embed.Footer.Value.Text ?? ""); return match.Success ? ulong.Parse(match.Groups[1].Value) : (ulong?) null; } + + private static FuzzyExtractResult? ExtractVanessa(SocketMessage msg) + { + // Title is "Message Deleted", embed description contains mention + var embed = msg.Embeds.FirstOrDefault(); + if (embed?.Title == null || embed.Title != "Message Deleted" || embed.Description == null) return null; + var match = _vanessaRegex.Match(embed.Description); + return match.Success + ? new FuzzyExtractResult {User = ulong.Parse(match.Groups[1].Value), ApproxTimestamp = msg.Timestamp} + : (FuzzyExtractResult?) null; + } + public class LoggerBot {