From b14a077a9bc35384d7561fd1b39bdad389cc4a53 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 1 Jun 2021 19:41:18 -0500 Subject: add key usage info to index --- src/hypixelApi.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/hypixelApi.ts') 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 -- cgit