aboutsummaryrefslogtreecommitdiff
path: root/src/hypixelCached.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-03-25 21:13:13 -0500
committermat <github@matdoes.dev>2022-03-25 21:13:13 -0500
commit6b94d0110a52a355758432ff6cd14c80553471ea (patch)
tree8113e5ee126b56f2d7e31309b5fa1fd65d008a77 /src/hypixelCached.ts
parent7f4e9c598d4697e63602bc36f9034610cac84604 (diff)
downloadskyblock-api-6b94d0110a52a355758432ff6cd14c80553471ea.tar.gz
skyblock-api-6b94d0110a52a355758432ff6cd14c80553471ea.tar.bz2
skyblock-api-6b94d0110a52a355758432ff6cd14c80553471ea.zip
Add typed-hypixel-api as a dep and change some code
Diffstat (limited to 'src/hypixelCached.ts')
-rw-r--r--src/hypixelCached.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts
index bc34ef0..5a17c3c 100644
--- a/src/hypixelCached.ts
+++ b/src/hypixelCached.ts
@@ -174,10 +174,9 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer | null> {
fetchingPlayers.add(playerUuid)
- const cleanPlayer: CleanPlayer = await hypixel.sendCleanApiRequest({
- path: 'player',
- args: { uuid: playerUuid }
- })
+ const cleanPlayer = await hypixel.sendCleanApiRequest('player',
+ { uuid: playerUuid }
+ )
fetchingPlayers.delete(playerUuid)
@@ -185,7 +184,7 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer | null> {
playerCache.set(playerUuid, cleanPlayer)
usernameCache.set(playerUuid, cleanPlayer.username)
-
+
// clone in case it gets modified somehow later
const cleanBasicPlayer = Object.assign({}, cleanPlayer)
if (cleanBasicPlayer.profiles) {
@@ -335,7 +334,8 @@ export async function fetchProfile(user: string, profile: string): Promise<Clean
if (!profileName) return null // uhh this should never happen but if it does just return null
- const cleanProfile: CleanFullProfile = await hypixel.fetchMemberProfileUncached(playerUuid, profileUuid)
+ const cleanProfile = await hypixel.fetchMemberProfileUncached(playerUuid, profileUuid)
+ if (!cleanProfile) return null
// we know the name from fetchProfileName, so set it here
cleanProfile.name = profileName
@@ -349,12 +349,12 @@ export async function fetchProfile(user: string, profile: string): Promise<Clean
* Fetch a CleanProfile from the uuid
* @param profileUuid A profile name or profile uuid
*/
-export async function fetchBasicProfileFromUuid(profileUuid: string): Promise<CleanProfile | undefined> {
+export async function fetchBasicProfileFromUuid(profileUuid: string): Promise<CleanProfile | null> {
if (profileCache.has(profileUuid)) {
// we have the profile cached, return it :)
if (debug) console.debug('Cache hit! fetchBasicProfileFromUuid', profileUuid)
const profile: CleanFullProfile | undefined = profileCache.get(profileUuid)
- if (!profile) return undefined
+ if (!profile) return null
return {
uuid: profile.uuid,
members: profile.members.map(m => ({