Files
discordeno/src/rest/check_rate_limits.ts
T
Skillz4Killz a9e5ce01c9 stuff
2021-09-30 08:06:42 +00:00

18 lines
511 B
TypeScript

import { RestManager } from "../bot.ts";
/** Check the rate limits for a url or a bucket. */
export function checkRateLimits(rest: RestManager, 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;
}