diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-05-01 19:04:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-01 19:04:52 -0500 |
commit | 4b78c2fbdfcdd9dcc794e4b0c17cfb6d88a1006b (patch) | |
tree | 6e8281984bef6d30cd2988fbf80bfcd22c4f668e /src/cleaners/skyblock/minions.ts | |
parent | 644e9c6629453b07844ca83fab7fbe9a3185b4b6 (diff) | |
download | skyblock-api-4b78c2fbdfcdd9dcc794e4b0c17cfb6d88a1006b.tar.gz skyblock-api-4b78c2fbdfcdd9dcc794e4b0c17cfb6d88a1006b.tar.bz2 skyblock-api-4b78c2fbdfcdd9dcc794e4b0c17cfb6d88a1006b.zip |
Show minions that haven't been unlocked in response (#20)
* add minions that haven't been unlocked yet to response, and slightly optimize constants
* remove most console.logs with console.debugs
* mock constants
Diffstat (limited to 'src/cleaners/skyblock/minions.ts')
-rw-r--r-- | src/cleaners/skyblock/minions.ts | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/cleaners/skyblock/minions.ts b/src/cleaners/skyblock/minions.ts index 06e7752..21f7b66 100644 --- a/src/cleaners/skyblock/minions.ts +++ b/src/cleaners/skyblock/minions.ts @@ -1,4 +1,5 @@ import { maxMinion } from '../../hypixel' +import * as constants from '../../constants' export interface CleanMinion { name: string, @@ -10,9 +11,11 @@ export interface CleanMinion { * Clean the minions provided by Hypixel * @param minionsRaw The minion data provided by the Hypixel API */ -export function cleanMinions(data: any): CleanMinion[] { +export async function cleanMinions(member: any): Promise<CleanMinion[]> { const minions: CleanMinion[] = [] - for (const minionRaw of data?.crafted_generators ?? []) { + const processedMinionNames: Set<string> = new Set() + + for (const minionRaw of member?.crafted_generators ?? []) { // do some regex magic to get the minion name and level // examples of potential minion names: CLAY_11, PIG_1, MAGMA_CUBE_4 const minionName = minionRaw.split(/_\d/)[0].toLowerCase() @@ -32,8 +35,29 @@ export function cleanMinions(data: any): CleanMinion[] { // set the minion at that level to true matchingMinion.levels[minionLevel - 1] = true + processedMinionNames.add(minionName) + } + + const allMinionNames = new Set(await constants.fetchMinions()) + + for (const minionName of processedMinionNames) { + if (!allMinionNames.has(minionName)) { + constants.addMinions(Array.from(processedMinionNames)) + break + } } - return minions + + for (const minionName of allMinionNames) { + if (!processedMinionNames.has(minionName)) { + processedMinionNames.add(minionName) + minions.push({ + name: minionName, + levels: new Array(maxMinion).fill(false) + }) + } + } + + return minions.sort((a, b) => a.name > b.name ? 1 : (a.name < b.name ? -1 : 0)) } /** |