Hopefully fix error in LogClean module
This commit is contained in:
parent
e7b28261b2
commit
91b60367f0
@ -8,6 +8,7 @@ using Dapper;
|
||||
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
||||
@ -78,6 +79,8 @@ namespace PluralKit.Bot
|
||||
// If we didn't find anything before, or what we found is an unsupported bot, bail
|
||||
if (bot == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
// We try two ways of extracting the actual message, depending on the bots
|
||||
if (bot.FuzzyExtractFunc != null)
|
||||
{
|
||||
@ -96,7 +99,8 @@ namespace PluralKit.Bot
|
||||
{
|
||||
fuzzy.Value.User,
|
||||
Guild = msg.Channel.GuildId,
|
||||
ApproxId = DiscordUtils.InstantToSnowflake(fuzzy.Value.ApproxTimestamp - TimeSpan.FromSeconds(3))
|
||||
ApproxId = DiscordUtils.InstantToSnowflake(
|
||||
fuzzy.Value.ApproxTimestamp - TimeSpan.FromSeconds(3))
|
||||
});
|
||||
if (mid == null) return; // If we didn't find a corresponding message, bail
|
||||
// Otherwise, we can *reasonably assume* that this is a logged deletion, so delete the log message.
|
||||
@ -110,13 +114,21 @@ namespace PluralKit.Bot
|
||||
|
||||
using var conn = await _db.Obtain();
|
||||
// We do this through an inline query instead of through DataStore since we don't need all the joins it does
|
||||
var mid = await conn.QuerySingleOrDefaultAsync<ulong?>("select mid from messages where original_mid = @Mid", new {Mid = extractedId.Value});
|
||||
var mid = await conn.QuerySingleOrDefaultAsync<ulong?>(
|
||||
"select mid from messages where original_mid = @Mid", new {Mid = extractedId.Value});
|
||||
if (mid == null) return;
|
||||
|
||||
// If we've gotten this far, we found a logged deletion of a trigger message. Just yeet it!
|
||||
await msg.DeleteAsync();
|
||||
} // else should not happen, but idk, it might
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
// Sort of a temporary measure: getting an error in Sentry about a NotFoundException from D#+ here
|
||||
// The only thing I can think of that'd cause this are the DeleteAsync() calls which 404 when
|
||||
// the message doesn't exist anyway - so should be safe to just ignore it, right?
|
||||
}
|
||||
}
|
||||
|
||||
private static ulong? ExtractAuttaja(DiscordMessage msg)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user