feat: add rateLimit event (#447)

* fix(controllers): change return value of INTERACTION_CREATE event

* feat: add rateLimit event

Closes https://github.com/discordeno/discordeno/issues/349

* Revert "fix(controllers): change return value of INTERACTION_CREATE event"

This reverts commit 9bc52d2ebf.

* https://open.spotify.com/track/6fxVffaTuwjgEk5h9QyRjy
This commit is contained in:
Ayyan
2021-01-24 23:04:34 +04:00
committed by GitHub
parent b679905b5c
commit 417315f89e
2 changed files with 27 additions and 0 deletions

View File

@@ -423,5 +423,16 @@ function processHeaders(url: string, headers: Headers) {
}
}
if (ratelimited) {
eventHandlers.rateLimit?.({
remaining,
bucketID,
global,
resetTimestamp,
retryAfter,
url,
});
}
return ratelimited ? bucketID : undefined;
}

View File

@@ -72,7 +72,23 @@ export interface DebugArg {
data: unknown;
}
interface RateLimitData {
/** The number of remaining requests that can be made */
remaining: string | null;
/** Epoch time (seconds since 00:00:00 UTC on January 1, 1970) at which the rate limit resets */
resetTimestamp: string | null;
/** Total time (in seconds) of when the current rate limit bucket will reset. Can have decimals to match previous millisecond ratelimit precision */
retryAfter: string | null;
/** Returned only on a HTTP 429 response if the rate limit headers returned are of the global rate limit (not per-route) */
global: string | null;
/** A unique string denoting the rate limit being encountered (non-inclusive of major parameters in the route path) */
bucketID: string | null;
/** The URL the HTTP request is made to */
url: string;
}
export interface EventHandlers {
rateLimit?: (data: RateLimitData) => unknown;
applicationCommandCreate?: (data: Application) => unknown;
/** Sent when properties about the user change. */
botUpdate?: (user: UserPayload) => unknown;