Table of Contents

Class RateLimiterService

Namespace
FishMMO.DiscordBot.Services
Assembly
FishMMO-DiscordBot.dll

Per-user sliding window rate limiter to prevent abuse of the Discord-to-game chat bridge. Uses a circular buffer of timestamps per user for O(1) per-check cost.

public sealed class RateLimiterService : IDisposable
Inheritance
RateLimiterService
Implements
Inherited Members

Constructors

RateLimiterService(IConfiguration, ILogger<RateLimiterService>)

Initializes a new instance of the RateLimiterService class. Reads rate limit settings from the "RateLimiting" configuration section.

public RateLimiterService(IConfiguration configuration, ILogger<RateLimiterService> logger)

Parameters

configuration IConfiguration

Application configuration.

logger ILogger<RateLimiterService>

Logger instance.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

IsRateLimited(ulong)

Checks whether the specified user is rate-limited. If not, records the current attempt.

public bool IsRateLimited(ulong userId)

Parameters

userId ulong

The Discord user snowflake.

Returns

bool

true if the user has exceeded the rate limit; otherwise false.