From 43f194ff780d704834706ac6da454a8858098906 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sat, 13 Feb 2021 16:03:49 -0600 Subject: add minion_count --- src/cleaners/skyblock/minions.ts | 11 ++++++++++- src/cleaners/skyblock/profile.ts | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cleaners/skyblock/minions.ts b/src/cleaners/skyblock/minions.ts index da69634..b5ac85d 100644 --- a/src/cleaners/skyblock/minions.ts +++ b/src/cleaners/skyblock/minions.ts @@ -67,4 +67,13 @@ export function combineMinionArrays(minions: CleanMinion[][]): CleanMinion[] { } return resultMinions -} \ No newline at end of file +} + +export function countUniqueMinions(minions: CleanMinion[]): number { + let uniqueMinions: number = 0 + for (const minion of minions) { + // find the number of times `true` is in the list and add it to uniqueMinions + uniqueMinions += minion.levels.filter(x => x).length + } + return uniqueMinions +} diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts index c61e6cf..5d2b7a3 100644 --- a/src/cleaners/skyblock/profile.ts +++ b/src/cleaners/skyblock/profile.ts @@ -1,5 +1,5 @@ import { CleanBasicMember, CleanMember, CleanMemberProfile, cleanSkyBlockProfileMemberResponse } from './member' -import { CleanMinion, combineMinionArrays } from './minions' +import { CleanMinion, combineMinionArrays, countUniqueMinions } from './minions' import * as cached from '../../hypixelCached' import { cleanBank } from './bank' @@ -92,6 +92,7 @@ export async function fetchMemberProfile(user: string, profile: string): Promise return { member: { + // the profile name is in member rather than profile since they sometimes differ for each member profileName: cleanProfile.name, first_join: member.first_join, last_save: member.last_save, @@ -102,6 +103,7 @@ export async function fetchMemberProfile(user: string, profile: string): Promise uuid: cleanProfile.uuid, bank: cleanProfile.bank, minions: cleanProfile.minions, + minion_count: countUniqueMinions(cleanProfile.minions) } } } -- cgit