Files
discordeno/src/rest/check_rate_limits.ts
T
Skillz4Killz ebb15afa0e refactor(rest): separate functions into diff files (#685)
* shtufffff

* fixe rate limit path infinite loop

* refactor

* ID > id

* Update process_request_headers.ts

* file names

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
Co-authored-by: ayntee <ayyantee@gmail.com>
2021-03-29 23:50:08 +04:00

18 lines
485 B
TypeScript

import { rest } from "./rest.ts";
/** Check the rate limits for a url or a bucket. */
export function checkRateLimits(url: string) {
const ratelimited = rest.ratelimitedPaths.get(url);
const global = rest.ratelimitedPaths.get("global");
const now = Date.now();
if (ratelimited && now < ratelimited.resetTimestamp) {
return ratelimited.resetTimestamp - now;
}
if (global && now < global.resetTimestamp) {
return global.resetTimestamp - now;
}
return false;
}