diff --git a/litecord/blueprints/gateway.py b/litecord/blueprints/gateway.py index 76567aa..a301cac 100644 --- a/litecord/blueprints/gateway.py +++ b/litecord/blueprints/gateway.py @@ -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), + } })