diff options
author | mat <github@matdoes.dev> | 2022-03-27 19:43:05 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-27 19:43:05 -0500 |
commit | 5a08829b7b6f711a1ffe19ed3e2cd724c54e7b2b (patch) | |
tree | 84de1955339075cdc69e21122d7ac18557581649 | |
parent | 0a31ac6943aef19fbc63b25163ecb3b4a3c9f81b (diff) | |
download | skyblock-api-5a08829b7b6f711a1ffe19ed3e2cd724c54e7b2b.tar.gz skyblock-api-5a08829b7b6f711a1ffe19ed3e2cd724c54e7b2b.tar.bz2 skyblock-api-5a08829b7b6f711a1ffe19ed3e2cd724c54e7b2b.zip |
Fix first join & add last save leaderboard
-rw-r--r-- | src/cleaners/skyblock/member.ts | 16 | ||||
-rw-r--r-- | src/database.ts | 11 | ||||
-rw-r--r-- | src/hypixel.ts | 2 |
3 files changed, 18 insertions, 11 deletions
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 2acbd26..c7c9a2e 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -22,8 +22,8 @@ import { CleanRank } from '../rank.js' export interface CleanBasicMember { uuid: string username: string - lastSave: number - firstJoin: number + lastSave: number | null + firstJoin: number | null rank: CleanRank left?: boolean } @@ -53,8 +53,8 @@ export async function cleanSkyBlockProfileMemberResponseBasic(member: typedHypix return { uuid: member.uuid, username: player.username, - lastSave: member.last_save ?? 0, - firstJoin: member.first_join ?? 0, + lastSave: member.last_save ?? null, + firstJoin: member.first_join ?? null, rank: player.rank } } @@ -74,8 +74,8 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi uuid: member.uuid, username: player.username, // members that haven't joined the profile have no last save or first join - lastSave: member.last_save ?? 0, - firstJoin: member.first_join ?? 0, + lastSave: member.last_save ?? null, + firstJoin: member.first_join ?? null, rank: player.rank, purse: member.coin_purse ?? 0, @@ -105,8 +105,8 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi export interface CleanMemberProfilePlayer extends CleanPlayer { // The profile name may be different for each player, so we put it here profileName: string - firstJoin: number - lastSave: number + firstJoin: number | null + lastSave: number | null purse: number stats: StatItem[] rawHypixelStats: { [key: string]: number } diff --git a/src/database.ts b/src/database.ts index 1702a20..8f0ce0a 100644 --- a/src/database.ts +++ b/src/database.ts @@ -185,7 +185,7 @@ function getMemberHarpAttributes(member: CleanMember): StringNumber { function getMemberLeaderboardAttributes(member: CleanMember): StringNumber { // if you want to add a new leaderboard for member attributes, add it here (and getAllLeaderboardAttributes) - return { + const data: StringNumber = { // we use the raw stat names rather than the clean stats in case hypixel adds a new stat and it takes a while for us to clean it ...member.rawHypixelStats, @@ -202,10 +202,16 @@ function getMemberLeaderboardAttributes(member: CleanMember): StringNumber { ...getMemberHarpAttributes(member), fairy_souls: member.fairySouls.total, - first_join: member.firstJoin, purse: member.purse, visited_zones: member.zones.filter(z => z.visited).length, } + + if (member.firstJoin) + data.first_join = member.firstJoin + if (member.lastSave) + data.last_save = member.lastSave + + return data } function getProfileLeaderboardAttributes(profile: CleanFullProfile): StringNumber { @@ -290,6 +296,7 @@ export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> { 'fairy_souls', 'first_join', + 'last_save', 'purse', 'visited_zones', 'leaderboards_count', diff --git a/src/hypixel.ts b/src/hypixel.ts index 4afac53..30a9f9b 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -135,7 +135,7 @@ export async function fetchUser({ user, uuid, username }: UserAny, included: Inc if (includeProfiles) { for (const profile of profilesData!) { const member = profile.members?.find(member => member.uuid === uuid) - if (member && member.lastSave > lastOnline) { + if (member && member.lastSave && member.lastSave > lastOnline) { lastOnline = member.lastSave activeProfile = profile } |