RateLimitProxy
A proxy towards a rate limit.
Attributes client :
Who's rate limits will be looked up.
The proxy's rate limit group to pull additional information.
or (
WeakReferer to
RateLimitHandler
)Reference to the actual rate limit handler of the client
with the specified group
and limiter
.
RateLimit handler used to lookup the active one.
Properties
free_count
Returns how much requests can be done towards the represented rate limit.
If the rate limit proxy represents an unlimited endpoint, then 0
is returned.
Returns
free_count : int
handler
Returns the client's represented active handler if applicable.
Returns
handler : None
, RateLimitHandler
keep_alive
Get-set property for accessing whether the rate limit proxy should keep alive the respective rate limit handler.
Accepts and returns bool
.
limiter_id
Returns the the represented rate limit handler's .limiter_id
.
Returns
limiter_id : int
next_reset_after
Familiar to .next_reset_at
but it instead returns how time is left till next reset instead.
Returns
next_reset_after : float
next_reset_at
Returns when the next rate limit reset will happen of the represented rate limit handler.
If there is no active rate limit handler represented or if the handler has has 0 used up limits, then returns 0.0
. if there is any, then returns it in LOOP_TIME
time.
Returns
next_reset_at : float
size
Returns the represented rate limit group's size.
Returns
size : int
used_count
Returns how much requests are used up or already done right now.
Returns
count : int
waiting_count
Returns how much requests are waiting in queue by the represented rate limit.
Returns
count : int
Methods
(client, group, ...)
__new__Creates a new rate limit proxy.
Parameter | Type | Optional | Default | Description | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
client | Who's rate limits will be looked up. | |||||||||||||||||
group | The proxy's rate limit group to pull additional information. | |||||||||||||||||
limiter |
|
| What's rate limits will be looked up. The accepted types depend on the group's limiter:
Note that at the case of | |||||||||||||||
keep_alive |
|
| Whether the rate limit proxy should keep alive the respective rate limit handler. Defaults to |
Raises
RuntimeError
If the given group
's limiter is not any of the predefined ones. Note that limiters are compared by memory address and not by value.
TypeError
If group
was not given as RateLimitGroup
.
ValueError
If the given limiter
cannot be casted to limiter_id
with the specified group
.
()
has_infoReturns whether the represented rate limit handler now stores any rate limit information.
Returns
has_info : bool
()
has_size_setReturns whether the represented rate limit group size is already set.
Not only not used rate limit groups, but still optimistic or unlimited rate limit groups fall under this category as well.
Returns
has_size_set : bool
()
is_aliveReturns whether the respective client has the represented rate limit handler is alive.
Returns
is_alive : bool
()
is_limited_by_channelReturns whether the represented rate limit group is limited by channel id.
Returns
is_limited_by_channel : bool
()
is_limited_by_guildReturns whether the represented rate limit group is limited by guild id.
Returns
is_limited_by_guild : bool
()
is_limited_by_interactionReturns whether the represented rate limit group is limited by interaction id.
Returns
is_limited_by_interaction : bool
()
is_limited_by_webhookReturns whether the represented rate limit group is limited by webhook id.
Returns
is_limited_by_webhook : bool
()
is_limited_globallyReturns whether the represented rate limit group is limited globally,
Returns
is_limited_globally : bool
()
is_unlimitedReturns whether the represented rate limit group is unlimited,
Returns
is_unlimited : bool
()
wait_till_limits_expireWaits till the represented rate limits expire.
This method is a coroutine.
Raises
RuntimeError
If the method is called meanwhile keep_alive
is True
.
Notes
The waiting is implemented with weakreference callback, so the coroutine returns when the source callback is garbage collected. This also means waiting on the exact same limit multiple times causes misbehaviour.
()
__hash__Hashes the rate limit proxy.
Classes
_wait_till_limits_expire_callback
WeakReferer
callback used at .wait_till_limits_expire
for waking it up.
Attributes
Future
The future to set it's result of.