From fd2348bf16c55422ec664e6677b636998eccc71c Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sun, 14 Feb 2021 19:01:27 -0600 Subject: fix special cases some users dont have a rank, and some users dont have skyblock profiles --- src/cleaners/player.ts | 14 +++++++------- src/cleaners/rank.ts | 16 ++++++++++------ src/cleaners/skyblock/member.ts | 2 +- src/cleaners/skyblock/profiles.ts | 4 ++-- src/cleaners/socialmedia.ts | 6 +++--- src/hypixel.ts | 7 +++++-- src/hypixelCached.ts | 4 +++- 7 files changed, 31 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/cleaners/player.ts b/src/cleaners/player.ts index f49d72c..f4cbb18 100644 --- a/src/cleaners/player.ts +++ b/src/cleaners/player.ts @@ -1,9 +1,9 @@ -import { CleanSocialMedia, parseSocialMedia } from './socialmedia' -import { CleanRank, parseRank } from './rank' +import { cleanPlayerSkyblockProfiles } from './skyblock/profiles' +import { cleanSocialMedia, CleanSocialMedia } from './socialmedia' +import { CleanBasicProfile } from './skyblock/profile' +import { cleanRank, CleanRank } from './rank' import { HypixelPlayer } from '../hypixelApi' import { undashUuid } from '../util' -import { CleanBasicProfile } from './skyblock/profile' -import { cleanPlayerSkyblockProfiles } from './skyblock/profiles' export interface CleanBasicPlayer { uuid: string @@ -21,8 +21,8 @@ export async function cleanPlayerResponse(data: HypixelPlayer): Promise= 1) colored = `${rankColorPrefix}[${nameWithoutPlus}§${plusColor}${plusesInName}${rankColorPrefix}]` - else + else if (name !== 'NONE') colored = `${rankColorPrefix}[${name}]` + else + // nons don't have a prefix + colored = `${rankColorPrefix}` } return { name, diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 6d419e1..a6bb4c5 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -11,7 +11,7 @@ import { CleanPlayer } from '../player' import { Bank } from './bank' import { cleanVisitedZones, Zone } from './zones' import { cleanCollections, Collection } from './collections' -import { cleanSlayers, Slayer, SlayerData } from './slayers' +import { cleanSlayers, SlayerData } from './slayers' export interface CleanBasicMember { uuid: string diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts index c942a14..0138c0b 100644 --- a/src/cleaners/skyblock/profiles.ts +++ b/src/cleaners/skyblock/profiles.ts @@ -3,7 +3,7 @@ import { CleanBasicProfile, CleanProfile, cleanSkyblockProfileResponseLighter } export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBlockProfiles): CleanBasicProfile[] { let profiles: CleanBasicProfile[] = [] - for (const profile of Object.values(rawProfiles)) { + for (const profile of Object.values(rawProfiles ?? {})) { profiles.push({ uuid: profile.profile_id, name: profile.cute_name @@ -16,7 +16,7 @@ export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBl /** Convert an array of raw profiles into clean profiles */ export async function cleanSkyblockProfilesResponse(data: any[]): Promise { const cleanedProfiles: CleanProfile[] = [] - for (const profile of data) { + for (const profile of data ?? []) { let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile) cleanedProfiles.push(cleanedProfile) } diff --git a/src/cleaners/socialmedia.ts b/src/cleaners/socialmedia.ts index c1f9551..c7ab7ef 100644 --- a/src/cleaners/socialmedia.ts +++ b/src/cleaners/socialmedia.ts @@ -5,10 +5,10 @@ export interface CleanSocialMedia { forums: string | null } -export function parseSocialMedia(socialMedia: HypixelPlayerSocialMedia): CleanSocialMedia { +export function cleanSocialMedia(data): CleanSocialMedia { return { - discord: socialMedia?.links?.DISCORD || null, - forums: socialMedia?.links?.HYPIXEL || null + discord: data?.socialMedia?.links?.DISCORD || null, + forums: data?.socialMedia?.links?.HYPIXEL || null } } diff --git a/src/hypixel.ts b/src/hypixel.ts index 8a955ab..395748a 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -59,8 +59,8 @@ export interface UserAny { } export interface CleanUser { - player: any - profiles?: any + player: CleanPlayer + profiles?: CleanProfile[] activeProfile?: string online?: boolean } @@ -126,6 +126,9 @@ export async function fetchMemberProfile(user: string, profile: string): Promise const playerUuid = await cached.uuidFromUser(user) const profileUuid = await cached.fetchProfileUuid(user, profile) + // if the profile doesn't have an id, just return + if (!profileUuid) return null + const player = await cached.fetchPlayer(playerUuid) const cleanProfile = await cached.fetchProfile(playerUuid, profileUuid) diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts index f98f6d6..35f1cbb 100644 --- a/src/hypixelCached.ts +++ b/src/hypixelCached.ts @@ -8,7 +8,6 @@ import * as hypixel from './hypixel' import { CleanPlayer } from './cleaners/player' import { undashUuid } from './util' import { CleanProfile, CleanFullProfile, CleanBasicProfile } from './cleaners/skyblock/profile' -import { cleanProfileStats } from './cleaners/skyblock/stats' // cache usernames for 4 hours @@ -177,6 +176,9 @@ async function fetchBasicProfiles(user: string): Promise { * @param profile A profile name or profile uuid */ export async function fetchProfileUuid(user: string, profile: string) { + // if a profile wasn't provided, return + if (!profile) return null + const profiles = await fetchBasicProfiles(user) const profileUuid = undashUuid(profile) -- cgit