discord_ex
discord_ex copied to clipboard
handle Rate Limits in some "good" way
RATE LIMITS docs (it's on github, link on web docs is broken)
Discord's dev request for lib developers to handle Rate Limiting properly
So, the simple way to implent:
We could have some "global state" implemented via Agent (or process) that is registered to atom name. And now, when geting REST reposnse we upgrade that "state" to current rate limit info. And when doing REST request we can:
if curr_time() < RateLimit.get(:rate_limit, "refresh_time") and RateLimit.get(:rate_limit, "req_left") == 0 do
{:error, "You have been blocked by RateLimit feature."
else
# send our request
end
I could start working on it when we agree on some architecture.
rate limiting:
HTTP
-
X-RateLimit-Remainingwill tell us how much more requests we can do -
X-RateLimit-Resetwill tell us when RL timer resets
WS
- sending limit: 120 events / minute
Game Status:
- 5 statuses / minute
Gateway connection:
- 1 connection / 5 seconds, but:
if you hit this limit the Gateway will delay your connection until the cooldown has timed out