From 4eef1dc8962df91500114945f35c0fce56a2c3fd Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 10 Apr 2022 19:03:58 -0500 Subject: Fix returning wrong color --- src/database.ts | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/database.ts') 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 { const leaderboardRaw = await fetchMemberLeaderboardRaw(name) - const fetchLeaderboardPlayer = async (i: memberRawLeaderboardItem): Promise => { - 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[] = [] - for (const item of leaderboardRaw) { - promises.push(fetchLeaderboardPlayer(item)) + }) } - const leaderboard = await Promise.all(promises) return { name: name, unit: getStatUnit(name) ?? null, -- cgit