diff options
author | mat <github@matdoes.dev> | 2022-04-10 19:03:58 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-04-10 19:03:58 -0500 |
commit | 4eef1dc8962df91500114945f35c0fce56a2c3fd (patch) | |
tree | fb9ed128e1b1f02efcac9aba787961c2718f1c6b | |
parent | 126fda903b87434b2204098ad7ae7ae14f363862 (diff) | |
download | skyblock-api-4eef1dc8962df91500114945f35c0fce56a2c3fd.tar.gz skyblock-api-4eef1dc8962df91500114945f35c0fce56a2c3fd.tar.bz2 skyblock-api-4eef1dc8962df91500114945f35c0fce56a2c3fd.zip |
Fix returning wrong color
-rw-r--r-- | src/database.ts | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/database.ts b/src/database.ts index 17b65e7..20da315 100644 --- a/src/database.ts +++ b/src/database.ts @@ -9,7 +9,7 @@ import { Collection, Db, MongoClient, WithId } from 'mongodb' import { CleanMember } from './cleaners/skyblock/member.js' import * as cached from './hypixelCached.js' import * as constants from './constants.js' -import { colorCodeFromName, letterFromColorCode, shuffle, sleep } from './util.js' +import { letterFromColorCode, minecraftColorCodes, shuffle, sleep } from './util.js' import * as discord from './discord.js' import NodeCache from 'node-cache' import { v4 as uuid4 } from 'uuid' @@ -529,26 +529,21 @@ interface LeaderboardBasicPlayer { export async function fetchMemberLeaderboard(name: string): Promise<MemberLeaderboard> { const leaderboardRaw = await fetchMemberLeaderboardRaw(name) - const fetchLeaderboardPlayer = async (i: memberRawLeaderboardItem): Promise<MemberLeaderboardItem> => { - const player: LeaderboardBasicPlayer = { - uuid: i.uuid, - username: i.username, - rank: { - color: (i.color ? colorCodeFromName(i.color) : null) ?? colorCodeFromName(RANK_COLORS.NONE)!, - }, - } - return { - player, + const leaderboard: MemberLeaderboardItem[] = [] + for (const i of leaderboardRaw) { + leaderboard.push({ + player: { + uuid: i.uuid, + username: i.username, + rank: { + color: (i.color ? minecraftColorCodes[i.color] : null) ?? minecraftColorCodes[RANK_COLORS.NONE]!, + }, + }, profileUuid: i.profile, value: i.value - } - } - const promises: Promise<MemberLeaderboardItem>[] = [] - for (const item of leaderboardRaw) { - promises.push(fetchLeaderboardPlayer(item)) + }) } - const leaderboard = await Promise.all(promises) return { name: name, unit: getStatUnit(name) ?? null, |