{"id":"grunionnn/ratelimiter","name":"ratelimiter","scope":"grunionnn","platform":"roblox","description":"Mirrored from the Wally registry.","version":"1.0.0","latest":"1.0.0","versions":["1.0.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"f513fec6d0256d9349253cb5f56695115b4e7451b82d40976bd80f0f7e8fde66","likes":0,"downloads":0,"install":"forest install grunionnn/ratelimiter","url":"https://forest.dev/p/roblox/grunionnn/ratelimiter","files":"https://api.forest.dev/ai/package/roblox/grunionnn/ratelimiter/files","readme":"# RateLimiter\n\nA lightweight Roblox rate limiter with independent limits for each player. Use it on the server to limit remote requests or repeated actions.\n\n## Installation\n\nAdd this to your Wally dependencies, run `wally install`, and map `Packages` into your Rojo project:\n\n```toml\n[dependencies]\nRateLimiter = \"grunionnn/ratelimiter@1.0.0\"\n```\n\n## Usage\n\nThis example assumes `Packages` is in `ReplicatedStorage`:\n\n```luau\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal RateLimiter = require(ReplicatedStorage.Packages.RateLimiter)\n\n-- Allow a burst of 10 requests, refilling 2 tokens per second.\nlocal limiter = RateLimiter.new(10, \"Token\", 2)\n\nReplicatedStorage.Action.OnServerEvent:Connect(function(player)\n\tif not limiter:CanRequest(player) then\n\t\treturn\n\tend\n\n\t-- Handle the allowed action here.\nend)\n```\n\nReplace `Action` with your RemoteEvent.\n\n## API\n\n- `RateLimiter.new(maxRequests, limitType, tokenRefillRate?)` creates a limiter. Use a positive integer for `maxRequests`.\n- `\"Token\"` starts each player with a full bucket. Each allowed request spends one token. Tokens refill up to `maxRequests` at the specified rate, which defaults to 1 token per second.\n- `\"HardCap\"` allows up to `maxRequests` in each player's fixed one-second window. The refill rate is unused. Requests can burst across window boundaries, so this is not a rolling-second limit.\n- `limiter:CanRequest(player)` returns whether the request is allowed and consumes allowance when it succeeds.\n- `limiter:Destroy()` disconnects cleanup and clears player data. Call it when finished and stop using that limiter.\n\nPlayer data is automatically removed when a player leaves. Each limiter instance tracks its own limits.\n\n## Types\n\nThe module exports `RateLimiter.RateLimiter`. For named types through Wally's generated wrappers, run [wally-package-types](https://github.com/JohnnyMorganz/wally-package-types) in your consuming project after installation:\n\n```sh\nrojo sourcemap default.project.json --output sourcemap.json\nwally-package-types --sourcemap sourcemap.json Packages/\n```\n\n## License\n\n[MIT](LICENSE) by Grunionnn.\n","readmeTruncated":false}