From 73f9a0aa367d3ea0a31af230012c74649236eb33 Mon Sep 17 00:00:00 2001 From: Dominik Koch Date: Fri, 6 Dec 2024 14:52:11 +0100 Subject: [PATCH] feat(log cleanup): add koira log cleanup support --- PluralKit.Bot/Services/LoggerCleanService.cs | 14 ++++++++++++++ docs/content/staff/compatibility.md | 1 + 2 files changed, 15 insertions(+) diff --git a/PluralKit.Bot/Services/LoggerCleanService.cs b/PluralKit.Bot/Services/LoggerCleanService.cs index af4ff011..178ce95b 100644 --- a/PluralKit.Bot/Services/LoggerCleanService.cs +++ b/PluralKit.Bot/Services/LoggerCleanService.cs @@ -44,6 +44,7 @@ public class LoggerCleanService private static readonly Regex _SkyraRegex = new("https://discord.com/channels/(\\d{17,19})/(\\d{17,19})/(\\d{17,19})"); private static readonly Regex _AnnabelleRegex = new("```\n(\\d{17,19})\n```"); private static readonly Regex _AnnabelleRegexFuzzy = new("\\ A message from \\*\\*[\\w.]{2,32}\\*\\* \\(`(\\d{17,19})`\\) was deleted in <#\\d{17,19}>"); + private static readonly Regex _koiraRegex = new("ID:\\*\\* (\\d{17,19})"); private static readonly Regex _VortexRegex = new("`\\[(\\d\\d:\\d\\d:\\d\\d)\\]` .* \\(ID:(\\d{17,19})\\).* <#\\d{17,19}>:"); @@ -82,6 +83,7 @@ public class LoggerCleanService new LoggerBot("Dozer", 356535250932858885, ExtractDozer), new LoggerBot("Skyra", 266624760782258186, ExtractSkyra), new LoggerBot("Annabelle", 231241068383961088, ExtractAnnabelle, fuzzyExtractFunc: ExtractAnnabelleFuzzy), + new LoggerBot("Koira", 1247013404569239624, ExtractKoira) }.ToDictionary(b => b.Id); private static Dictionary _botsByApplicationId @@ -427,6 +429,18 @@ public class LoggerCleanService : null; } + private static ulong? ExtractKoira(Message msg) + { + // Embed, Message author name field: "Message Deleted", description contains "**[emoji] ID:** [id]" + // Example: "ID:** 347077478726238228" + // We only use the end of the bold markdown because there's a custom emoji in the bold we don't want to copy the code of + var embed = msg.Embeds?.FirstOrDefault(); + if (embed == null) return null; + if (!(embed.Author?.Name?.StartsWith("Message Deleted") ?? false)) return null; + var match = _koiraRegex.Match(embed.Description); + return match.Success ? ulong.Parse(match.Groups[1].Value) : null; + } + public class LoggerBot { public ulong Id; diff --git a/docs/content/staff/compatibility.md b/docs/content/staff/compatibility.md index 5dd93dc2..b6315a0f 100644 --- a/docs/content/staff/compatibility.md +++ b/docs/content/staff/compatibility.md @@ -31,6 +31,7 @@ At the moment, log cleanup works with the following bots: - [Dyno](https://dyno.gg/) (precise) - [GearBot](https://gearbot.rocks/) (fuzzy) - [GenericBot](https://github.com/galenguyer/GenericBot) (precise) +- Koira (precise) - [Logger#6088](https://logger.bot/) (precise) - [Logger#6278](https://loggerbot.chat/) (precise) - [Mantaro](https://mantaro.site/) (precise)