diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 20:11:53 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 20:11:53 -0600 |
commit | cd707234194b41df933a3a287b5fbec3657063d5 (patch) | |
tree | 22115a93afcba5b268fbeb9d69b7e1fa8ed95fa6 /src/cleaners/skyblock | |
parent | 9b2856303374521b315759500cf594ec7f22d293 (diff) | |
download | skyblock-api-cd707234194b41df933a3a287b5fbec3657063d5.tar.gz skyblock-api-cd707234194b41df933a3a287b5fbec3657063d5.tar.bz2 skyblock-api-cd707234194b41df933a3a287b5fbec3657063d5.zip |
add objectives and skills
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/bank.ts | 3 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 30 | ||||
-rw-r--r-- | src/cleaners/skyblock/objectives.ts | 17 | ||||
-rw-r--r-- | src/cleaners/skyblock/profile.ts | 10 | ||||
-rw-r--r-- | src/cleaners/skyblock/skills.ts | 19 | ||||
-rw-r--r-- | src/cleaners/skyblock/stats.ts | 8 |
6 files changed, 68 insertions, 19 deletions
diff --git a/src/cleaners/skyblock/bank.ts b/src/cleaners/skyblock/bank.ts index 302f392..4735bec 100644 --- a/src/cleaners/skyblock/bank.ts +++ b/src/cleaners/skyblock/bank.ts @@ -7,6 +7,7 @@ export function cleanBank(data: any): Bank { return { balance: data?.banking?.balance ?? 0, // TODO: make transactions good - history: data?.banking?.transactions ?? [] + // history: data?.banking?.transactions ?? [] + history: [] } }
\ No newline at end of file diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index d7d0cd1..04aa476 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -5,6 +5,7 @@ import { Bank } from './bank' import { cleanFairySouls, FairySouls } from './fairysouls' import { cleanInventories, INVENTORIES } from './inventory' import { CleanMinion, cleanMinions } from './minions' +import { cleanObjectives, Objective } from './objectives' import { CleanFullProfile } from './profile' import { CleanProfileStats, cleanProfileStats } from './stats' @@ -16,29 +17,38 @@ export interface CleanBasicMember { } export interface CleanMember extends CleanBasicMember { - stats?: CleanProfileStats - minions?: CleanMinion[] - bank?: Bank - fairy_souls?: FairySouls + stats: CleanProfileStats + minions: CleanMinion[] + fairy_souls: FairySouls inventories: typeof INVENTORIES + objectives: Objective[] } +export async function cleanSkyBlockProfileMemberResponseBasic(member, included: Included[] = null): Promise<CleanBasicMember> { + return { + uuid: member.uuid, + username: await cached.usernameFromUser(member.uuid), + last_save: member.last_save, + first_join: member.first_join, + } +} /** Cleans up a member (from skyblock/profile) */ export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> { // profiles.members[] - const statsIncluded = included == null || included.includes('stats') const inventoriesIncluded = included == null || included.includes('inventories') return { uuid: member.uuid, username: await cached.usernameFromUser(member.uuid), last_save: member.last_save, first_join: member.first_join, - // last_death: ??? idk how this is formatted, - stats: statsIncluded ? cleanProfileStats(member?.stats) : undefined, - minions: statsIncluded ? cleanMinions(member) : undefined, - fairy_souls: statsIncluded ? cleanFairySouls(member) : undefined, - inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, + + stats: cleanProfileStats(member), + minions: cleanMinions(member), + fairy_souls: cleanFairySouls(member), + inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, + objectives: cleanObjectives(member), + // skills: statsIncluded ? } } diff --git a/src/cleaners/skyblock/objectives.ts b/src/cleaners/skyblock/objectives.ts new file mode 100644 index 0000000..3427f1f --- /dev/null +++ b/src/cleaners/skyblock/objectives.ts @@ -0,0 +1,17 @@ +export interface Objective { + name: string + completed: boolean +} + +export function cleanObjectives(data: any): Objective[] { + const rawObjectives = data?.objectives || {} + const objectives: Objective[] = [] + for (const rawObjectiveName in rawObjectives) { + const rawObjectiveValue = rawObjectives[rawObjectiveName] + objectives.push({ + name: rawObjectiveName, + completed: rawObjectiveValue.status === 'COMPLETE', + }) + } + return objectives +} diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts index b4a8574..2b092a1 100644 --- a/src/cleaners/skyblock/profile.ts +++ b/src/cleaners/skyblock/profile.ts @@ -1,4 +1,4 @@ -import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse } from './member' +import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse, cleanSkyBlockProfileMemberResponseBasic } from './member' import { CleanMinion, combineMinionArrays, countUniqueMinions } from './minions' import { Bank, cleanBank } from './bank' import { ApiOptions } from '../../hypixel' @@ -8,7 +8,7 @@ export interface CleanProfile extends CleanBasicProfile { } export interface CleanFullProfile extends CleanProfile { - members: CleanMember[] + members: (CleanMember|CleanBasicMember)[] bank: Bank minions: CleanMinion[] minion_count: number @@ -17,16 +17,16 @@ export interface CleanFullProfile extends CleanProfile { /** Return a `CleanProfile` instead of a `CleanFullProfile`, useful when we need to get members but don't want to waste much ram */ export async function cleanSkyblockProfileResponseLighter(data): Promise<CleanProfile> { // We use Promise.all so it can fetch all the usernames at once instead of waiting for the previous promise to complete - const promises: Promise<CleanMember>[] = [] + const promises: Promise<CleanBasicMember>[] = [] for (const memberUUID in data.members) { const memberRaw = data.members[memberUUID] memberRaw.uuid = memberUUID // we pass an empty array to make it not check stats - promises.push(cleanSkyBlockProfileMemberResponse(memberRaw, [])) + promises.push(cleanSkyBlockProfileMemberResponseBasic(memberRaw)) } - const cleanedMembers: CleanMember[] = await Promise.all(promises) + const cleanedMembers: CleanBasicMember[] = await Promise.all(promises) return { uuid: data.profile_id, diff --git a/src/cleaners/skyblock/skills.ts b/src/cleaners/skyblock/skills.ts new file mode 100644 index 0000000..e283379 --- /dev/null +++ b/src/cleaners/skyblock/skills.ts @@ -0,0 +1,19 @@ +export interface Skill { + name: string + xp: number +} + +export function cleanSkills(data: any): Skill[] { + const skills: Skill[] = [] + for (const item in data) { + if (item.startsWith('experience_skill_')) { + const skillName = item.substr('experience_skill_'.length) + const skillValue = data[item] + skills.push({ + name: skillName, + xp: skillValue + }) + } + } + return skills +} diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts index 1222582..99aa1f7 100644 --- a/src/cleaners/skyblock/stats.ts +++ b/src/cleaners/skyblock/stats.ts @@ -61,13 +61,15 @@ export interface CleanProfileStats { } } -export function cleanProfileStats(statsRaw: any): CleanProfileStats { +export function cleanProfileStats(data: any): CleanProfileStats { // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there) const stats: CleanProfileStats = {} - for (let statNameRaw in statsRaw) { + const rawStats = data?.stats ?? {} + for (const statNameRaw in rawStats) { + const statValue = rawStats[statNameRaw] let { category: statCategory, name: statName } = categorizeStat(statNameRaw) if (!stats[statCategory]) stats[statCategory] = {} - stats[statCategory][statName || 'total'] = statsRaw[statNameRaw] + stats[statCategory][statName || 'total'] = statValue } return stats } |