Added auto delete after x amount of time to the send chat message method

This commit is contained in:
barelyprofessional
2025-10-06 03:14:08 -05:00
parent c6658bae1f
commit 23568a85c6
5 changed files with 67 additions and 77 deletions

View File

@@ -166,34 +166,16 @@ internal class BotCommands
}
_logger.Info($"Oldest entry: {oldestEntryExpires:o}");
var timeRemaining = oldestEntryExpires - DateTimeOffset.UtcNow;
var message = await _bot.SendChatMessageAsync($"{user.FormatUsername()}, please wait {timeRemaining.Humanize(maxUnit: TimeUnit.Minute, minUnit: TimeUnit.Millisecond, precision: 2)} before attempting to run {commandName} again.", true);
if (options.Flags.HasFlag(RateLimitFlags.NoAutoDeleteCooldownResponse))
TimeSpan? autoDeleteAfter = null;
if (!options.Flags.HasFlag(RateLimitFlags.NoAutoDeleteCooldownResponse))
{
_logger.Info("Not going to cleanup cooldown response");
return;
}
var i = 0;
while (message.ChatMessageId == null)
{
i++;
await Task.Delay(250, _cancellationToken);
if (i > 30)
{
_logger.Error("Gave up waiting for Sneedchat to give us the message ID for removing a cooldown notification");
return;
}
if (message.Status is SentMessageTrackerStatus.NotSending or SentMessageTrackerStatus.Lost)
{
_logger.Error("Cooldown message was suppressed or lost");
return;
}
autoDeleteAfter = TimeSpan.FromMilliseconds(
(await SettingsProvider.GetValueAsync(BuiltIn.Keys.BotRateLimitCooldownAutoDeleteDelay)).ToType<int>());
}
var autoDeleteInterval =
(await SettingsProvider.GetValueAsync(BuiltIn.Keys.BotRateLimitCooldownAutoDeleteDelay)).ToType<int>();
await Task.Delay(autoDeleteInterval, _cancellationToken);
await _bot.KfClient.DeleteMessageAsync(message.ChatMessageId.Value);
await _bot.SendChatMessageAsync(
$"{user.FormatUsername()}, please wait {timeRemaining.Humanize(maxUnit: TimeUnit.Minute, minUnit: TimeUnit.Millisecond, precision: 2)} before attempting to run {commandName} again.",
true, autoDeleteAfter: autoDeleteAfter);
}
private async Task CleanupExpiredRateLimitEntriesTask()