From d00f71b611fd26216bf379df265e53493a1adcb3 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Mon, 1 Mar 2021 15:05:32 -0600 Subject: fix error on timedeo's profile --- src/hypixelCached.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts index b407a69..4063069 100644 --- a/src/hypixelCached.ts +++ b/src/hypixelCached.ts @@ -52,7 +52,7 @@ function waitForSet(cache: NodeCache, key?: string, value?: string): Promise { if (setKey === key || (value && setValue === value)) { cache.removeListener('set', listener) - return resolve({ key, value }) + return resolve({ key: setKey, value: setValue }) } } cache.on('set', listener) @@ -73,7 +73,9 @@ export async function uuidFromUser(user: string): Promise { const username: any = usernameCache.get(undashUuid(user)) // if it has .then, then that means its a waitForSet promise. This is done to prevent requests made while it is already requesting if (username.then) { - return (await username).key + const { key: uuid, value: _username } = await username + usernameCache.set(uuid, _username) + return uuid } else return undashUuid(user) } @@ -92,7 +94,10 @@ export async function uuidFromUser(user: string): Promise { // not cached, actually fetch mojang api now let { uuid, username } = await mojang.mojangDataFromUser(user) - if (!uuid) return + if (!uuid) { + usernameCache.set(uuid, null) + return + } // remove dashes from the uuid so its more normal uuid = undashUuid(uuid) @@ -133,6 +138,7 @@ export async function fetchPlayer(user: string): Promise { path: 'player', args: { uuid: playerUuid } }) + if (!cleanPlayer) return // clone in case it gets modified somehow later -- cgit