Inverted cooldown cleanup behavior

This commit is contained in:
barelyprofessional
2025-09-12 13:50:23 -05:00
parent 74be702473
commit 2067267027
3 changed files with 5 additions and 8 deletions

View File

@@ -128,8 +128,7 @@ public class RakebackCommand : ICommand
public RateLimitOptionsModel? RateLimitOptions => new RateLimitOptionsModel public RateLimitOptionsModel? RateLimitOptions => new RateLimitOptionsModel
{ {
MaxInvocations = 1, MaxInvocations = 1,
Window = TimeSpan.FromSeconds(30), Window = TimeSpan.FromSeconds(30)
Flags = RateLimitFlags.AutoDeleteCooldownResponse
}; };
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx) CancellationToken ctx)
@@ -182,8 +181,7 @@ public class LossbackCommand : ICommand
public RateLimitOptionsModel? RateLimitOptions => new RateLimitOptionsModel public RateLimitOptionsModel? RateLimitOptions => new RateLimitOptionsModel
{ {
Window = TimeSpan.FromSeconds(30), Window = TimeSpan.FromSeconds(30),
MaxInvocations = 1, MaxInvocations = 1
Flags = RateLimitFlags.AutoDeleteCooldownResponse
}; };
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx) CancellationToken ctx)

View File

@@ -76,8 +76,7 @@ public enum RateLimitFlags
/// </summary> /// </summary>
ExemptPrivilegedUsers, ExemptPrivilegedUsers,
/// <summary> /// <summary>
/// Automatically clean up the cooldown response sent to a user /// Do not automatically clean up the cooldown response sent to a user
/// Mutually exclusive with NoResponse
/// </summary> /// </summary>
AutoDeleteCooldownResponse NoAutoDeleteCooldownResponse
} }

View File

@@ -158,7 +158,7 @@ internal class BotCommands
if (options.Flags.HasFlag(RateLimitFlags.NoResponse)) return; if (options.Flags.HasFlag(RateLimitFlags.NoResponse)) return;
var timeRemaining = oldestEntryExpires - DateTimeOffset.UtcNow; 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); 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.AutoDeleteCooldownResponse)) return; if (options.Flags.HasFlag(RateLimitFlags.NoAutoDeleteCooldownResponse)) return;
var i = 0; var i = 0;
while (message.ChatMessageId == null) while (message.ChatMessageId == null)
{ {