From 5105df276bfba0425d8acde26ab00862a83a7d82 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 27 Mar 2022 19:05:17 -0500 Subject: Add default skills if they're missing from member --- src/cleaners/skyblock/skills.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/cleaners') diff --git a/src/cleaners/skyblock/skills.ts b/src/cleaners/skyblock/skills.ts index 4180ab2..ac5c10c 100644 --- a/src/cleaners/skyblock/skills.ts +++ b/src/cleaners/skyblock/skills.ts @@ -1,4 +1,5 @@ import typedHypixelApi from 'typed-hypixel-api' +import { fetchSkills } from '../../constants.js' import { levelFromXpTable } from '../../util.js' export interface Skill { @@ -136,6 +137,7 @@ export function levelForSkillXp(xp: number, maxLevel: number) { } export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember): Promise { + const allSkillNames = await fetchSkills() const skills: Skill[] = [] for (const item in data) { if (item.startsWith('experience_skill_')) { @@ -170,5 +172,22 @@ export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember): }) } } + + // add missing skills + const missingSkillNames = allSkillNames.filter(skillName => !skills.some(skill => skill.name === skillName)) + for (const skillName of missingSkillNames) { + skills.push({ + name: skillName, + xp: 0, + level: 0, + maxLevel: skillsMaxLevel[skillName] ?? skillsDefaultMaxLevel, + levelXp: 0, + levelXpRequired: 0 + }) + } + + // sort skills by name + skills.sort((a, b) => a.name.localeCompare(b.name)) + return skills } -- cgit