TokenBucket → Consume & Check

Consume & Check

Attempt to spend a token or inspect the bucket without spending. The request pipeline calls Consume automatically on every incoming request — you only need to call these manually for custom rate-limiting logic outside the pipeline.

Signatures

bucket:Consume(player: Player) → boolean
bucket:HasTokens(player: Player) → boolean

Behaviour

MethodDeducts tokensReturns
ConsumeYes — deducts cost (default 1)true if tokens were available, false if the bucket was empty (rate limit hit)
HasTokensNotrue if at least cost tokens are present, false otherwise

When the pipeline calls Consume and it returns false, the request is rejected with 429 before any middleware or handler runs. This signal is also observed by the Tamper module as a flood indicator.

Example: manual consume in a custom action

local TokenBucket = RoExpress("TokenBucket")
local craftBucket = TokenBucket.new({ max = 5, refill = 1, cost = 1 })

app:Post("craft", function(req, res)
    if not craftBucket:Consume(req.player) then
        return res:Error(429, "Too many craft requests")
    end
    -- process craft...
    res:Send({ ok = true })
end)

See also

← TokenBucket  ·  Grant & Reset | add tokens back or reset the bucket  ·  Configuration | max, refillRate, refillInterval  ·  Request Pipeline | stage 2 rate limiting