diff options
author | dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> | 2021-09-06 21:06:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-06 21:06:22 +0000 |
commit | 487f208565894f332ca58c13e1b208c3beb9c8c6 (patch) | |
tree | b3209e94cc63658b5430bc1949b80140cc27efe4 /build/cleaners | |
parent | 4f03cb71b30978b277ff292dbddeba182117a7cb (diff) | |
download | skyblock-api-487f208565894f332ca58c13e1b208c3beb9c8c6.tar.gz skyblock-api-487f208565894f332ca58c13e1b208c3beb9c8c6.tar.bz2 skyblock-api-487f208565894f332ca58c13e1b208c3beb9c8c6.zip |
Bump node-fetch from 2.6.1 to 3.0.0 (#116)
* Bump node-fetch from 2.6.1 to 3.0.0
Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.1 to 3.0.0.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/node-fetch/node-fetch/compare/v2.6.1...v3.0.0)
---
updated-dependencies:
- dependency-name: node-fetch
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* fix issues with node fetch 3.0
* change module to esnext instead of commonjs
* fix imports and tests
* fix package-lock.json
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: mat <github@matdoes.dev>
Co-authored-by: mat <27899617+mat-1@users.noreply.github.com>
Diffstat (limited to 'build/cleaners')
-rw-r--r-- | build/cleaners/player.js | 23 | ||||
-rw-r--r-- | build/cleaners/rank.js | 18 | ||||
-rw-r--r-- | build/cleaners/skyblock/bank.js | 9 | ||||
-rw-r--r-- | build/cleaners/skyblock/collections.js | 19 | ||||
-rw-r--r-- | build/cleaners/skyblock/fairysouls.js | 13 | ||||
-rw-r--r-- | build/cleaners/skyblock/inventory.js | 64 | ||||
-rw-r--r-- | build/cleaners/skyblock/itemId.js | 9 | ||||
-rw-r--r-- | build/cleaners/skyblock/member.js | 73 | ||||
-rw-r--r-- | build/cleaners/skyblock/minions.js | 42 | ||||
-rw-r--r-- | build/cleaners/skyblock/objectives.js | 8 | ||||
-rw-r--r-- | build/cleaners/skyblock/profile.js | 54 | ||||
-rw-r--r-- | build/cleaners/skyblock/profiles.js | 17 | ||||
-rw-r--r-- | build/cleaners/skyblock/skills.js | 12 | ||||
-rw-r--r-- | build/cleaners/skyblock/slayers.js | 19 | ||||
-rw-r--r-- | build/cleaners/skyblock/stats.js | 23 | ||||
-rw-r--r-- | build/cleaners/skyblock/zones.js | 8 | ||||
-rw-r--r-- | build/cleaners/socialmedia.js | 11 |
17 files changed, 128 insertions, 294 deletions
diff --git a/build/cleaners/player.js b/build/cleaners/player.js index 42c76b8..214be1f 100644 --- a/build/cleaners/player.js +++ b/build/cleaners/player.js @@ -1,22 +1,17 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanPlayerResponse = void 0; -const profiles_1 = require("./skyblock/profiles"); -const socialmedia_1 = require("./socialmedia"); -const rank_1 = require("./rank"); -const util_1 = require("../util"); -async function cleanPlayerResponse(data) { - var _a, _b; +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: util_1.undashUuid(data.uuid), + uuid: undashUuid(data.uuid), username: data.displayname, - rank: rank_1.cleanRank(data), - socials: socialmedia_1.cleanSocialMedia(data), + rank: cleanRank(data), + socials: cleanSocialMedia(data), // first_join: data.firstLogin / 1000, - profiles: profiles_1.cleanPlayerSkyblockProfiles((_b = (_a = data.stats) === null || _a === void 0 ? void 0 : _a.SkyBlock) === null || _b === void 0 ? void 0 : _b.profiles) + profiles: cleanPlayerSkyblockProfiles(data.stats?.SkyBlock?.profiles) }; } -exports.cleanPlayerResponse = cleanPlayerResponse; diff --git a/build/cleaners/rank.js b/build/cleaners/rank.js index 19e4938..1d80d2c 100644 --- a/build/cleaners/rank.js +++ b/build/cleaners/rank.js @@ -1,7 +1,4 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanRank = void 0; -const util_1 = require("../util"); +import { colorCodeFromName, minecraftColorCodes } from '../util.js'; const rankColors = { 'NONE': '7', 'VIP': 'a', @@ -16,15 +13,14 @@ const rankColors = { 'ADMIN': 'c' }; /** Response cleaning (reformatting to be nicer) */ -function cleanRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusColor, rank, prefix }) { - var _a; +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 = util_1.minecraftColorCodes[colored.match(/§./)[0][1]]; + color = minecraftColorCodes[colored.match(/§./)[0][1]]; name = colored.replace(/§./g, '').replace(/[\[\]]/g, ''); } else { @@ -33,7 +29,8 @@ function cleanRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusCo else if (rank && rank !== 'NORMAL') name = rank; else - name = (_a = newPackageRank === null || newPackageRank === void 0 ? void 0 : newPackageRank.replace('_PLUS', '+')) !== null && _a !== void 0 ? _a : packageRank === null || packageRank === void 0 ? void 0 : packageRank.replace('_PLUS', '+'); + name = newPackageRank?.replace('_PLUS', '+') + ?? packageRank?.replace('_PLUS', '+'); switch (name) { // MVP++ is called Superstar for some reason case 'SUPERSTAR': @@ -54,8 +51,8 @@ function cleanRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusCo name = 'NONE'; break; } - const plusColor = rankPlusColor ? util_1.colorCodeFromName(rankPlusColor) : null; - color = util_1.minecraftColorCodes[rankColors[name]]; + 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') @@ -82,4 +79,3 @@ function cleanRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusCo colored }; } -exports.cleanRank = cleanRank; diff --git a/build/cleaners/skyblock/bank.js b/build/cleaners/skyblock/bank.js index 9836685..fb08af5 100644 --- a/build/cleaners/skyblock/bank.js +++ b/build/cleaners/skyblock/bank.js @@ -1,13 +1,8 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanBank = void 0; -function cleanBank(data) { - var _a, _b; +export function cleanBank(data) { return { - balance: (_b = (_a = data === null || data === void 0 ? void 0 : data.banking) === null || _a === void 0 ? void 0 : _a.balance) !== null && _b !== void 0 ? _b : 0, + balance: data?.banking?.balance ?? 0, // TODO: make transactions good // history: data?.banking?.transactions ?? [] history: [] }; } -exports.cleanBank = cleanBank; diff --git a/build/cleaners/skyblock/collections.js b/build/cleaners/skyblock/collections.js index 0bb4cb5..4a5b34e 100644 --- a/build/cleaners/skyblock/collections.js +++ b/build/cleaners/skyblock/collections.js @@ -1,7 +1,4 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanCollections = void 0; -const itemId_1 = require("./itemId"); +import { cleanItemId } from './itemId.js'; const COLLECTIONS = { 'farming': [ 'wheat', @@ -83,15 +80,14 @@ function getCategory(collectionName) { return categoryName; } } -function cleanCollections(data) { - var _a, _b, _c; +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 = (_a = data === null || data === void 0 ? void 0 : data.unlocked_coll_tiers) !== null && _a !== void 0 ? _a : []; + const playerCollectionTiersRaw = data?.unlocked_coll_tiers ?? []; const playerCollectionTiers = {}; for (const collectionTierNameValueRaw of playerCollectionTiersRaw) { const [collectionTierNameRaw, collectionTierValueRaw] = collectionTierNameValueRaw.split(/_(?=-?\d+$)/); - const collectionName = itemId_1.cleanItemId(collectionTierNameRaw); + 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 @@ -100,13 +96,13 @@ function cleanCollections(data) { } // 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 = (_b = data === null || data === void 0 ? void 0 : data.collection) !== null && _b !== void 0 ? _b : {}; + const playerCollectionXpsRaw = data?.collection ?? {}; const playerCollections = []; for (const collectionNameRaw in playerCollectionXpsRaw) { const collectionXp = playerCollectionXpsRaw[collectionNameRaw]; - const collectionName = itemId_1.cleanItemId(collectionNameRaw); + const collectionName = cleanItemId(collectionNameRaw); const collectionLevel = playerCollectionTiers[collectionName]; - const collectionCategory = (_c = getCategory(collectionName)) !== null && _c !== void 0 ? _c : 'unknown'; + 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({ @@ -118,4 +114,3 @@ function cleanCollections(data) { } return playerCollections; } -exports.cleanCollections = cleanCollections; diff --git a/build/cleaners/skyblock/fairysouls.js b/build/cleaners/skyblock/fairysouls.js index 1c6cef6..8ec8078 100644 --- a/build/cleaners/skyblock/fairysouls.js +++ b/build/cleaners/skyblock/fairysouls.js @@ -1,12 +1,7 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanFairySouls = void 0; -function cleanFairySouls(data) { - var _a, _b, _c; +export function cleanFairySouls(data) { return { - total: (_a = data === null || data === void 0 ? void 0 : data.fairy_souls_collected) !== null && _a !== void 0 ? _a : 0, - unexchanged: (_b = data === null || data === void 0 ? void 0 : data.fairy_souls) !== null && _b !== void 0 ? _b : 0, - exchanges: (_c = data === null || data === void 0 ? void 0 : data.fairy_exchanges) !== null && _c !== void 0 ? _c : 0, + total: data?.fairy_souls_collected ?? 0, + unexchanged: data?.fairy_souls ?? 0, + exchanges: data?.fairy_exchanges ?? 0, }; } -exports.cleanFairySouls = cleanFairySouls; diff --git a/build/cleaners/skyblock/inventory.js b/build/cleaners/skyblock/inventory.js index 098b8d4..714a302 100644 --- a/build/cleaners/skyblock/inventory.js +++ b/build/cleaners/skyblock/inventory.js @@ -1,32 +1,9 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanInventories = exports.INVENTORIES = exports.cleanInventory = void 0; // maybe todo?: create a fast replacement for prismarine-nbt -const nbt = __importStar(require("prismarine-nbt")); +import * as nbt from 'prismarine-nbt'; function base64decode(base64) { return Buffer.from(base64, 'base64'); } function cleanItem(rawItem) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; // if the item doesn't have an id, it isn't an item if (rawItem.id === undefined) return null; @@ -34,13 +11,13 @@ function cleanItem(rawItem) { const itemCount = rawItem.Count; const damageValue = rawItem.Damage; const itemTag = rawItem.tag; - const extraAttributes = (_a = itemTag === null || itemTag === void 0 ? void 0 : itemTag.ExtraAttributes) !== null && _a !== void 0 ? _a : {}; + const extraAttributes = itemTag?.ExtraAttributes ?? {}; let headId; if (vanillaId === 397) { - const headDataBase64 = (_e = (_d = (_c = (_b = itemTag === null || itemTag === void 0 ? void 0 : itemTag.SkullOwner) === null || _b === void 0 ? void 0 : _b.Properties) === null || _c === void 0 ? void 0 : _c.textures) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.Value; + const headDataBase64 = itemTag?.SkullOwner?.Properties?.textures?.[0]?.Value; if (headDataBase64) { const headData = JSON.parse(base64decode(headDataBase64).toString()); - const headDataUrl = (_g = (_f = headData === null || headData === void 0 ? void 0 : headData.textures) === null || _f === void 0 ? void 0 : _f.SKIN) === null || _g === void 0 ? void 0 : _g.url; + const headDataUrl = headData?.textures?.SKIN?.url; if (headDataUrl) { const splitUrl = headDataUrl.split('/'); headId = splitUrl[splitUrl.length - 1]; @@ -48,26 +25,26 @@ function cleanItem(rawItem) { } } return { - id: (_h = extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.id) !== null && _h !== void 0 ? _h : null, - count: itemCount !== null && itemCount !== void 0 ? itemCount : 1, + id: extraAttributes?.id ?? null, + count: itemCount ?? 1, vanillaId: damageValue ? `${vanillaId}:${damageValue}` : vanillaId.toString(), display: { - name: (_k = (_j = itemTag === null || itemTag === void 0 ? void 0 : itemTag.display) === null || _j === void 0 ? void 0 : _j.Name) !== null && _k !== void 0 ? _k : 'null', - lore: (_m = (_l = itemTag === null || itemTag === void 0 ? void 0 : itemTag.display) === null || _l === void 0 ? void 0 : _l.Lore) !== null && _m !== void 0 ? _m : [], + 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: ((_o = itemTag === null || itemTag === void 0 ? void 0 : itemTag.ench) !== null && _o !== void 0 ? _o : []).length > 0 + glint: (itemTag?.ench ?? []).length > 0 }, - reforge: extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.modifier, - enchantments: extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.enchantments, - anvil_uses: extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.anvil_uses, - timestamp: extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.timestamp, + reforge: extraAttributes?.modifier, + enchantments: extraAttributes?.enchantments, + anvil_uses: extraAttributes?.anvil_uses, + timestamp: extraAttributes?.timestamp, head_texture: headId, }; } function cleanItems(rawItems) { return rawItems.map(cleanItem); } -function cleanInventory(encodedNbt) { +export function cleanInventory(encodedNbt) { return new Promise(resolve => { const base64Data = base64decode(encodedNbt); nbt.parse(base64Data, false, (err, value) => { @@ -77,8 +54,7 @@ function cleanInventory(encodedNbt) { }); }); } -exports.cleanInventory = cleanInventory; -exports.INVENTORIES = { +export const INVENTORIES = { armor: 'inv_armor', inventory: 'inv_contents', ender_chest: 'ender_chest_contents', @@ -89,12 +65,11 @@ exports.INVENTORIES = { trick_or_treat_bag: 'candy_inventory_contents', wardrobe: 'wardrobe_contents' }; -async function cleanInventories(data) { - var _a; +export async function cleanInventories(data) { const cleanInventories = {}; - for (const cleanInventoryName in exports.INVENTORIES) { - const hypixelInventoryName = exports.INVENTORIES[cleanInventoryName]; - const encodedInventoryContents = (_a = data[hypixelInventoryName]) === null || _a === void 0 ? void 0 : _a.data; + for (const cleanInventoryName in INVENTORIES) { + const hypixelInventoryName = INVENTORIES[cleanInventoryName]; + const encodedInventoryContents = data[hypixelInventoryName]?.data; let inventoryContents; if (encodedInventoryContents) { inventoryContents = await cleanInventory(encodedInventoryContents); @@ -106,4 +81,3 @@ async function cleanInventories(data) { } return cleanInventories; } -exports.cleanInventories = cleanInventories; diff --git a/build/cleaners/skyblock/itemId.js b/build/cleaners/skyblock/itemId.js index 7bf5402..ea94771 100644 --- a/build/cleaners/skyblock/itemId.js +++ b/build/cleaners/skyblock/itemId.js @@ -1,6 +1,3 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanItemId = void 0; // change weird item names to be more consistent with vanilla const ITEMS = { 'log': 'oak_log', @@ -55,8 +52,6 @@ const ITEMS = { '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) */ -function cleanItemId(itemId) { - var _a; - return (_a = ITEMS[itemId.toLowerCase()]) !== null && _a !== void 0 ? _a : itemId.toLowerCase(); +export function cleanItemId(itemId) { + return ITEMS[itemId.toLowerCase()] ?? itemId.toLowerCase(); } -exports.cleanItemId = cleanItemId; diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js index cc66488..2242828 100644 --- a/build/cleaners/skyblock/member.js +++ b/build/cleaners/skyblock/member.js @@ -1,37 +1,15 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanSkyBlockProfileMemberResponse = exports.cleanSkyBlockProfileMemberResponseBasic = void 0; -const collections_1 = require("./collections"); -const inventory_1 = require("./inventory"); -const fairysouls_1 = require("./fairysouls"); -const objectives_1 = require("./objectives"); -const stats_1 = require("./stats"); -const minions_1 = require("./minions"); -const slayers_1 = require("./slayers"); -const zones_1 = require("./zones"); -const skills_1 = require("./skills"); -const cached = __importStar(require("../../hypixelCached")); -const constants = __importStar(require("../../constants")); -async function cleanSkyBlockProfileMemberResponseBasic(member) { +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; @@ -43,18 +21,16 @@ async function cleanSkyBlockProfileMemberResponseBasic(member) { rank: player.rank }; } -exports.cleanSkyBlockProfileMemberResponseBasic = cleanSkyBlockProfileMemberResponseBasic; /** Cleans up a member (from skyblock/profile) */ -async function cleanSkyBlockProfileMemberResponse(member, included = undefined) { - var _a; +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 = fairysouls_1.cleanFairySouls(member); + const fairySouls = cleanFairySouls(member); const { max_fairy_souls: maxFairySouls } = await constants.fetchConstantValues(); - if (fairySouls.total > (maxFairySouls !== null && maxFairySouls !== void 0 ? maxFairySouls : 0)) + if (fairySouls.total > (maxFairySouls ?? 0)) await constants.setConstantValues({ max_fairy_souls: fairySouls.total }); return { uuid: member.uuid, @@ -63,17 +39,16 @@ async function cleanSkyBlockProfileMemberResponse(member, included = undefined) first_join: member.first_join / 1000, rank: player.rank, purse: member.coin_purse, - stats: stats_1.cleanProfileStats(member), + stats: cleanProfileStats(member), // this is used for leaderboards - rawHypixelStats: (_a = member.stats) !== null && _a !== void 0 ? _a : {}, - minions: await minions_1.cleanMinions(member), + rawHypixelStats: member.stats ?? {}, + minions: await cleanMinions(member), fairy_souls: fairySouls, - inventories: inventoriesIncluded ? await inventory_1.cleanInventories(member) : undefined, - objectives: objectives_1.cleanObjectives(member), - skills: await skills_1.cleanSkills(member), - visited_zones: zones_1.cleanVisitedZones(member), - collections: collections_1.cleanCollections(member), - slayers: slayers_1.cleanSlayers(member) + inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, + objectives: cleanObjectives(member), + skills: await cleanSkills(member), + visited_zones: cleanVisitedZones(member), + collections: cleanCollections(member), + slayers: cleanSlayers(member) }; } -exports.cleanSkyBlockProfileMemberResponse = cleanSkyBlockProfileMemberResponse; diff --git a/build/cleaners/skyblock/minions.js b/build/cleaners/skyblock/minions.js index d2bfc41..5c0bd9a 100644 --- a/build/cleaners/skyblock/minions.js +++ b/build/cleaners/skyblock/minions.js @@ -1,36 +1,13 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.countUniqueMinions = exports.combineMinionArrays = exports.cleanMinions = void 0; -const hypixel_1 = require("../../hypixel"); -const constants = __importStar(require("../../constants")); +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 */ -async function cleanMinions(member) { - var _a; +export async function cleanMinions(member) { const minions = []; const processedMinionNames = new Set(); - for (const minionRaw of (_a = member === null || member === void 0 ? void 0 : member.crafted_generators) !== null && _a !== void 0 ? _a : []) { + 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(); @@ -40,7 +17,7 @@ async function cleanMinions(member) { // if the minion doesnt already exist in the minions array, then create it matchingMinion = { name: minionName, - levels: new Array(hypixel_1.maxMinion).fill(false) + levels: new Array(maxMinion).fill(false) }; minions.push(matchingMinion); } @@ -63,18 +40,17 @@ async function cleanMinions(member) { processedMinionNames.add(minionName); minions.push({ name: minionName, - levels: new Array(hypixel_1.maxMinion).fill(false) + levels: new Array(maxMinion).fill(false) }); } } return minions.sort((a, b) => a.name > b.name ? 1 : (a.name < b.name ? -1 : 0)); } -exports.cleanMinions = cleanMinions; /** * Combine multiple arrays of minions into one, useful when getting the minions for members * @param minions An array of arrays of minions */ -function combineMinionArrays(minions) { +export function combineMinionArrays(minions) { const resultMinions = []; for (const memberMinions of minions) { for (const minion of memberMinions) { @@ -99,8 +75,7 @@ function combineMinionArrays(minions) { } return resultMinions; } -exports.combineMinionArrays = combineMinionArrays; -function countUniqueMinions(minions) { +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 @@ -108,4 +83,3 @@ function countUniqueMinions(minions) { } return uniqueMinions; } -exports.countUniqueMinions = countUniqueMinions; diff --git a/build/cleaners/skyblock/objectives.js b/build/cleaners/skyblock/objectives.js index d45307c..52e92db 100644 --- a/build/cleaners/skyblock/objectives.js +++ b/build/cleaners/skyblock/objectives.js @@ -1,8 +1,5 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanObjectives = void 0; -function cleanObjectives(data) { - const rawObjectives = (data === null || data === void 0 ? void 0 : data.objectives) || {}; +export function cleanObjectives(data) { + const rawObjectives = data?.objectives || {}; const objectives = []; for (const rawObjectiveName in rawObjectives) { const rawObjectiveValue = rawObjectives[rawObjectiveName]; @@ -13,4 +10,3 @@ function cleanObjectives(data) { } return objectives; } -exports.cleanObjectives = cleanObjectives; diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js index 6460c3b..42e26b3 100644 --- a/build/cleaners/skyblock/profile.js +++ b/build/cleaners/skyblock/profile.js @@ -1,38 +1,16 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanSkyblockProfileResponse = exports.cleanSkyblockProfileResponseLighter = void 0; -const member_1 = require("./member"); -const minions_1 = require("./minions"); -const bank_1 = require("./bank"); -const constants = __importStar(require("../../constants")); +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 */ -async function cleanSkyblockProfileResponseLighter(data) { +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(member_1.cleanSkyBlockProfileMemberResponseBasic(memberRaw)); + promises.push(cleanSkyBlockProfileMemberResponseBasic(memberRaw)); } const cleanedMembers = (await Promise.all(promises)).filter(m => m); return { @@ -41,11 +19,10 @@ async function cleanSkyblockProfileResponseLighter(data) { members: cleanedMembers, }; } -exports.cleanSkyblockProfileResponseLighter = cleanSkyblockProfileResponseLighter; /** * This function is somewhat costly and shouldn't be called often. Use cleanSkyblockProfileResponseLighter if you don't need all the data */ -async function cleanSkyblockProfileResponse(data, options) { +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) @@ -53,13 +30,13 @@ async function cleanSkyblockProfileResponse(data, options) { for (const memberUUID in data.members) { const memberRaw = data.members[memberUUID]; memberRaw.uuid = memberUUID; - promises.push(member_1.cleanSkyBlockProfileMemberResponse(memberRaw, [ - !(options === null || options === void 0 ? void 0 : options.basic) ? 'stats' : undefined, - (options === null || options === void 0 ? void 0 : options.mainMemberUuid) === memberUUID ? 'inventories' : undefined + 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 === null || options === void 0 ? void 0 : options.basic) { + if (options?.basic) { return { uuid: data.profile_id, name: data.cute_name, @@ -70,19 +47,18 @@ async function cleanSkyblockProfileResponse(data, options) { for (const member of cleanedMembers) { memberMinions.push(member.minions); } - const minions = minions_1.combineMinionArrays(memberMinions); + const minions = combineMinionArrays(memberMinions); const { max_minions: maxUniqueMinions } = await constants.fetchConstantValues(); - const uniqueMinions = minions_1.countUniqueMinions(minions); - if (uniqueMinions > (maxUniqueMinions !== null && maxUniqueMinions !== void 0 ? maxUniqueMinions : 0)) + 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: bank_1.cleanBank(data), + bank: cleanBank(data), minions: minions, minion_count: uniqueMinions }; } -exports.cleanSkyblockProfileResponse = cleanSkyblockProfileResponse; diff --git a/build/cleaners/skyblock/profiles.js b/build/cleaners/skyblock/profiles.js index b916209..a85b1f3 100644 --- a/build/cleaners/skyblock/profiles.js +++ b/build/cleaners/skyblock/profiles.js @@ -1,10 +1,7 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanSkyblockProfilesResponse = exports.cleanPlayerSkyblockProfiles = void 0; -const profile_1 = require("./profile"); -function cleanPlayerSkyblockProfiles(rawProfiles) { +import { cleanSkyblockProfileResponse } from './profile.js'; +export function cleanPlayerSkyblockProfiles(rawProfiles) { let profiles = []; - for (const profile of Object.values(rawProfiles !== null && rawProfiles !== void 0 ? rawProfiles : {})) { + for (const profile of Object.values(rawProfiles ?? {})) { profiles.push({ uuid: profile.profile_id, name: profile.cute_name @@ -12,15 +9,13 @@ function cleanPlayerSkyblockProfiles(rawProfiles) { } return profiles; } -exports.cleanPlayerSkyblockProfiles = cleanPlayerSkyblockProfiles; /** Convert an array of raw profiles into clean profiles */ -async function cleanSkyblockProfilesResponse(data) { +export async function cleanSkyblockProfilesResponse(data) { const promises = []; - for (const profile of data !== null && data !== void 0 ? data : []) { + for (const profile of data ?? []) { // let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile) - promises.push(profile_1.cleanSkyblockProfileResponse(profile)); + promises.push(cleanSkyblockProfileResponse(profile)); } const cleanedProfiles = (await Promise.all(promises)).filter(p => p); return cleanedProfiles; } -exports.cleanSkyblockProfilesResponse = cleanSkyblockProfilesResponse; diff --git a/build/cleaners/skyblock/skills.js b/build/cleaners/skyblock/skills.js index 2518d60..e9b19f8 100644 --- a/build/cleaners/skyblock/skills.js +++ b/build/cleaners/skyblock/skills.js @@ -1,6 +1,3 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanSkills = exports.levelForSkillXp = void 0; // the highest level you can have in each skill // numbers taken from https://hypixel-skyblock.fandom.com/wiki/Skills const skillsMaxLevel = { @@ -113,21 +110,19 @@ const skillsDefaultMaxLevel = 50; * @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) */ -function levelForSkillXp(xp, maxLevel) { +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; } -exports.levelForSkillXp = levelForSkillXp; -async function cleanSkills(data) { - var _a; +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 = (_a = skillsMaxLevel[skillName]) !== null && _a !== void 0 ? _a : skillsDefaultMaxLevel; + 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); @@ -149,4 +144,3 @@ async function cleanSkills(data) { } return skills; } -exports.cleanSkills = cleanSkills; diff --git a/build/cleaners/skyblock/slayers.js b/build/cleaners/skyblock/slayers.js index 8575d43..75894f7 100644 --- a/build/cleaners/skyblock/slayers.js +++ b/build/cleaners/skyblock/slayers.js @@ -1,30 +1,26 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanSlayers = exports.slayerLevels = void 0; -exports.slayerLevels = 5; +export const slayerLevels = 5; const SLAYER_NAMES = { spider: 'tarantula', zombie: 'revenant', wolf: 'sven' }; -function cleanSlayers(data) { - var _a, _b; +export function cleanSlayers(data) { const slayers = []; - const slayersDataRaw = data === null || data === void 0 ? void 0 : data.slayer_bosses; + 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 = (_a = slayerDataRaw.xp) !== null && _a !== void 0 ? _a : 0; + 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 = (_b = slayerDataRaw[slayerDataKey]) !== null && _b !== void 0 ? _b : 0; + const slayerTierKills = slayerDataRaw[slayerDataKey] ?? 0; // add 1 since hypixel is using 0 indexed tiers const slayerTier = slayerTierRaw + 1; slayerTiers.push({ @@ -37,7 +33,7 @@ function cleanSlayers(data) { } } // if the slayer tier length is less than the max, add more empty ones - while (slayerTiers.length < exports.slayerLevels) + while (slayerTiers.length < slayerLevels) slayerTiers.push({ tier: slayerTiers.length + 1, kills: 0 @@ -46,7 +42,7 @@ function cleanSlayers(data) { name: slayerName, raw_name: slayerNameRaw, tiers: slayerTiers, - xp: slayerXp !== null && slayerXp !== void 0 ? slayerXp : 0, + xp: slayerXp ?? 0, kills: slayerKills }; slayers.push(slayer); @@ -62,4 +58,3 @@ function cleanSlayers(data) { bosses: slayers }; } -exports.cleanSlayers = cleanSlayers; diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js index 1f72201..361f1ba 100644 --- a/build/cleaners/skyblock/stats.js +++ b/build/cleaners/skyblock/stats.js @@ -1,6 +1,3 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanProfileStats = exports.getStatUnit = exports.statUnits = exports.categorizeStat = void 0; const statCategories = { 'deaths': ['deaths_', 'deaths'], 'kills': ['kills_', 'kills'], @@ -13,7 +10,7 @@ const statCategories = { 'slayer': ['slayer_'], 'misc': null // everything else goes here }; -function categorizeStat(statNameRaw) { +export function categorizeStat(statNameRaw) { // 'deaths_void' for (const statCategory in statCategories) { // 'deaths' @@ -56,15 +53,14 @@ function categorizeStat(statNameRaw) { name: statNameRaw }; } -exports.categorizeStat = categorizeStat; -exports.statUnits = { +export const statUnits = { time: ['_best_time', '_best_time_2'], date: ['first_join'], coins: ['purse'], leaderboards: ['leaderboards_count', 'top_1_leaderboards_count'] }; -function getStatUnit(name) { - for (const [unitName, statMatchers] of Object.entries(exports.statUnits)) { +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) === '_'; @@ -76,23 +72,20 @@ function getStatUnit(name) { } return null; } -exports.getStatUnit = getStatUnit; -function cleanProfileStats(data) { - var _a, _b; +export function cleanProfileStats(data) { // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there) const stats = []; - const rawStats = (_a = data === null || data === void 0 ? void 0 : data.stats) !== null && _a !== void 0 ? _a : {}; + const rawStats = data?.stats ?? {}; for (const statNameRaw in rawStats) { const statValue = rawStats[statNameRaw]; let { category: statCategory, name: statName } = categorizeStat(statNameRaw); stats.push({ - categorizedName: statName !== null && statName !== void 0 ? statName : 'total', + categorizedName: statName ?? 'total', value: statValue, rawName: statNameRaw, category: statCategory, - unit: (_b = getStatUnit(statNameRaw)) !== null && _b !== void 0 ? _b : null + unit: getStatUnit(statNameRaw) ?? null }); } return stats; } -exports.cleanProfileStats = cleanProfileStats; diff --git a/build/cleaners/skyblock/zones.js b/build/cleaners/skyblock/zones.js index fb79441..ef7015e 100644 --- a/build/cleaners/skyblock/zones.js +++ b/build/cleaners/skyblock/zones.js @@ -1,8 +1,5 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanVisitedZones = void 0; -function cleanVisitedZones(data) { - const rawZones = (data === null || data === void 0 ? void 0 : data.visited_zones) || []; +export 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 = []; for (const rawZoneName of rawZones) { @@ -13,4 +10,3 @@ function cleanVisitedZones(data) { } return zones; } -exports.cleanVisitedZones = cleanVisitedZones; diff --git a/build/cleaners/socialmedia.js b/build/cleaners/socialmedia.js index 4883cc4..c901725 100644 --- a/build/cleaners/socialmedia.js +++ b/build/cleaners/socialmedia.js @@ -1,11 +1,6 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanSocialMedia = void 0; -function cleanSocialMedia(data) { - var _a, _b, _c, _d; +export function cleanSocialMedia(data) { return { - discord: ((_b = (_a = data === null || data === void 0 ? void 0 : data.socialMedia) === null || _a === void 0 ? void 0 : _a.links) === null || _b === void 0 ? void 0 : _b.DISCORD) || null, - forums: ((_d = (_c = data === null || data === void 0 ? void 0 : data.socialMedia) === null || _c === void 0 ? void 0 : _c.links) === null || _d === void 0 ? void 0 : _d.HYPIXEL) || null + discord: data?.socialMedia?.links?.DISCORD || null, + forums: data?.socialMedia?.links?.HYPIXEL || null }; } -exports.cleanSocialMedia = cleanSocialMedia; |