aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/cleaners/player.ts14
-rw-r--r--src/cleaners/rank.ts16
-rw-r--r--src/cleaners/skyblock/member.ts2
-rw-r--r--src/cleaners/skyblock/profiles.ts4
-rw-r--r--src/cleaners/socialmedia.ts6
-rw-r--r--src/hypixel.ts7
-rw-r--r--src/hypixelCached.ts4
8 files changed, 32 insertions, 23 deletions
diff --git a/README.md b/README.md
index bf28cae..5767202 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# SkyBlock API
-The thing that powers [skyblock.matdoes.dev](https://github.com/mat-1/skyblock-stats)
+The thing that powers [skyblock.matdoes.dev](https://github.com/skyblockstats/skyblock-stats)
Basically this is [Slothpixel](https://github.com/slothpixel/core) but more specialized
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<CleanPla
return {
uuid: undashUuid(data.uuid),
username: data.displayname,
- rank: parseRank(data),
- socials: parseSocialMedia(data.socialMedia),
- profiles: cleanPlayerSkyblockProfiles(data.stats.SkyBlock.profiles)
+ rank: cleanRank(data),
+ socials: cleanSocialMedia(data),
+ profiles: cleanPlayerSkyblockProfiles(data.stats?.SkyBlock?.profiles)
}
}
diff --git a/src/cleaners/rank.ts b/src/cleaners/rank.ts
index 49520a9..bd39088 100644
--- a/src/cleaners/rank.ts
+++ b/src/cleaners/rank.ts
@@ -1,5 +1,5 @@
-import { HypixelPlayer } from '../hypixelApi'
import { colorCodeFromName, minecraftColorCodes } from '../util'
+import { HypixelPlayer } from '../hypixelApi'
const rankColors: { [ name: string ]: string } = {
'NONE': '7',
@@ -21,7 +21,7 @@ export interface CleanRank {
}
/** Response cleaning (reformatting to be nicer) */
-export function parseRank({
+export function cleanRank({
packageRank,
newPackageRank,
monthlyPackageRank,
@@ -38,24 +38,28 @@ export function parseRank({
name = colored.replace(/§./g, '').replace(/[\[\]]/g, '')
} else {
name = rank
- || newPackageRank.replace('_PLUS', '+')
- || packageRank.replace('_PLUS', '+')
+ || newPackageRank?.replace('_PLUS', '+')
+ || packageRank?.replace('_PLUS', '+')
|| monthlyPackageRank
// MVP++ is called Superstar for some reason
if (name === 'SUPERSTAR') name = 'MVP++'
// YouTube rank is called YouTuber, change this to the proper name
else if (name === 'YOUTUBER') name = 'YOUTUBE'
+ else if (name === undefined) name = 'NONE'
- const plusColor = colorCodeFromName(rankPlusColor)
+ const plusColor = rankPlusColor ? colorCodeFromName(rankPlusColor) : null
color = minecraftColorCodes[rankColors[name]]
const rankColorPrefix = rankColors[name] ? '§' + rankColors[name] : ''
const nameWithoutPlus = name.split('+')[0]
const plusesInName = '+'.repeat(name.split('+').length - 1)
if (plusColor && plusesInName.length >= 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<CleanProfile[]> {
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<CleanBasicProfile[]> {
* @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)