diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 14:13:42 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 14:13:42 -0600 |
commit | 52e38809212133ef673d11bfa96ba3bb43c3644c (patch) | |
tree | f54408afd41cc64b64d5e82a3ad814b1bb55d4a7 /src/cleaners/rank.ts | |
parent | a23103ec24128f2e24b93ad101ade6dfdd4758c3 (diff) | |
download | skyblock-api-52e38809212133ef673d11bfa96ba3bb43c3644c.tar.gz skyblock-api-52e38809212133ef673d11bfa96ba3bb43c3644c.tar.bz2 skyblock-api-52e38809212133ef673d11bfa96ba3bb43c3644c.zip |
move stuff into src folder
Diffstat (limited to 'src/cleaners/rank.ts')
-rw-r--r-- | src/cleaners/rank.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/cleaners/rank.ts b/src/cleaners/rank.ts new file mode 100644 index 0000000..928373a --- /dev/null +++ b/src/cleaners/rank.ts @@ -0,0 +1,66 @@ +import { HypixelPlayer } from '../hypixelApi' +import { colorCodeFromName, minecraftColorCodes } from '../util' + +const rankColors: { [ name: string ]: string } = { + 'NONE': '7', + 'VIP': 'a', + 'VIP+': 'a', + 'MVP': 'b', + 'MVP+': 'b', + 'MVP++': '6', + 'YOUTUBE': 'c', + 'HELPER': '9', + 'MODERATOR': '2', + 'ADMIN': 'c' +} + +export interface CleanRank { + name: string, + color: string | null, + colored: string | null, +} + +/** Response cleaning (reformatting to be nicer) */ +export function parseRank({ + packageRank, + newPackageRank, + monthlyPackageRank, + rankPlusColor, + rank, + prefix +}: HypixelPlayer): CleanRank { + let name + let color + let colored + if (prefix) { // derive values from prefix + colored = prefix + color = 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 = colorCodeFromName(rankPlusColor) + color = 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 + } +} |