diff options
author | mat <github@matdoes.dev> | 2021-06-01 19:41:18 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2021-06-01 19:41:18 -0500 |
commit | b14a077a9bc35384d7561fd1b39bdad389cc4a53 (patch) | |
tree | 60932357984618c0b815dfa6b8eee7c10bc2fcd8 /src/hypixelApi.ts | |
parent | 58cf3377dfcb47d58e2ef936dcbbfa99c37783c4 (diff) | |
download | skyblock-api-b14a077a9bc35384d7561fd1b39bdad389cc4a53.tar.gz skyblock-api-b14a077a9bc35384d7561fd1b39bdad389cc4a53.tar.bz2 skyblock-api-b14a077a9bc35384d7561fd1b39bdad389cc4a53.zip |
add key usage info to index
Diffstat (limited to 'src/hypixelApi.ts')
-rw-r--r-- | src/hypixelApi.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts index 72af1af..a212f34 100644 --- a/src/hypixelApi.ts +++ b/src/hypixelApi.ts @@ -36,7 +36,7 @@ export function chooseApiKey(): string { // find the api key with the lowest amount of uses let bestKeyUsage: KeyUsage = null let bestKey: string = null - for (var key of shuffle(apiKeys)) { + for (let key of shuffle(apiKeys)) { const keyUsage = apiKeyUsage[key] // if the key has never been used before, use it @@ -55,6 +55,19 @@ export function chooseApiKey(): string { return bestKey } +export 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 + } +} + export interface HypixelResponse { [key: string]: any | { success: boolean |