aboutsummaryrefslogtreecommitdiff
path: root/src/hypixel.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/hypixel.ts')
-rw-r--r--src/hypixel.ts34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/hypixel.ts b/src/hypixel.ts
index 4d3e692..99bc671 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -2,14 +2,14 @@
* Fetch the clean Hypixel API
*/
-import { CleanPlayer, cleanPlayerResponse } from './cleaners/player'
-import { chooseApiKey, HypixelResponse, sendApiRequest } from './hypixelApi'
-import * as cached from './hypixelCached'
-import { CleanBasicMember, CleanMemberProfile } from './cleaners/skyblock/member'
import { cleanSkyblockProfileResponse, CleanProfile, CleanBasicProfile, CleanFullProfile, CleanFullProfileBasicMembers } from './cleaners/skyblock/profile'
+import { AccountCustomization, AccountSchema, fetchAccount, queueUpdateDatabaseMember, queueUpdateDatabaseProfile } from './database'
+import { CleanBasicMember, CleanMemberProfile } from './cleaners/skyblock/member'
+import { chooseApiKey, HypixelResponse, sendApiRequest } from './hypixelApi'
import { cleanSkyblockProfilesResponse } from './cleaners/skyblock/profiles'
+import { CleanPlayer, cleanPlayerResponse } from './cleaners/player'
+import * as cached from './hypixelCached'
import { debug } from '.'
-import { queueUpdateDatabaseMember, queueUpdateDatabaseProfile } from './database'
export type Included = 'profiles' | 'player' | 'stats' | 'inventories'
@@ -67,6 +67,7 @@ export interface CleanUser {
profiles?: CleanProfile[]
activeProfile?: string
online?: boolean
+ customization?: AccountCustomization
}
@@ -76,11 +77,12 @@ export interface CleanUser {
* @param included lets you choose what is returned, so there's less processing required on the backend
* used inclusions: player, profiles
*/
-export async function fetchUser({ user, uuid, username }: UserAny, included: Included[]=['player']): Promise<CleanUser> {
+export async function fetchUser({ user, uuid, username }: UserAny, included: Included[]=['player'], customization?: boolean): Promise<CleanUser> {
if (!uuid) {
// If the uuid isn't provided, get it
uuid = await cached.uuidFromUser(user || username)
}
+ const websiteAccountPromise = customization ? fetchAccount(uuid) : null
if (!uuid) {
// the user doesn't exist.
if (debug) console.debug('error:', user, 'doesnt exist')
@@ -118,11 +120,16 @@ export async function fetchUser({ user, uuid, username }: UserAny, included: Inc
}
}
}
+ let websiteAccount: AccountSchema = undefined
+
+ if (websiteAccountPromise)
+ websiteAccount = await websiteAccountPromise
return {
player: playerData ?? null,
profiles: profilesData ?? basicProfilesData,
activeProfile: includeProfiles ? activeProfile?.uuid : undefined,
- online: includeProfiles ? lastOnline > (Date.now() - saveInterval): undefined
+ online: includeProfiles ? lastOnline > (Date.now() - saveInterval): undefined,
+ customization: websiteAccount?.customization
}
}
@@ -131,9 +138,12 @@ export async function fetchUser({ user, uuid, username }: UserAny, included: Inc
* This is safe to use many times as the results are cached!
* @param user A username or uuid
* @param profile A profile name or profile uuid
+ * @param customization Whether stuff like the user's custom background will be returned
*/
-export async function fetchMemberProfile(user: string, profile: string): Promise<CleanMemberProfile> {
+export async function fetchMemberProfile(user: string, profile: string, customization: boolean): Promise<CleanMemberProfile> {
const playerUuid = await cached.uuidFromUser(user)
+ // we don't await the promise immediately so it can load while we do other stuff
+ const websiteAccountPromise = customization ? fetchAccount(playerUuid) : null
const profileUuid = await cached.fetchProfileUuid(user, profile)
// if the profile doesn't have an id, just return
@@ -158,6 +168,11 @@ export async function fetchMemberProfile(user: string, profile: string): Promise
cleanProfile.members = simpleMembers
+ let websiteAccount: AccountSchema = undefined
+
+ if (websiteAccountPromise)
+ websiteAccount = await websiteAccountPromise
+
return {
member: {
// the profile name is in member rather than profile since they sometimes differ for each member
@@ -167,7 +182,8 @@ export async function fetchMemberProfile(user: string, profile: string): Promise
// add all other data relating to the hypixel player, such as username, rank, etc
...player
},
- profile: cleanProfile
+ profile: cleanProfile,
+ customization: websiteAccount?.customization
}
}