aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock
diff options
context:
space:
mode:
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r--src/cleaners/skyblock/member.ts2
-rw-r--r--src/cleaners/skyblock/minions.ts30
2 files changed, 28 insertions, 4 deletions
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index 5d8d4f9..cfa9a71 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -67,7 +67,7 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu
// this is used for leaderboards
rawHypixelStats: member.stats ?? {},
- minions: cleanMinions(member),
+ minions: await cleanMinions(member),
fairy_souls: cleanFairySouls(member),
inventories: inventoriesIncluded ? await cleanInventories(member) : undefined,
objectives: cleanObjectives(member),
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))
}
/**