From 4d7552c19f85de7137457fd443b05dc9eb7d1e6c Mon Sep 17 00:00:00 2001 From: mat-1 Date: Wed, 2 Jun 2021 00:41:52 +0000 Subject: Compiled TS into JS --- build/hypixelApi.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'build/hypixelApi.js') diff --git a/build/hypixelApi.js b/build/hypixelApi.js index 9f54ef2..59a798c 100644 --- a/build/hypixelApi.js +++ b/build/hypixelApi.js @@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; var _a, _b, _c; Object.defineProperty(exports, "__esModule", { value: true }); -exports.sendApiRequest = exports.chooseApiKey = void 0; +exports.sendApiRequest = exports.getKeyUsage = exports.chooseApiKey = void 0; /** * Fetch the raw Hypixel API */ @@ -27,7 +27,7 @@ function chooseApiKey() { // find the api key with the lowest amount of uses let bestKeyUsage = null; let bestKey = null; - for (var key of util_1.shuffle(apiKeys)) { + for (let key of util_1.shuffle(apiKeys)) { const keyUsage = apiKeyUsage[key]; // if the key has never been used before, use it if (!keyUsage) @@ -44,6 +44,19 @@ function chooseApiKey() { return bestKey; } exports.chooseApiKey = chooseApiKey; +function getKeyUsage() { + let keyLimit = 0; + let keyUsage = 0; + for (let key of Object.values(apiKeyUsage)) { + keyLimit += key.limit; + keyUsage += key.limit - key.remaining; + } + return { + limit: keyLimit, + usage: keyUsage + }; +} +exports.getKeyUsage = getKeyUsage; /** Send an HTTP request to the Hypixel API */ async function sendApiRequest({ path, key, args }) { // Send a raw http request to api.hypixel.net, and return the parsed json -- cgit