def rate_limited?(thing, rate_limit_time = nil, increment: 1)
      key = resolve_key thing
      limit_hash = @bucket[key]

      # First case: limit_hash doesn't exist yet
      unless limit_hash
        @bucket[key] = {
          last_time: Time.now,
          set_time: Time.now,
          count: increment
        }

        return false
      end

      # Define the time at which we're being rate limited once so it doesn't get inaccurate
      rate_limit_time ||= Time.now

      if @limit && (limit_hash[:count] + increment) > @limit
        # Second case: Count is over the limit and the time has not run out yet
        return (limit_hash[:set_time] + @time_span) - rate_limit_time if @time_span && rate_limit_time < (limit_hash[:set_time] + @time_span)

        # Third case: Count is over the limit but the time has run out
        # Don't return anything here because there may still be delay-based limiting
        limit_hash[:set_time] = rate_limit_time
        limit_hash[:count] = 0
      end

      if @delay && rate_limit_time < (limit_hash[:last_time] + @delay)
        # Fourth case: we're being delayed
        (limit_hash[:last_time] + @delay) - rate_limit_time
      else
        # Fifth case: no rate limiting at all! Increment the count, set the last_time, and return false
        limit_hash[:last_time] = rate_limit_time
        limit_hash[:count] += increment
        false
      end
    end
def rate_limited?(thing, rate_limit_time = nil, increment: 1)
      key = resolve_key thing
      limit_hash = @bucket[key]

      # First case: limit_hash doesn't exist yet
      unless limit_hash
        @bucket[key] = {
          last_time: Time.now,
          set_time: Time.now,
          count: increment
        }

        return false
      end

      # Define the time at which we're being rate limited once so it doesn't get inaccurate
      rate_limit_time ||= Time.now

      if @limit && (limit_hash[:count] + increment) > @limit
        # Second case: Count is over the limit and the time has not run out yet
        return (limit_hash[:set_time] + @time_span) - rate_limit_time if @time_span && rate_limit_time < (limit_hash[:set_time] + @time_span)

        # Third case: Count is over the limit but the time has run out
        # Don't return anything here because there may still be delay-based limiting
        limit_hash[:set_time] = rate_limit_time
        limit_hash[:count] = 0
      end

      if @delay && rate_limit_time < (limit_hash[:last_time] + @delay)
        # Fourth case: we're being delayed
        (limit_hash[:last_time] + @delay) - rate_limit_time
      else
        # Fifth case: no rate limiting at all! Increment the count, set the last_time, and return false
        limit_hash[:last_time] = rate_limit_time
        limit_hash[:count] += increment
        false
      end
    end
Performs a rate limiting request
 @param thing [#resolve_id, Integer, Symbol] The particular thing that should be rate-limited (usually a user/channel, but you can also choose arbitrary integers or symbols)
 @param rate_limit_time [Time] The time to base the rate limiting on, only useful for testing.
 @param increment [Integer] How much to increment the rate-limit counter. Default is 1.
 @return [Integer, false] the waiting time until the next request, in seconds, or false if the request succeeded