Add support for Vanessa log cleaning

This commit is contained in:
Ske 2020-03-04 18:32:14 +01:00
parent 628ae6beb7
commit e49f2850c6

View File

@ -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 _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 _pancakeRegex = new Regex("Message from <@(\\d{17,19})> deleted in");
private static Regex _unbelievaboatRegex = new Regex("Message ID: (\\d{17,19})"); 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<ulong, LoggerBot> _bots = new[] private static readonly Dictionary<ulong, LoggerBot> _bots = new[]
{ {
@ -42,6 +43,7 @@ namespace PluralKit.Bot
new LoggerBot("blargbot", 134133271750639616, ExtractBlargBot), new LoggerBot("blargbot", 134133271750639616, ExtractBlargBot),
new LoggerBot("Mantaro", 213466096718708737, ExtractMantaro), new LoggerBot("Mantaro", 213466096718708737, ExtractMantaro),
new LoggerBot("UnbelievaBoat", 292953664492929025, ExtractUnbelievaBoat, webhookName: "UnbelievaBoat"), new LoggerBot("UnbelievaBoat", 292953664492929025, ExtractUnbelievaBoat, webhookName: "UnbelievaBoat"),
new LoggerBot("Vanessa", 310261055060443136, fuzzyExtractFunc: ExtractVanessa),
}.ToDictionary(b => b.Id); }.ToDictionary(b => b.Id);
private static readonly Dictionary<string, LoggerBot> _botsByWebhookName = _bots.Values private static readonly Dictionary<string, LoggerBot> _botsByWebhookName = _bots.Values
@ -242,6 +244,18 @@ namespace PluralKit.Bot
var match = _unbelievaboatRegex.Match(embed.Footer.Value.Text ?? ""); var match = _unbelievaboatRegex.Match(embed.Footer.Value.Text ?? "");
return match.Success ? ulong.Parse(match.Groups[1].Value) : (ulong?) null; 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 public class LoggerBot
{ {