Rate Limiting
Built-in rate limiting middleware with per-user token bucket and customizable responses.
Usage
from pyrogram_patch.middleware import RateLimitMiddleware
rate_limiter = RateLimitMiddleware(
limit=5, # max requests
period=60, # per 60 seconds
on_limited=lambda u: u.reply("Too many requests. Please wait."),
)
await manager.add_middleware(rate_limiter, kind="before", priority=100)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | int | — | Max number of requests per period |
period | float | — | Time window in seconds |
on_limited | Callable | None | Callback when rate limit is hit |
key_func | Callable | user ID | Function to extract rate limit key from update |