namespace KfChatDotNetBot.Models;
public class RateLimitBucketEntryModel
{
///
/// Database user ID of the user whose entry this belongs to
///
public required int UserId { get; set; }
///
/// When the entry was created in the bucket
///
public required DateTimeOffset EntryCreated { get; set; }
///
/// When the entry is expected to expire based on the command's window
///
public required DateTimeOffset EntryExpires { get; set; }
///
/// String representation of the command using ICommand.GetType().Name
///
public required string CommandInvoked { get; set; }
///
/// Hashed contents of the message for if UseEntireMessage is enabled
///
public required string MessageHash { get; set; }
}
public class RateLimitOptionsModel
{
///
/// Window of time to count an invocation towards the rate limit
///
public required TimeSpan Window { get; set; }
///
/// Maximum number of permitted invocations within the window before triggering the rate limit
///
public required int MaxInvocations { get; set; }
///
/// Optional set of flags to configure the behavior of the rate limiter
///
public RateLimitFlags Flags { get; set; } = RateLimitFlags.None;
}
public class IsRateLimitedModel
{
///
/// Is the user's request rate limited?
///
public required bool IsRateLimited { get; set; }
///
/// When the oldest entry expires so users know when they can next use the command
/// This is set to null if the user is not rate limited
///
public DateTimeOffset? OldestEntryExpires { get; set; }
}
[Flags]
public enum RateLimitFlags
{
///
/// Placeholder for the default value
///
None,
///
/// Silently ignore a user when they trigger a rate limit
///
NoResponse,
///
/// The default behavior is to rate limit based on command invoked.
/// UseEntireMessage changes it to consider dissimilar messages which invoke
/// the same command as being separate for the purposes of rate limiting.
/// With this, only identical messages count towards the rate limit.
///
UseEntireMessage,
///
/// The rate limit is global instead of applying per-user
///
Global,
///
/// Exempt users with a higher than default level from rate limiting
///
ExemptPrivilegedUsers,
///
/// Do not automatically clean up the cooldown response sent to a user
///
NoAutoDeleteCooldownResponse
}