curious.commands.ratelimit

Utilities for ratelimiting a command.

Classes

BucketNamer A simple namespace for storing bucket functions.
CommandRateLimit(*, limit, time, …) Represents a ratelimit for a command.
RateLimiter() Represents a ratelimiter.
class curious.commands.ratelimit.BucketNamer[source]

Bases: object

A simple namespace for storing bucket functions.

staticmethod AUTHOR()[source]

A bucket namer that uses the author ID as the bucket.

Return type:str
staticmethod CHANNEL()[source]

A bucket namer that uses the channel ID as the bucket.

Return type:str
staticmethod GLOBAL()[source]

A bucket namer that is global.

Return type:str
staticmethod GUILD()[source]

A bucket namer that uses the guild ID as the bucket.

Return type:str
class curious.commands.ratelimit.CommandRateLimit(*, limit: int, time: float, bucket_namer: typing.Callable[curious.commands.context.Context, str] = <function BucketNamer.AUTHOR>)[source]

Bases: object

Represents a ratelimit for a command.

Parameters:
  • limit (int) – The number of times a command can be called in the specified limit.
  • time (float) – The time (in seconds) this ratelimit lasts.
  • bucket_namer (Callable[[Context], str]) – A callable that gets the ratelimit bucket name.
get_full_bucket_key(ctx)[source]

Gets the full bucket key for this ratelimit.

Return type:Tuple[str, str]
class curious.commands.ratelimit.RateLimiter[source]

Bases: object

Represents a ratelimiter. This ensures that commands meet the ratelimit before being ran.

await ensure_ratelimits(ctx, cmd)[source]

Ensures the ratelimits for a command.

await get_bucket(key)[source]

Gets the ratelimit bucket for the specified key.

Parameters:key (Any) – The key to use.
Return type:Tuple[int, float]
Returns:A two-item tuple of (uses, expiration), or None if no bucket was found.
await update_bucket(key, current_uses, expiration)[source]

Updates a ratelimit bucket.

Parameters:
  • key (Any) – The ratelimit key to use.
  • current_uses (int) – The current uses for the key.
  • expiration (float) – When the ratelimit expires.