diff options
author | mat-1 <github@matdoes.dev> | 2021-02-15 01:35:32 +0000 |
---|---|---|
committer | mat-1 <github@matdoes.dev> | 2021-02-15 01:35:32 +0000 |
commit | 84778bb94747390fbcc83a3d6a5bd69286208f61 (patch) | |
tree | cd515d0a8c51b0f343611fd78db7d08f34456c0b /build | |
parent | 342d11858b4db9981a23a27dfb28e18d18a4c2fa (diff) | |
download | skyblock-api-84778bb94747390fbcc83a3d6a5bd69286208f61.tar.gz skyblock-api-84778bb94747390fbcc83a3d6a5bd69286208f61.tar.bz2 skyblock-api-84778bb94747390fbcc83a3d6a5bd69286208f61.zip |
Compiled TS into JS
Diffstat (limited to 'build')
-rw-r--r-- | build/cleaners/player.js | 9 | ||||
-rw-r--r-- | build/cleaners/rank.js | 19 | ||||
-rw-r--r-- | build/cleaners/skyblock/member.js | 12 | ||||
-rw-r--r-- | build/cleaners/skyblock/profiles.js | 4 | ||||
-rw-r--r-- | build/cleaners/skyblock/slayers.js | 53 | ||||
-rw-r--r-- | build/cleaners/socialmedia.js | 12 | ||||
-rw-r--r-- | build/hypixel.js | 4 | ||||
-rw-r--r-- | build/hypixelCached.js | 6 |
8 files changed, 96 insertions, 23 deletions
diff --git a/build/cleaners/player.js b/build/cleaners/player.js index ab1bea7..3ae4e87 100644 --- a/build/cleaners/player.js +++ b/build/cleaners/player.js @@ -1,18 +1,19 @@ "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"); -const profiles_1 = require("./skyblock/profiles"); async function cleanPlayerResponse(data) { + var _a, _b; // Cleans up a 'player' api response return { uuid: util_1.undashUuid(data.uuid), username: data.displayname, - rank: rank_1.parseRank(data), - socials: socialmedia_1.parseSocialMedia(data.socialMedia), - profiles: profiles_1.cleanPlayerSkyblockProfiles(data.stats.SkyBlock.profiles) + rank: rank_1.cleanRank(data), + socials: socialmedia_1.cleanSocialMedia(data), + profiles: profiles_1.cleanPlayerSkyblockProfiles((_b = (_a = data.stats) === null || _a === void 0 ? void 0 : _a.SkyBlock) === null || _b === void 0 ? void 0 : _b.profiles) }; } exports.cleanPlayerResponse = cleanPlayerResponse; diff --git a/build/cleaners/rank.js b/build/cleaners/rank.js index 2287d18..ea8af7e 100644 --- a/build/cleaners/rank.js +++ b/build/cleaners/rank.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.parseRank = void 0; +exports.cleanRank = void 0; const util_1 = require("../util"); const rankColors = { 'NONE': '7', @@ -15,7 +15,7 @@ const rankColors = { 'ADMIN': 'c' }; /** Response cleaning (reformatting to be nicer) */ -function parseRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusColor, rank, prefix }) { +function cleanRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusColor, rank, prefix }) { let name; let color; let colored; @@ -26,8 +26,8 @@ function parseRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusCo } else { name = rank - || newPackageRank.replace('_PLUS', '+') - || packageRank.replace('_PLUS', '+') + || (newPackageRank === null || newPackageRank === void 0 ? void 0 : newPackageRank.replace('_PLUS', '+')) + || (packageRank === null || packageRank === void 0 ? void 0 : packageRank.replace('_PLUS', '+')) || monthlyPackageRank; // MVP++ is called Superstar for some reason if (name === 'SUPERSTAR') @@ -35,15 +35,20 @@ function parseRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusCo // YouTube rank is called YouTuber, change this to the proper name else if (name === 'YOUTUBER') name = 'YOUTUBE'; - const plusColor = util_1.colorCodeFromName(rankPlusColor); + else if (name === undefined) + name = 'NONE'; + const plusColor = rankPlusColor ? util_1.colorCodeFromName(rankPlusColor) : null; color = util_1.minecraftColorCodes[rankColors[name]]; const rankColorPrefix = rankColors[name] ? '§' + rankColors[name] : ''; const nameWithoutPlus = name.split('+')[0]; const plusesInName = '+'.repeat(name.split('+').length - 1); if (plusColor && plusesInName.length >= 1) colored = `${rankColorPrefix}[${nameWithoutPlus}§${plusColor}${plusesInName}${rankColorPrefix}]`; - else + else if (name !== 'NONE') colored = `${rankColorPrefix}[${name}]`; + else + // nons don't have a prefix + colored = `${rankColorPrefix}`; } return { name, @@ -51,4 +56,4 @@ function parseRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusCo colored }; } -exports.parseRank = parseRank; +exports.cleanRank = cleanRank; diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js index 41092e1..0f2e048 100644 --- a/build/cleaners/skyblock/member.js +++ b/build/cleaners/skyblock/member.js @@ -29,12 +29,15 @@ const skills_1 = require("./skills"); const cached = __importStar(require("../../hypixelCached")); const zones_1 = require("./zones"); const collections_1 = require("./collections"); +const slayers_1 = require("./slayers"); async function cleanSkyBlockProfileMemberResponseBasic(member, included = null) { + const player = await cached.fetchPlayer(member.uuid); return { uuid: member.uuid, - username: await cached.usernameFromUser(member.uuid), + username: player.username, last_save: member.last_save, first_join: member.first_join, + rank: player.rank }; } exports.cleanSkyBlockProfileMemberResponseBasic = cleanSkyBlockProfileMemberResponseBasic; @@ -42,11 +45,13 @@ exports.cleanSkyBlockProfileMemberResponseBasic = cleanSkyBlockProfileMemberResp async function cleanSkyBlockProfileMemberResponse(member, included = null) { // profiles.members[] const inventoriesIncluded = included == null || included.includes('inventories'); + const player = await cached.fetchPlayer(member.uuid); return { uuid: member.uuid, - username: await cached.usernameFromUser(member.uuid), + username: player.username, last_save: member.last_save, first_join: member.first_join, + rank: player.rank, purse: member.coin_purse, stats: stats_1.cleanProfileStats(member), minions: minions_1.cleanMinions(member), @@ -55,7 +60,8 @@ async function cleanSkyBlockProfileMemberResponse(member, included = null) { objectives: objectives_1.cleanObjectives(member), skills: skills_1.cleanSkills(member), visited_zones: zones_1.cleanVisitedZones(member), - collections: collections_1.cleanCollections(member) + collections: collections_1.cleanCollections(member), + slayers: slayers_1.cleanSlayers(member) }; } exports.cleanSkyBlockProfileMemberResponse = cleanSkyBlockProfileMemberResponse; diff --git a/build/cleaners/skyblock/profiles.js b/build/cleaners/skyblock/profiles.js index b79fc56..1996d55 100644 --- a/build/cleaners/skyblock/profiles.js +++ b/build/cleaners/skyblock/profiles.js @@ -4,7 +4,7 @@ exports.cleanSkyblockProfilesResponse = exports.cleanPlayerSkyblockProfiles = vo const profile_1 = require("./profile"); function cleanPlayerSkyblockProfiles(rawProfiles) { let profiles = []; - for (const profile of Object.values(rawProfiles)) { + for (const profile of Object.values(rawProfiles !== null && rawProfiles !== void 0 ? rawProfiles : {})) { profiles.push({ uuid: profile.profile_id, name: profile.cute_name @@ -17,7 +17,7 @@ exports.cleanPlayerSkyblockProfiles = cleanPlayerSkyblockProfiles; /** Convert an array of raw profiles into clean profiles */ async function cleanSkyblockProfilesResponse(data) { const cleanedProfiles = []; - for (const profile of data) { + for (const profile of data !== null && data !== void 0 ? data : []) { let cleanedProfile = await profile_1.cleanSkyblockProfileResponseLighter(profile); cleanedProfiles.push(cleanedProfile); } diff --git a/build/cleaners/skyblock/slayers.js b/build/cleaners/skyblock/slayers.js new file mode 100644 index 0000000..d2b9dbe --- /dev/null +++ b/build/cleaners/skyblock/slayers.js @@ -0,0 +1,53 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cleanSlayers = void 0; +const slayerLevels = 4; // number of slayer levels, this might be 5 soon +const SLAYER_NAMES = { + spider: 'tarantula', + zombie: 'revenant', + wolf: 'sven' +}; +function cleanSlayers(data) { + const slayers = []; + const slayersDataRaw = data === null || data === void 0 ? void 0 : data.slayer_bosses; + let totalXp = 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[slayerDataRaw]; + const slayerXp = slayerDataRaw.xp; + 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]; + // add 1 since hypixel is using 0 indexed tiers + const slayerTier = slayerTierRaw + 1; + slayerTiers.push({ + kills: slayerTierKills, + tier: slayerTier + }); + } + } + // 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, + tiers: slayerTiers, + xp: slayerXp + }; + slayers.push(slayer); + // add the xp from this slayer to the total xp + totalXp += slayerXp; + } + return { + xp: totalXp, + bosses: slayers + }; +} +exports.cleanSlayers = cleanSlayers; diff --git a/build/cleaners/socialmedia.js b/build/cleaners/socialmedia.js index 84ebfd5..4883cc4 100644 --- a/build/cleaners/socialmedia.js +++ b/build/cleaners/socialmedia.js @@ -1,11 +1,11 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.parseSocialMedia = void 0; -function parseSocialMedia(socialMedia) { - var _a, _b; +exports.cleanSocialMedia = void 0; +function cleanSocialMedia(data) { + var _a, _b, _c, _d; return { - discord: ((_a = socialMedia === null || socialMedia === void 0 ? void 0 : socialMedia.links) === null || _a === void 0 ? void 0 : _a.DISCORD) || null, - forums: ((_b = socialMedia === null || socialMedia === void 0 ? void 0 : socialMedia.links) === null || _b === void 0 ? void 0 : _b.HYPIXEL) || null + 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 }; } -exports.parseSocialMedia = parseSocialMedia; +exports.cleanSocialMedia = cleanSocialMedia; diff --git a/build/hypixel.js b/build/hypixel.js index 5c6ce4c..91ec025 100644 --- a/build/hypixel.js +++ b/build/hypixel.js @@ -107,6 +107,9 @@ exports.fetchUser = fetchUser; async function fetchMemberProfile(user, profile) { const playerUuid = await cached.uuidFromUser(user); const profileUuid = await cached.fetchProfileUuid(user, profile); + // if the profile doesn't have an id, just return + if (!profileUuid) + return null; const player = await cached.fetchPlayer(playerUuid); const cleanProfile = await cached.fetchProfile(playerUuid, profileUuid); const member = cleanProfile.members.find(m => m.uuid === playerUuid); @@ -117,6 +120,7 @@ async function fetchMemberProfile(user, profile) { username: m.username, first_join: m.first_join, last_save: m.last_save, + rank: m.rank }; }); cleanProfile.members = simpleMembers; diff --git a/build/hypixelCached.js b/build/hypixelCached.js index cb8d0db..c357763 100644 --- a/build/hypixelCached.js +++ b/build/hypixelCached.js @@ -138,7 +138,8 @@ async function fetchSkyblockProfiles(playerUuid) { uuid: m.uuid, username: m.username, first_join: m.first_join, - last_save: m.last_save + last_save: m.last_save, + rank: m.rank }; }) }; @@ -170,6 +171,9 @@ async function fetchBasicProfiles(user) { * @param profile A profile name or profile uuid */ async function fetchProfileUuid(user, profile) { + // if a profile wasn't provided, return + if (!profile) + return null; const profiles = await fetchBasicProfiles(user); const profileUuid = util_1.undashUuid(profile); for (const p of profiles) { |