diff options
Diffstat (limited to 'build/cleaners')
-rw-r--r-- | build/cleaners/player.js | 19 | ||||
-rw-r--r-- | build/cleaners/rank.js | 55 | ||||
-rw-r--r-- | build/cleaners/skyblock/minions.js | 63 | ||||
-rw-r--r-- | build/cleaners/skyblock/stats.js | 66 | ||||
-rw-r--r-- | build/cleaners/socialmedia.js | 10 |
5 files changed, 213 insertions, 0 deletions
diff --git a/build/cleaners/player.js b/build/cleaners/player.js new file mode 100644 index 0000000..25ae1f2 --- /dev/null +++ b/build/cleaners/player.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cleanPlayerResponse = void 0; +const hypixel_1 = require("../hypixel"); +const socialmedia_1 = require("./socialmedia"); +const rank_1 = require("./rank"); +const util_1 = require("../util"); +async function cleanPlayerResponse(data) { + // Cleans up a 'player' api response + console.log('cleanPlayerResponse', data.stats.SkyBlock.profiles); + return { + uuid: util_1.undashUuid(data.uuid), + username: data.displayname, + rank: rank_1.parseRank(data), + socials: socialmedia_1.parseSocialMedia(data.socialMedia), + profiles: hypixel_1.cleanPlayerSkyblockProfiles(data.stats.SkyBlock.profiles) + }; +} +exports.cleanPlayerResponse = cleanPlayerResponse; diff --git a/build/cleaners/rank.js b/build/cleaners/rank.js new file mode 100644 index 0000000..875d2db --- /dev/null +++ b/build/cleaners/rank.js @@ -0,0 +1,55 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseRank = void 0; +const util_1 = require("../util"); +const rankColors = { + 'NONE': '7', + 'VIP': 'a', + 'VIP+': 'a', + 'MVP': 'b', + 'MVP+': 'b', + 'MVP++': '6', + 'YOUTUBE': 'c', + 'HELPER': '9', + 'MODERATOR': '2', + 'ADMIN': 'c' +}; +/** Response cleaning (reformatting to be nicer) */ +function parseRank({ packageRank, newPackageRank, monthlyPackageRank, rankPlusColor, rank, prefix }) { + let name; + let color; + let colored; + if (prefix) { // derive values from prefix + colored = prefix; + color = util_1.minecraftColorCodes[colored.match(/§./)[0][1]]; + name = colored.replace(/§./g, '').replace(/[\[\]]/g, ''); + } + else { + name = rank + || newPackageRank.replace('_PLUS', '+') + || packageRank.replace('_PLUS', '+') + || monthlyPackageRank; + // MVP++ is called Superstar for some reason + if (name === 'SUPERSTAR') + name = 'MVP++'; + // YouTube rank is called YouTuber, change this to the proper name + else if (name === 'YOUTUBER') + name = 'YOUTUBE'; + const plusColor = util_1.colorCodeFromName(rankPlusColor); + color = util_1.minecraftColorCodes[rankColors[name]]; + const rankColorPrefix = rankColors[name] ? '§' + rankColors[name] : ''; + const nameWithoutPlus = name.split('+')[0]; + const plusesInName = '+'.repeat(name.split('+').length - 1); + console.log(plusColor, nameWithoutPlus, plusesInName); + if (plusColor && plusesInName.length >= 1) + colored = `${rankColorPrefix}[${nameWithoutPlus}§${plusColor}${plusesInName}${rankColorPrefix}]`; + else + colored = `${rankColorPrefix}[${name}]`; + } + return { + name, + color, + colored + }; +} +exports.parseRank = parseRank; diff --git a/build/cleaners/skyblock/minions.js b/build/cleaners/skyblock/minions.js new file mode 100644 index 0000000..8ffa9c1 --- /dev/null +++ b/build/cleaners/skyblock/minions.js @@ -0,0 +1,63 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.combineMinionArrays = exports.cleanMinions = void 0; +const hypixel_1 = require("../../hypixel"); +/** + * Clean the minions provided by Hypixel + * @param minionsRaw The minion data provided by the Hypixel API + */ +function cleanMinions(minionsRaw) { + const minions = []; + for (const minionRaw of minionsRaw ?? []) { + // 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(hypixel_1.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; + } + return minions; +} +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) { + 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(null); + for (let i = 0; i < minion.levels.length; i++) { + if (minion.levels[i]) + matchingMinionReference.levels[i] = true; + } + } + } + } + return resultMinions; +} +exports.combineMinionArrays = combineMinionArrays; diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js new file mode 100644 index 0000000..81f5544 --- /dev/null +++ b/build/cleaners/skyblock/stats.js @@ -0,0 +1,66 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.cleanProfileStats = void 0; +const statCategories = { + 'deaths': ['deaths_', 'deaths'], + 'kills': ['kills_', 'kills'], + 'fishing': ['items_fished_', 'items_fished'], + 'auctions': ['auctions_'], + 'races': ['_best_time'], + 'misc': null // everything else goes here +}; +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, 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 + }; +} +function cleanProfileStats(statsRaw) { + // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there) + const stats = {}; + for (let statNameRaw in statsRaw) { + let { category: statCategory, name: statName } = categorizeStat(statNameRaw); + if (!stats[statCategory]) + stats[statCategory] = {}; + stats[statCategory][statName || 'total'] = statsRaw[statNameRaw]; + } + return stats; +} +exports.cleanProfileStats = cleanProfileStats; diff --git a/build/cleaners/socialmedia.js b/build/cleaners/socialmedia.js new file mode 100644 index 0000000..fb0bcfd --- /dev/null +++ b/build/cleaners/socialmedia.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseSocialMedia = void 0; +function parseSocialMedia(socialMedia) { + return { + discord: socialMedia?.links?.DISCORD || null, + forums: socialMedia?.links?.HYPIXEL || null + }; +} +exports.parseSocialMedia = parseSocialMedia; |