Module: Discordrb::Commands::RateLimiter
- Included in:
- CommandContainer, SimpleRateLimiter
- Defined in:
- lib/discordrb/commands/rate_limiter.rb
Overview
Represents a collection of Buckets.
Instance Method Summary collapse
-
#bucket(key, attributes) ⇒ Bucket
Defines a new bucket for this rate limiter.
-
#clean ⇒ Object
Cleans all buckets.
-
#include_buckets(limiter) ⇒ Object
Adds all the buckets from another RateLimiter onto this one.
-
#rate_limited?(key, thing, increment: 1) ⇒ Integer, false
Performs a rate limit request.
Instance Method Details
#bucket(key, attributes) ⇒ Bucket
Defines a new bucket for this rate limiter.
101 102 103 104 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 101 def bucket(key, attributes) @buckets ||= {} @buckets[key] = Bucket.new(attributes[:limit], attributes[:time_span], attributes[:delay]) end |
#clean ⇒ Object
Cleans all buckets
121 122 123 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 121 def clean @buckets.each(&:clean) end |
#include_buckets(limiter) ⇒ Object
Adds all the buckets from another RateLimiter onto this one.
127 128 129 130 131 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 127 def include_buckets(limiter) buckets = limiter.instance_variable_get('@buckets') || {} @buckets ||= {} @buckets.merge! buckets end |
#rate_limited?(key, thing, increment: 1) ⇒ Integer, false
Performs a rate limit request.
112 113 114 115 116 117 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 112 def rate_limited?(key, thing, increment: 1) # Check whether the bucket actually exists return false unless @buckets && @buckets[key] @buckets[key].rate_limited?(thing, increment: increment) end |