diff options
Diffstat (limited to 'build/cleaners')
-rw-r--r-- | build/cleaners/player.js | 17 | ||||
-rw-r--r-- | build/cleaners/rank.js | 81 | ||||
-rw-r--r-- | build/cleaners/skyblock/bank.js | 8 | ||||
-rw-r--r-- | build/cleaners/skyblock/collections.js | 116 | ||||
-rw-r--r-- | build/cleaners/skyblock/fairysouls.js | 7 | ||||
-rw-r--r-- | build/cleaners/skyblock/inventory.js | 83 | ||||
-rw-r--r-- | build/cleaners/skyblock/itemId.js | 57 | ||||
-rw-r--r-- | build/cleaners/skyblock/member.js | 54 | ||||
-rw-r--r-- | build/cleaners/skyblock/minions.js | 85 | ||||
-rw-r--r-- | build/cleaners/skyblock/objectives.js | 12 | ||||
-rw-r--r-- | build/cleaners/skyblock/profile.js | 64 | ||||
-rw-r--r-- | build/cleaners/skyblock/profiles.js | 21 | ||||
-rw-r--r-- | build/cleaners/skyblock/skills.js | 146 | ||||
-rw-r--r-- | build/cleaners/skyblock/slayers.js | 60 | ||||
-rw-r--r-- | build/cleaners/skyblock/stats.js | 91 | ||||
-rw-r--r-- | build/cleaners/skyblock/zones.js | 23 | ||||
-rw-r--r-- | build/cleaners/socialmedia.js | 6 |
17 files changed, 0 insertions, 931 deletions
diff --git a/build/cleaners/player.js b/build/cleaners/player.js deleted file mode 100644 index 214be1f..0000000 --- a/build/cleaners/player.js +++ /dev/null @@ -1,17 +0,0 @@ -import { cleanPlayerSkyblockProfiles } from './skyblock/profiles.js'; -import { cleanSocialMedia } from './socialmedia.js'; -import { cleanRank } from './rank.js'; -import { undashUuid } from '../util.js'; -export async function cleanPlayerResponse(data) { - // Cleans up a 'player' api response - if (!data) - return null; // bruh - return { - uuid: undashUuid(data.uuid), - username: data.displayname, - rank: cleanRank(data), - socials: cleanSocialMedia(data), - // first_join: data.firstLogin / 1000, - profiles: cleanPlayerSkyblockProfiles(data.stats?.SkyBlock?.profiles) - }; -} diff --git a/build/cleaners/rank.js b/build/cleaners/rank.js deleted file mode 100644 index 1d80d2c..0000000 --- a/build/cleaners/rank.js +++ /dev/null @@ -1,81 +0,0 @@ -import { colorCodeFromName, minecraftColorCodes } from '../util.js'; -const rankColors = { - 'NONE': '7', - 'VIP': 'a', - 'VIP+': 'a', - 'MVP': 'b', - 'MVP+': 'b', - 'MVP++': '6', - 'YOUTUBE': 'c', - 'HELPER': '9', - 'MOD': '2', - 'GM': '2', - 'ADMIN': 'c' -}; -/** Response cleaning (reformatting to be nicer) */ -export function cleanRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusColor, rank, prefix }) { - let name; - let color; - let colored; - let bracketColor; - if (prefix) { // derive values from prefix - colored = prefix; - color = minecraftColorCodes[colored.match(/§./)[0][1]]; - name = colored.replace(/§./g, '').replace(/[\[\]]/g, ''); - } - else { - if (monthlyPackageRank && monthlyPackageRank !== 'NONE') - name = monthlyPackageRank; - else if (rank && rank !== 'NORMAL') - name = rank; - else - name = newPackageRank?.replace('_PLUS', '+') - ?? packageRank?.replace('_PLUS', '+'); - switch (name) { - // MVP++ is called Superstar for some reason - case 'SUPERSTAR': - name = 'MVP++'; - break; - // YouTube rank is called YouTuber, change this to the proper name - case 'YOUTUBER': - name = 'YOUTUBE'; - bracketColor = 'c'; - break; - case 'GAME_MASTER': - name = 'GM'; - break; - case 'MODERATOR': - name = 'MOD'; - break; - case undefined: - name = 'NONE'; - break; - } - const plusColor = rankPlusColor ? colorCodeFromName(rankPlusColor) : null; - color = minecraftColorCodes[rankColors[name]]; - let rankColorPrefix = rankColors[name] ? '§' + rankColors[name] : ''; - // the text is white, but only in the prefix - if (name === 'YOUTUBE') - rankColorPrefix = '§f'; - const nameWithoutPlus = name.split('+')[0]; - const plusesInName = '+'.repeat(name.split('+').length - 1); - if (plusColor && plusesInName.length >= 1) - if (bracketColor) - colored = `§${bracketColor}[${rankColorPrefix}${nameWithoutPlus}§${plusColor}${plusesInName}${rankColorPrefix}§${bracketColor}]`; - else - colored = `${rankColorPrefix}[${nameWithoutPlus}§${plusColor}${plusesInName}${rankColorPrefix}]`; - else if (name !== 'NONE') - if (bracketColor) - colored = `§${bracketColor}[${rankColorPrefix}${name}§${bracketColor}]`; - else - colored = `${rankColorPrefix}[${name}]`; - else - // nons don't have a prefix - colored = `${rankColorPrefix}`; - } - return { - name, - color, - colored - }; -} diff --git a/build/cleaners/skyblock/bank.js b/build/cleaners/skyblock/bank.js deleted file mode 100644 index fb08af5..0000000 --- a/build/cleaners/skyblock/bank.js +++ /dev/null @@ -1,8 +0,0 @@ -export function cleanBank(data) { - return { - balance: data?.banking?.balance ?? 0, - // TODO: make transactions good - // history: data?.banking?.transactions ?? [] - history: [] - }; -} diff --git a/build/cleaners/skyblock/collections.js b/build/cleaners/skyblock/collections.js deleted file mode 100644 index 4a5b34e..0000000 --- a/build/cleaners/skyblock/collections.js +++ /dev/null @@ -1,116 +0,0 @@ -import { cleanItemId } from './itemId.js'; -const COLLECTIONS = { - 'farming': [ - 'wheat', - 'carrot', - 'potato', - 'pumpkin', - 'melon_slice', - 'wheat_seeds', - 'red_mushroom', - 'cocoa_beans', - 'cactus', - 'sugar_cane', - 'feather', - 'leather', - 'porkchop', - 'chicken', - 'mutton', - 'rabbit', - 'nether_wart' - ], - 'mining': [ - 'cobblestone', - 'coal', - 'iron_ingot', - 'gold_ingot', - 'diamond', - 'lapis_lazuli', - 'emerald', - 'redstone', - 'quartz', - 'obsidian', - 'glowstone_dust', - 'gravel', - 'ice', - 'netherrack', - 'sand', - 'end_stone' - ], - 'combat': [ - 'rotten_flesh', - 'bone', - 'string', - 'spider_eye', - 'gunpowder', - 'ender_pearl', - 'ghast_tear', - 'slime_ball', - 'blaze_rod', - 'magma_cream' - ], - 'foraging': [ - 'oak_log', - 'spruce_log', - 'birch_log', - 'jungle_log', - 'acacia_log', - 'dark_oak_log' - ], - 'fishing': [ - 'cod', - 'salmon', - 'tropical_fish', - 'pufferfish', - 'prismarine_shard', - 'prismarine_crystals', - 'clay_ball', - 'lily_pad', - 'ink_sac', - 'sponge' - ], - // no item should be here, but in case a new collection is added itll default to this - 'unknown': [] -}; -// get a category name (farming) from a collection name (wheat) -function getCategory(collectionName) { - for (const categoryName in COLLECTIONS) { - const categoryItems = COLLECTIONS[categoryName]; - if (categoryItems.includes(collectionName)) - return categoryName; - } -} -export function cleanCollections(data) { - // collection tiers show up like this: [ GRAVEL_3, GOLD_INGOT_2, MELON_-1, LOG_2:1_7, RAW_FISH:3_-1] - // these tiers are the same for all players in a coop - const playerCollectionTiersRaw = data?.unlocked_coll_tiers ?? []; - const playerCollectionTiers = {}; - for (const collectionTierNameValueRaw of playerCollectionTiersRaw) { - const [collectionTierNameRaw, collectionTierValueRaw] = collectionTierNameValueRaw.split(/_(?=-?\d+$)/); - const collectionName = cleanItemId(collectionTierNameRaw); - // ensure it's at least 0 - const collectionValue = Math.max(parseInt(collectionTierValueRaw), 0); - // if the collection hasn't been checked yet, or the new value is higher than the old, replace it - if (!playerCollectionTiers[collectionName] || collectionValue > playerCollectionTiers[collectionName]) - playerCollectionTiers[collectionName] = collectionValue; - } - // collection names show up like this: { LOG: 49789, LOG:2: 26219, MUSHROOM_COLLECTION: 2923} - // these values are different for each player in a coop - const playerCollectionXpsRaw = data?.collection ?? {}; - const playerCollections = []; - for (const collectionNameRaw in playerCollectionXpsRaw) { - const collectionXp = playerCollectionXpsRaw[collectionNameRaw]; - const collectionName = cleanItemId(collectionNameRaw); - const collectionLevel = playerCollectionTiers[collectionName]; - const collectionCategory = getCategory(collectionName) ?? 'unknown'; - // in some very weird cases the collection level will be undefined, we should ignore these collections - if (collectionLevel !== undefined) - playerCollections.push({ - name: collectionName, - xp: collectionXp, - level: collectionLevel, - category: collectionCategory - }); - } - return playerCollections; -} diff --git a/build/cleaners/skyblock/fairysouls.js b/build/cleaners/skyblock/fairysouls.js deleted file mode 100644 index 8ec8078..0000000 --- a/build/cleaners/skyblock/fairysouls.js +++ /dev/null @@ -1,7 +0,0 @@ -export function cleanFairySouls(data) { - return { - total: data?.fairy_souls_collected ?? 0, - unexchanged: data?.fairy_souls ?? 0, - exchanges: data?.fairy_exchanges ?? 0, - }; -} diff --git a/build/cleaners/skyblock/inventory.js b/build/cleaners/skyblock/inventory.js deleted file mode 100644 index 714a302..0000000 --- a/build/cleaners/skyblock/inventory.js +++ /dev/null @@ -1,83 +0,0 @@ -// maybe todo?: create a fast replacement for prismarine-nbt -import * as nbt from 'prismarine-nbt'; -function base64decode(base64) { - return Buffer.from(base64, 'base64'); -} -function cleanItem(rawItem) { - // if the item doesn't have an id, it isn't an item - if (rawItem.id === undefined) - return null; - const vanillaId = rawItem.id; - const itemCount = rawItem.Count; - const damageValue = rawItem.Damage; - const itemTag = rawItem.tag; - const extraAttributes = itemTag?.ExtraAttributes ?? {}; - let headId; - if (vanillaId === 397) { - const headDataBase64 = itemTag?.SkullOwner?.Properties?.textures?.[0]?.Value; - if (headDataBase64) { - const headData = JSON.parse(base64decode(headDataBase64).toString()); - const headDataUrl = headData?.textures?.SKIN?.url; - if (headDataUrl) { - const splitUrl = headDataUrl.split('/'); - headId = splitUrl[splitUrl.length - 1]; - } - } - } - return { - id: extraAttributes?.id ?? null, - count: itemCount ?? 1, - vanillaId: damageValue ? `${vanillaId}:${damageValue}` : vanillaId.toString(), - display: { - name: itemTag?.display?.Name ?? 'null', - lore: itemTag?.display?.Lore ?? [], - // if it has an ench value in the tag, then it should have an enchant glint effect - glint: (itemTag?.ench ?? []).length > 0 - }, - reforge: extraAttributes?.modifier, - enchantments: extraAttributes?.enchantments, - anvil_uses: extraAttributes?.anvil_uses, - timestamp: extraAttributes?.timestamp, - head_texture: headId, - }; -} -function cleanItems(rawItems) { - return rawItems.map(cleanItem); -} -export function cleanInventory(encodedNbt) { - return new Promise(resolve => { - const base64Data = base64decode(encodedNbt); - nbt.parse(base64Data, false, (err, value) => { - const simplifiedNbt = nbt.simplify(value); - // do some basic cleaning on the items and return - resolve(cleanItems(simplifiedNbt.i)); - }); - }); -} -export const INVENTORIES = { - armor: 'inv_armor', - inventory: 'inv_contents', - ender_chest: 'ender_chest_contents', - talisman_bag: 'talisman_bag', - potion_bag: 'potion_bag', - fishing_bag: 'fishing_bag', - quiver: 'quiver', - trick_or_treat_bag: 'candy_inventory_contents', - wardrobe: 'wardrobe_contents' -}; -export async function cleanInventories(data) { - const cleanInventories = {}; - for (const cleanInventoryName in INVENTORIES) { - const hypixelInventoryName = INVENTORIES[cleanInventoryName]; - const encodedInventoryContents = data[hypixelInventoryName]?.data; - let inventoryContents; - if (encodedInventoryContents) { - inventoryContents = await cleanInventory(encodedInventoryContents); - if (cleanInventoryName === 'armor') - // the armor is sent from boots to head, the opposite makes more sense - inventoryContents.reverse(); - cleanInventories[cleanInventoryName] = inventoryContents; - } - } - return cleanInventories; -} diff --git a/build/cleaners/skyblock/itemId.js b/build/cleaners/skyblock/itemId.js deleted file mode 100644 index ea94771..0000000 --- a/build/cleaners/skyblock/itemId.js +++ /dev/null @@ -1,57 +0,0 @@ -// change weird item names to be more consistent with vanilla -const ITEMS = { - 'log': 'oak_log', - 'log:1': 'spruce_log', - 'log:2': 'birch_log', - 'log:3': 'jungle_log', - 'log_2': 'acacia_log', - 'log_2:1': 'dark_oak_log', - 'ink_sack': 'ink_sac', - 'ink_sack:3': 'cocoa_beans', - 'ink_sack:4': 'lapis_lazuli', - 'cocoa': 'cocoa_beans', - 'raw_fish': 'cod', - 'raw_fish:1': 'salmon', - 'raw_fish:2': 'tropical_fish', - 'raw_fish:3': 'pufferfish', - 'raw_salmon': 'salmon', - 'cooked_fish': 'cooked_cod', - 'seeds': 'wheat_seeds', - 'sulphur': 'gunpowder', - 'raw_chicken': 'chicken', - 'pork': 'porkchop', - 'potato_item': 'potato', - 'carrot_item': 'carrot', - 'mushroom_collection': 'red_mushroom', - 'nether_stalk': 'nether_wart', - 'water_lily': 'lily_pad', - 'melon': 'melon_slice', - 'ender_stone': 'end_stone', - 'huge_mushroom_1': 'red_mushroom_block', - 'huge_mushroom_2': 'brown_mushroom_block', - 'iron_ingot': 'iron_ingot', - 'iron': 'iron_ingot', - 'gold': 'gold_ingot', - 'endstone': 'end_stone', - 'lapis_lazuli_block': 'lapis_block', - 'snow_ball': 'snowball', - 'raw_beef': 'beef', - 'eye_of_ender': 'ender_eye', - 'grilled_pork': 'cooked_porkchop', - 'glistering_melon': 'glistering_melon_slice', - 'cactus_green': 'green_dye', - 'enchanted_lapis_lazuli': 'enchanted_lapis_lazuli', - 'enchanted_potato': 'enchanted_potato', - 'enchanted_birch_log': 'enchanted_birch_log', - 'enchanted_gunpowder': 'enchanted_gunpowder', - 'enchanted_raw_salmon': 'enchanted_salmon', - 'enchanted_raw_chicken': 'enchanted_chicken', - 'enchanted_water_lily': 'enchanted_lily_pad', - 'enchanted_ink_sack': 'enchanted_ink_sac', - 'enchanted_melon': 'enchanted_melon_slice', - 'enchanted_glistering_melon': 'enchanted_glistering_melon_slice' -}; -/** Clean an item with a weird name (log_2:1) and make it have a better name (dark_oak_log) */ -export function cleanItemId(itemId) { - return ITEMS[itemId.toLowerCase()] ?? itemId.toLowerCase(); -} diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js deleted file mode 100644 index 3a6a143..0000000 --- a/build/cleaners/skyblock/member.js +++ /dev/null @@ -1,54 +0,0 @@ -import { cleanCollections } from './collections.js'; -import { cleanInventories } from './inventory.js'; -import { cleanFairySouls } from './fairysouls.js'; -import { cleanObjectives } from './objectives.js'; -import { cleanProfileStats } from './stats.js'; -import { cleanMinions } from './minions.js'; -import { cleanSlayers } from './slayers.js'; -import { cleanVisitedZones } from './zones.js'; -import { cleanSkills } from './skills.js'; -import * as cached from '../../hypixelCached.js'; -import * as constants from '../../constants.js'; -export async function cleanSkyBlockProfileMemberResponseBasic(member) { - const player = await cached.fetchPlayer(member.uuid); - if (!player) - return null; - return { - uuid: member.uuid, - username: player.username, - last_save: member.last_save / 1000, - first_join: member.first_join / 1000, - rank: player.rank - }; -} -/** Cleans up a member (from skyblock/profile) */ -export async function cleanSkyBlockProfileMemberResponse(member, included = undefined) { - // profiles.members[] - const inventoriesIncluded = included === undefined || included.includes('inventories'); - const player = await cached.fetchPlayer(member.uuid); - if (!player) - return null; - const fairySouls = cleanFairySouls(member); - const { max_fairy_souls: maxFairySouls } = await constants.fetchConstantValues(); - if (fairySouls.total > (maxFairySouls ?? 0)) - await constants.setConstantValues({ max_fairy_souls: fairySouls.total }); - return { - uuid: member.uuid, - username: player.username, - last_save: member.last_save / 1000, - first_join: member.first_join / 1000, - rank: player.rank, - purse: member.coin_purse, - stats: cleanProfileStats(member), - // this is used for leaderboards - rawHypixelStats: member.stats ?? {}, - minions: await cleanMinions(member), - fairy_souls: fairySouls, - inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, - objectives: cleanObjectives(member), - skills: await cleanSkills(member), - visited_zones: await cleanVisitedZones(member), - collections: cleanCollections(member), - slayers: cleanSlayers(member) - }; -} diff --git a/build/cleaners/skyblock/minions.js b/build/cleaners/skyblock/minions.js deleted file mode 100644 index 5c0bd9a..0000000 --- a/build/cleaners/skyblock/minions.js +++ /dev/null @@ -1,85 +0,0 @@ -import { maxMinion } from '../../hypixel.js'; -import * as constants from '../../constants.js'; -/** - * Clean the minions provided by Hypixel - * @param minionsRaw The minion data provided by the Hypixel API - */ -export async function cleanMinions(member) { - const minions = []; - const processedMinionNames = 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(); - const minionLevel = parseInt(minionRaw.split(/\D*_/)[1]); - let matchingMinion = minions.find(m => m.name === minionName); - if (!matchingMinion) { - // if the minion doesnt already exist in the minions array, then create it - matchingMinion = { - name: minionName, - levels: new Array(maxMinion).fill(false) - }; - minions.push(matchingMinion); - } - while (minionLevel > matchingMinion.levels.length) - // if hypixel increases the minion level, this will increase with it - matchingMinion.levels.push(false); - // 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; - } - } - 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)); -} -/** - * Combine multiple arrays of minions into one, useful when getting the minions for members - * @param minions An array of arrays of minions - */ -export function combineMinionArrays(minions) { - const resultMinions = []; - for (const memberMinions of minions) { - for (const minion of memberMinions) { - // this is a reference, so we can directly modify the attributes for matchingMinionReference - // and they'll be in the resultMinions array - const matchingMinionReference = resultMinions.find(m => m.name === minion.name); - if (!matchingMinionReference) { - // if the minion name isn't already in the array, add it! - resultMinions.push(minion); - } - else { - // This should never happen, but in case the length of `minion.levels` is longer than - // `matchingMinionReference.levels`, then it should be extended to be equal length - while (matchingMinionReference.levels.length < minion.levels.length) - matchingMinionReference.levels.push(false); - for (let i = 0; i < minion.levels.length; i++) { - if (minion.levels[i]) - matchingMinionReference.levels[i] = true; - } - } - } - } - return resultMinions; -} -export function countUniqueMinions(minions) { - let uniqueMinions = 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/build/cleaners/skyblock/objectives.js b/build/cleaners/skyblock/objectives.js deleted file mode 100644 index 52e92db..0000000 --- a/build/cleaners/skyblock/objectives.js +++ /dev/null @@ -1,12 +0,0 @@ -export function cleanObjectives(data) { - const rawObjectives = data?.objectives || {}; - const objectives = []; - for (const rawObjectiveName in rawObjectives) { - const rawObjectiveValue = rawObjectives[rawObjectiveName]; - objectives.push({ - name: rawObjectiveName, - completed: rawObjectiveValue.status === 'COMPLETE', - }); - } - return objectives; -} diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js deleted file mode 100644 index 42e26b3..0000000 --- a/build/cleaners/skyblock/profile.js +++ /dev/null @@ -1,64 +0,0 @@ -import { cleanSkyBlockProfileMemberResponse, cleanSkyBlockProfileMemberResponseBasic } from './member.js'; -import { combineMinionArrays, countUniqueMinions } from './minions.js'; -import * as constants from '../../constants.js'; -import { cleanBank } from './bank.js'; -/** 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) { - // We use Promise.all so it can fetch all the usernames at once instead of waiting for the previous promise to complete - const promises = []; - 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(cleanSkyBlockProfileMemberResponseBasic(memberRaw)); - } - const cleanedMembers = (await Promise.all(promises)).filter(m => m); - return { - uuid: data.profile_id, - name: data.cute_name, - members: cleanedMembers, - }; -} -/** - * This function is somewhat costly and shouldn't be called often. Use cleanSkyblockProfileResponseLighter if you don't need all the data - */ -export async function cleanSkyblockProfileResponse(data, options) { - // We use Promise.all so it can fetch all the users at once instead of waiting for the previous promise to complete - const promises = []; - if (!data) - return null; - for (const memberUUID in data.members) { - const memberRaw = data.members[memberUUID]; - memberRaw.uuid = memberUUID; - promises.push(cleanSkyBlockProfileMemberResponse(memberRaw, [ - !options?.basic ? 'stats' : undefined, - options?.mainMemberUuid === memberUUID ? 'inventories' : undefined - ])); - } - const cleanedMembers = (await Promise.all(promises)).filter(m => m !== null && m !== undefined); - if (options?.basic) { - return { - uuid: data.profile_id, - name: data.cute_name, - members: cleanedMembers, - }; - } - const memberMinions = []; - for (const member of cleanedMembers) { - memberMinions.push(member.minions); - } - const minions = combineMinionArrays(memberMinions); - const { max_minions: maxUniqueMinions } = await constants.fetchConstantValues(); - const uniqueMinions = countUniqueMinions(minions); - if (uniqueMinions > (maxUniqueMinions ?? 0)) - await constants.setConstantValues({ max_minions: uniqueMinions }); - // return more detailed info - return { - uuid: data.profile_id, - name: data.cute_name, - members: cleanedMembers, - bank: cleanBank(data), - minions: minions, - minion_count: uniqueMinions - }; -} diff --git a/build/cleaners/skyblock/profiles.js b/build/cleaners/skyblock/profiles.js deleted file mode 100644 index a85b1f3..0000000 --- a/build/cleaners/skyblock/profiles.js +++ /dev/null @@ -1,21 +0,0 @@ -import { cleanSkyblockProfileResponse } from './profile.js'; -export function cleanPlayerSkyblockProfiles(rawProfiles) { - let profiles = []; - for (const profile of Object.values(rawProfiles ?? {})) { - profiles.push({ - uuid: profile.profile_id, - name: profile.cute_name - }); - } - return profiles; -} -/** Convert an array of raw profiles into clean profiles */ -export async function cleanSkyblockProfilesResponse(data) { - const promises = []; - for (const profile of data ?? []) { - // let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile) - promises.push(cleanSkyblockProfileResponse(profile)); - } - const cleanedProfiles = (await Promise.all(promises)).filter(p => p); - return cleanedProfiles; -} diff --git a/build/cleaners/skyblock/skills.js b/build/cleaners/skyblock/skills.js deleted file mode 100644 index e9b19f8..0000000 --- a/build/cleaners/skyblock/skills.js +++ /dev/null @@ -1,146 +0,0 @@ -// the highest level you can have in each skill -// numbers taken from https://hypixel-skyblock.fandom.com/wiki/Skills -const skillsMaxLevel = { - farming: 60, - mining: 60, - combat: 60, - foraging: 50, - fishing: 50, - enchanting: 60, - alchemy: 50, - taming: 50, - dungeoneering: 50, - carpentry: 50, - runecrafting: 25, - social: 25 -}; -const skillXpTable = [ - 50, - 175, - 375, - 675, - 1175, - 1925, - 2925, - 4425, - 6425, - 9925, - 14925, - 22425, - 32425, - 47425, - 67425, - 97425, - 147425, - 222425, - 322425, - 522425, - 822425, - 1222425, - 1722425, - 2322425, - 3022425, - 3822425, - 4722425, - 5722425, - 6822425, - 8022425, - 9322425, - 10722425, - 12222425, - 13822425, - 15522425, - 17322425, - 19222425, - 21222425, - 23322425, - 25522425, - 27822425, - 30222425, - 32722425, - 35322425, - 38072425, - 40972425, - 44072425, - 47472425, - 51172425, - 55172425, - 59472425, - 64072425, - 68972425, - 74172425, - 79672425, - 85472425, - 91572425, - 97972425, - 104672425, - 111672425 // 60 -]; -const skillXpTableEasier = [ - 50, - 150, - 275, - 435, - 635, - 885, - 1200, - 1600, - 2100, - 2725, - 3510, - 4510, - 5760, - 7325, - 9325, - 11825, - 14950, - 18950, - 23950, - 30200, - 38050, - 47850, - 60100, - 75400, - 94450 // 25 -]; -// for skills that aren't in maxSkills, default to this -const skillsDefaultMaxLevel = 50; -/** - * Get the skill level for the amount of total xp - * @param xp The xp we're finding the level for - * @param easierLevel Whether it should use the alternate leveling xp table (used for cosmetic skills and dungeoneering) - */ -export function levelForSkillXp(xp, maxLevel) { - const xpTable = (maxLevel <= 25 ? skillXpTableEasier : skillXpTable).slice(0, maxLevel); - const skillLevel = [...xpTable].reverse().findIndex(levelXp => xp >= levelXp); - return skillLevel === -1 ? 0 : xpTable.length - skillLevel; -} -export async function cleanSkills(data) { - const skills = []; - for (const item in data) { - if (item.startsWith('experience_skill_')) { - const skillName = item.substr('experience_skill_'.length); - // the amount of total xp you have in this skill - const skillXp = data[item]; - const skillMaxLevel = skillsMaxLevel[skillName] ?? skillsDefaultMaxLevel; - const xpTable = (skillMaxLevel <= 25 ? skillXpTableEasier : skillXpTable).slice(0, skillMaxLevel); - // the level you're at for this skill - const skillLevel = levelForSkillXp(skillXp, skillMaxLevel); - // the total xp required for the previous level - const previousLevelXp = skillLevel >= 1 ? xpTable[skillLevel - 1] : 0; - // the extra xp left over - const skillLevelXp = skillXp - previousLevelXp; - // the amount of extra xp required for this level - const skillLevelXpRequired = xpTable[skillLevel] - previousLevelXp; - skills.push({ - name: skillName, - xp: skillXp, - level: skillLevel, - maxLevel: skillMaxLevel, - levelXp: skillLevelXp, - levelXpRequired: skillLevelXpRequired - }); - } - } - return skills; -} diff --git a/build/cleaners/skyblock/slayers.js b/build/cleaners/skyblock/slayers.js deleted file mode 100644 index 75894f7..0000000 --- a/build/cleaners/skyblock/slayers.js +++ /dev/null @@ -1,60 +0,0 @@ -export const slayerLevels = 5; -const SLAYER_NAMES = { - spider: 'tarantula', - zombie: 'revenant', - wolf: 'sven' -}; -export function cleanSlayers(data) { - const slayers = []; - const slayersDataRaw = data?.slayer_bosses; - let totalXp = 0; - let totalKills = 0; - for (const slayerNameRaw in slayersDataRaw) { - const slayerDataRaw = slayersDataRaw[slayerNameRaw]; - // convert name provided by api (spider) to the real name (tarantula) - const slayerName = SLAYER_NAMES[slayerNameRaw]; - const slayerXp = slayerDataRaw.xp ?? 0; - let slayerKills = 0; - const slayerTiers = []; - for (const slayerDataKey in slayerDataRaw) { - // if a key starts with boss_kills_tier_ (boss_kills_tier_1), get the last number - if (slayerDataKey.startsWith('boss_kills_tier_')) { - const slayerTierRaw = parseInt(slayerDataKey.substr('boss_kills_tier_'.length)); - const slayerTierKills = slayerDataRaw[slayerDataKey] ?? 0; - // add 1 since hypixel is using 0 indexed tiers - const slayerTier = slayerTierRaw + 1; - slayerTiers.push({ - kills: slayerTierKills, - tier: slayerTier - }); - // count up the total number of kills for this slayer - if (slayerTierKills) - slayerKills += slayerTierKills; - } - } - // if the slayer tier length is less than the max, add more empty ones - while (slayerTiers.length < slayerLevels) - slayerTiers.push({ - tier: slayerTiers.length + 1, - kills: 0 - }); - const slayer = { - name: slayerName, - raw_name: slayerNameRaw, - tiers: slayerTiers, - xp: slayerXp ?? 0, - kills: slayerKills - }; - slayers.push(slayer); - // add the xp and kills from this slayer to the total xp - if (slayerXp) - totalXp += slayerXp; - if (slayerKills) - totalKills += slayerKills; - } - return { - xp: totalXp, - kills: totalKills, - bosses: slayers - }; -} diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js deleted file mode 100644 index 361f1ba..0000000 --- a/build/cleaners/skyblock/stats.js +++ /dev/null @@ -1,91 +0,0 @@ -const statCategories = { - 'deaths': ['deaths_', 'deaths'], - 'kills': ['kills_', 'kills'], - 'fishing': ['items_fished_', 'items_fished', 'shredder_'], - 'auctions': ['auctions_'], - 'races': ['_best_time', '_best_time_2'], - 'mythos': ['mythos_burrows_', 'mythos_kills'], - 'collection': ['collection_'], - 'skills': ['skill_'], - 'slayer': ['slayer_'], - 'misc': null // everything else goes here -}; -export function categorizeStat(statNameRaw) { - // 'deaths_void' - for (const statCategory in statCategories) { - // 'deaths' - const statCategoryMatchers = statCategories[statCategory]; - if (statCategoryMatchers == null) { - // If it's null, just go with this. Can only ever be 'misc' - return { - category: statCategory, - name: statNameRaw - }; - } - for (const categoryMatch of statCategoryMatchers) { - // ['deaths_'] - let trailingEnd = categoryMatch[0] === '_'; - let trailingStart = categoryMatch.substr(-1) === '_'; - if (trailingStart && statNameRaw.startsWith(categoryMatch)) { - return { - category: statCategory, - name: statNameRaw.substr(categoryMatch.length) - }; - } - else if (trailingEnd && statNameRaw.endsWith(categoryMatch)) { - return { - category: statCategory, - name: statNameRaw.substr(0, statNameRaw.length - categoryMatch.length) - }; - } - else if (statNameRaw == categoryMatch) { - // if it matches exactly, we don't know the name. will be defaulted to category later on - return { - category: statCategory, - name: null - }; - } - } - } - // this should never happen, as it'll default to misc and return if nothing is found - return { - category: null, - name: statNameRaw - }; -} -export const statUnits = { - time: ['_best_time', '_best_time_2'], - date: ['first_join'], - coins: ['purse'], - leaderboards: ['leaderboards_count', 'top_1_leaderboards_count'] -}; -export function getStatUnit(name) { - for (const [unitName, statMatchers] of Object.entries(statUnits)) { - for (const statMatch of statMatchers) { - let trailingEnd = statMatch[0] === '_'; - let trailingStart = statMatch.substr(-1) === '_'; - if ((trailingStart && name.startsWith(statMatch)) - || (trailingEnd && name.endsWith(statMatch)) - || (name == statMatch)) - return unitName; - } - } - return null; -} -export function cleanProfileStats(data) { - // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there) - const stats = []; - const rawStats = data?.stats ?? {}; - for (const statNameRaw in rawStats) { - const statValue = rawStats[statNameRaw]; - let { category: statCategory, name: statName } = categorizeStat(statNameRaw); - stats.push({ - categorizedName: statName ?? 'total', - value: statValue, - rawName: statNameRaw, - category: statCategory, - unit: getStatUnit(statNameRaw) ?? null - }); - } - return stats; -} diff --git a/build/cleaners/skyblock/zones.js b/build/cleaners/skyblock/zones.js deleted file mode 100644 index 90c689b..0000000 --- a/build/cleaners/skyblock/zones.js +++ /dev/null @@ -1,23 +0,0 @@ -import * as constants from '../../constants.js'; -export async function cleanVisitedZones(data) { - const rawZones = data?.visited_zones || []; - // TODO: store all the zones that exist in SkyBlock, add add those to the array with visited being false - const zones = []; - const knownZones = await constants.fetchZones(); - for (const rawZoneName of knownZones) { - zones.push({ - name: rawZoneName, - visited: rawZones.includes(rawZoneName) - }); - } - // if this user somehow has a zone that we don't know about, just add it to zones - for (const rawZoneName of rawZones) { - if (!knownZones.includes(rawZoneName)) { - zones.push({ - name: rawZoneName, - visited: true - }); - } - } - return zones; -} diff --git a/build/cleaners/socialmedia.js b/build/cleaners/socialmedia.js deleted file mode 100644 index c901725..0000000 --- a/build/cleaners/socialmedia.js +++ /dev/null @@ -1,6 +0,0 @@ -export function cleanSocialMedia(data) { - return { - discord: data?.socialMedia?.links?.DISCORD || null, - forums: data?.socialMedia?.links?.HYPIXEL || null - }; -} |