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) ⇒ Integer, false
Performs a rate limit request.
Instance Method Details
#bucket(key, attributes) ⇒ Bucket
Defines a new bucket for this rate limiter.
99 100 101 102 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 99 def bucket(key, attributes) @buckets ||= {} @buckets[key] = Bucket.new(attributes[:limit], attributes[:time_span], attributes[:delay]) end |
#clean ⇒ Object
Cleans all buckets
118 119 120 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 118 def clean @buckets.each(&:clean) end |
#include_buckets(limiter) ⇒ Object
Adds all the buckets from another RateLimiter onto this one.
124 125 126 127 128 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 124 def include_buckets(limiter) buckets = limiter.instance_variable_get('@buckets') || {} @buckets ||= {} @buckets.merge! buckets end |
#rate_limited?(key, thing) ⇒ Integer, false
Performs a rate limit request.
109 110 111 112 113 114 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 109 def rate_limited?(key, thing) # Check whether the bucket actually exists return false unless @buckets && @buckets[key] @buckets[key].rate_limited?(thing) end |