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.
100 101 102 103 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 100 def bucket(key, attributes) @buckets ||= {} @buckets[key] = Bucket.new(attributes[:limit], attributes[:time_span], attributes[:delay]) end |
#clean ⇒ Object
Cleans all buckets
120 121 122 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 120 def clean @buckets.each(&:clean) end |
#include_buckets(limiter) ⇒ Object
Adds all the buckets from another RateLimiter onto this one.
126 127 128 129 130 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 126 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.
111 112 113 114 115 116 |
# File 'lib/discordrb/commands/rate_limiter.rb', line 111 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 |