Completely untested and totally experimental rate limit feature

This commit is contained in:
barelyprofessional
2025-09-08 15:09:59 -05:00
parent f9445d407a
commit ff1d83d9f7
18 changed files with 420 additions and 28 deletions

View File

@@ -21,7 +21,7 @@ public class AddImageCommand : ICommand
public string? HelpText => "Add an image to the image rotation specified";
public UserRight RequiredRight => UserRight.TrueAndHonest;
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
public RateLimitOptionsModel? RateLimitOptions => null;
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx)
{
@@ -61,7 +61,7 @@ public class RemoveImageCommand : ICommand
public string? HelpText => "Remove an image from the image rotation specified";
public UserRight RequiredRight => UserRight.TrueAndHonest;
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
public RateLimitOptionsModel? RateLimitOptions => null;
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx)
{
@@ -99,7 +99,7 @@ public class ListImageCommand : ICommand
public string? HelpText => "Remove an image from the image rotation specified";
public UserRight RequiredRight => UserRight.TrueAndHonest;
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
public RateLimitOptionsModel? RateLimitOptions => null;
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx)
{
@@ -138,7 +138,12 @@ public class GetRandomImage : ICommand
public string? HelpText => "Get a random image";
public UserRight RequiredRight => UserRight.Loser;
public TimeSpan Timeout => TimeSpan.FromMinutes(10);
public RateLimitOptionsModel? RateLimitOptions => new()
{
Window = TimeSpan.FromSeconds(10),
MaxInvocations = 3,
Flags = RateLimitFlags.NoResponse | RateLimitFlags.UseEntireMessage
};
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
CancellationToken ctx)
{