diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hypixelApi.ts | 15 | ||||
-rw-r--r-- | src/index.ts | 2 |
2 files changed, 16 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 diff --git a/src/index.ts b/src/index.ts index a4f9a39..0a27e4f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import rateLimit from 'express-rate-limit' import * as constants from './constants' import * as discord from './discord' import express from 'express' +import { getKeyUsage } from './hypixelApi' const app = express() @@ -39,6 +40,7 @@ app.get('/', async(req, res) => { finishedCachingRawLeaderboards, leaderboardUpdateMemberQueueSize: leaderboardUpdateMemberQueue.size, leaderboardUpdateProfileQueueSize: leaderboardUpdateProfileQueue.size, + key: getKeyUsage() }) }) |