mirror of https://gitlab.com/litecord/litecord.git
gateway: add session_start_limit
This commit is contained in:
parent
c710ad5aaf
commit
818571d336
|
|
@ -1,3 +1,5 @@
|
|||
import time
|
||||
|
||||
from quart import Blueprint, jsonify, current_app as app
|
||||
|
||||
from ..auth import token_check
|
||||
|
|
@ -31,8 +33,23 @@ async def api_gateway_bot():
|
|||
|
||||
shards = max(int(guild_count / 1000), 1)
|
||||
|
||||
# TODO: session_start_limit (depends on ratelimits)
|
||||
# get _ws.session ratelimit
|
||||
ratelimit = app.ratelimiter.get_ratelimit('_ws.session')
|
||||
bucket = ratelimit.get_bucket(user_id)
|
||||
|
||||
# timestamp of bucket reset
|
||||
reset_ts = bucket._window + bucket.second
|
||||
|
||||
# how many seconds until bucket reset
|
||||
reset_after_ts = reset_ts - time.time()
|
||||
|
||||
return jsonify({
|
||||
'url': get_gw(),
|
||||
'shards': shards,
|
||||
|
||||
'session_start_limit': {
|
||||
'total': bucket.requests,
|
||||
'remaining': bucket._tokens,
|
||||
'reset_after': int(reset_after_ts * 1000),
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue