diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cleaners/skyblock/stats.ts | 5 | ||||
-rw-r--r-- | src/database.ts | 20 | ||||
-rw-r--r-- | src/index.ts | 4 |
3 files changed, 25 insertions, 4 deletions
diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts index 99aa1f7..d55fdd4 100644 --- a/src/cleaners/skyblock/stats.ts +++ b/src/cleaners/skyblock/stats.ts @@ -3,16 +3,17 @@ const statCategories: { [ key: string ]: string[] | null } = { // sorted in orde 'kills': ['kills_', 'kills'], 'fishing': ['items_fished_', 'items_fished'], 'auctions': ['auctions_'], + 'collection': ['collection_'], 'races': ['_best_time'], 'misc': null // everything else goes here } -interface statCategory { +export interface StatCategory { category: string, name: string } -function categorizeStat(statNameRaw: string): statCategory { +export function categorizeStat(statNameRaw: string): StatCategory { // 'deaths_void' for (const statCategory in statCategories) { // 'deaths' diff --git a/src/database.ts b/src/database.ts index 7cc2f46..b6507cc 100644 --- a/src/database.ts +++ b/src/database.ts @@ -10,6 +10,7 @@ import { CleanMember } from './cleaners/skyblock/member' import { CleanPlayer } from './cleaners/player' import { shuffle } from './util' import { CleanFullProfile } from './cleaners/skyblock/profile' +import { categorizeStat, StatCategory } from './cleaners/skyblock/stats' // don't update the user for 3 minutes const recentlyUpdated = new NodeCache({ @@ -75,6 +76,25 @@ function getMemberLeaderboardAttributes(member: CleanMember) { } } +interface CategorizedLeaderboard extends StatCategory { + id: string +} + +export async function fetchAllLeaderboardsCategoriezed(): Promise<CategorizedLeaderboard[]> { + const memberLeaderboardAttributes = await fetchAllMemberLeaderboardAttributes() + const categorizedLeaderboards: CategorizedLeaderboard[] = [] + for (const leaderboard of memberLeaderboardAttributes) { + const { category, name } = categorizeStat(leaderboard) + categorizedLeaderboards.push({ + category, + name, + id: leaderboard + }) + } + return categorizedLeaderboards +} + + /** Fetch the names of all the leaderboards */ export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> { return [ diff --git a/src/index.ts b/src/index.ts index a1da3e1..f35363a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { fetchMemberProfile, fetchUser } from './hypixel' import express from 'express' -import { fetchAllMemberLeaderboardAttributes, fetchMemberLeaderboard } from './database' +import { fetchAllLeaderboardsCategoriezed, fetchMemberLeaderboard } from './database' const app = express() @@ -42,7 +42,7 @@ app.get('/leaderboard/:name', async(req, res) => { app.get('/leaderboards', async(req, res) => { res.json( - await fetchAllMemberLeaderboardAttributes() + await fetchAllLeaderboardsCategoriezed() ) }) |