mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat: let logbots have both fuzzy and precise matching
This commit is contained in:
parent
ee43ad8f83
commit
79ea22f527
1 changed files with 18 additions and 14 deletions
|
|
@ -80,7 +80,7 @@ public class LoggerCleanService
|
||||||
new LoggerBot("ProBot Prime", 567703512763334685, fuzzyExtractFunc: ExtractProBot), // webhook (?)
|
new LoggerBot("ProBot Prime", 567703512763334685, fuzzyExtractFunc: ExtractProBot), // webhook (?)
|
||||||
new LoggerBot("Dozer", 356535250932858885, ExtractDozer),
|
new LoggerBot("Dozer", 356535250932858885, ExtractDozer),
|
||||||
new LoggerBot("Skyra", 266624760782258186, ExtractSkyra),
|
new LoggerBot("Skyra", 266624760782258186, ExtractSkyra),
|
||||||
new LoggerBot("Annabelle", 231241068383961088, ExtractAnnabelle),
|
new LoggerBot("Annabelle", 231241068383961088, ExtractAnnabelle),
|
||||||
}.ToDictionary(b => b.Id);
|
}.ToDictionary(b => b.Id);
|
||||||
|
|
||||||
private static Dictionary<ulong, LoggerBot> _botsByApplicationId
|
private static Dictionary<ulong, LoggerBot> _botsByApplicationId
|
||||||
|
|
@ -121,6 +121,7 @@ public class LoggerCleanService
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// We try two ways of extracting the actual message, depending on the bots
|
// We try two ways of extracting the actual message, depending on the bots
|
||||||
|
// Some bots have different log formats so we check for both types of extract function
|
||||||
if (bot.FuzzyExtractFunc != null)
|
if (bot.FuzzyExtractFunc != null)
|
||||||
{
|
{
|
||||||
// Some bots (Carl, Circle, etc) only give us a user ID and a rough timestamp, so we try our best to
|
// Some bots (Carl, Circle, etc) only give us a user ID and a rough timestamp, so we try our best to
|
||||||
|
|
@ -129,20 +130,22 @@ public class LoggerCleanService
|
||||||
// delete event timestamp, which is... good enough, I think? Potential for false positives and negatives
|
// delete event timestamp, which is... good enough, I think? Potential for false positives and negatives
|
||||||
// either way but shouldn't be too much, given it's constrained by user ID and guild.
|
// either way but shouldn't be too much, given it's constrained by user ID and guild.
|
||||||
var fuzzy = bot.FuzzyExtractFunc(msg);
|
var fuzzy = bot.FuzzyExtractFunc(msg);
|
||||||
if (fuzzy == null) return;
|
if (fuzzy != null)
|
||||||
|
{
|
||||||
|
|
||||||
_logger.Debug("Fuzzy logclean for {BotName} on {MessageId}: {@FuzzyExtractResult}",
|
_logger.Debug("Fuzzy logclean for {BotName} on {MessageId}: {@FuzzyExtractResult}",
|
||||||
bot.Name, msg.Id, fuzzy);
|
bot.Name, msg.Id, fuzzy);
|
||||||
|
|
||||||
var exists = await _redis.HasLogCleanup(fuzzy.Value.User, msg.GuildId.Value);
|
var exists = await _redis.HasLogCleanup(fuzzy.Value.User, msg.GuildId.Value);
|
||||||
|
|
||||||
// If we didn't find a corresponding message, bail
|
// If we didn't find a corresponding message, bail
|
||||||
if (!exists) return;
|
if (!exists) return;
|
||||||
|
|
||||||
// Otherwise, we can *reasonably assume* that this is a logged deletion, so delete the log message.
|
// Otherwise, we can *reasonably assume* that this is a logged deletion, so delete the log message.
|
||||||
await _client.DeleteMessage(msg.ChannelId, msg.Id);
|
await _client.DeleteMessage(msg.ChannelId, msg.Id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (bot.ExtractFunc != null)
|
if (bot.ExtractFunc != null)
|
||||||
{
|
{
|
||||||
// Other bots give us the message ID itself, and we can just extract that from the database directly.
|
// Other bots give us the message ID itself, and we can just extract that from the database directly.
|
||||||
var extractedId = bot.ExtractFunc(msg);
|
var extractedId = bot.ExtractFunc(msg);
|
||||||
|
|
@ -152,10 +155,11 @@ public class LoggerCleanService
|
||||||
bot.Name, msg.Id, extractedId);
|
bot.Name, msg.Id, extractedId);
|
||||||
|
|
||||||
var mid = await _redis.GetOriginalMid(extractedId.Value);
|
var mid = await _redis.GetOriginalMid(extractedId.Value);
|
||||||
if (mid == null) return;
|
if (mid != null)
|
||||||
|
{
|
||||||
// If we've gotten this far, we found a logged deletion of a trigger message. Just yeet it!
|
// If we've gotten this far, we found a logged deletion of a trigger message. Just yeet it!
|
||||||
await _client.DeleteMessage(msg.ChannelId, msg.Id);
|
await _client.DeleteMessage(msg.ChannelId, msg.Id);
|
||||||
|
}
|
||||||
} // else should not happen, but idk, it might
|
} // else should not happen, but idk, it might
|
||||||
}
|
}
|
||||||
catch (NotFoundException)
|
catch (NotFoundException)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue