diff options
author | mat <github@matdoes.dev> | 2022-04-09 17:22:00 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-04-09 17:22:00 -0500 |
commit | 751b207c86c1e9bea14d48c0855fce5b62ddaba3 (patch) | |
tree | 1a4ee78abff537f1af7a5a0418aee2726f7ff211 /src/cleaners/skyblock | |
parent | 0fe3c70af87813b73f2b263fe3314e69d57b4dbd (diff) | |
download | skyblock-api-751b207c86c1e9bea14d48c0855fce5b62ddaba3.tar.gz skyblock-api-751b207c86c1e9bea14d48c0855fce5b62ddaba3.tar.bz2 skyblock-api-751b207c86c1e9bea14d48c0855fce5b62ddaba3.zip |
Add farming contest leaderboards
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/farmingContents.ts | 11 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 3 | ||||
-rw-r--r-- | src/cleaners/skyblock/slayers.ts | 2 | ||||
-rw-r--r-- | src/cleaners/skyblock/stats.ts | 10 |
4 files changed, 18 insertions, 8 deletions
diff --git a/src/cleaners/skyblock/farmingContents.ts b/src/cleaners/skyblock/farmingContents.ts index 218837d..75427ef 100644 --- a/src/cleaners/skyblock/farmingContents.ts +++ b/src/cleaners/skyblock/farmingContents.ts @@ -1,4 +1,5 @@ import typedHypixelApi from 'typed-hypixel-api' +import { addCrops } from '../../constants.js' import { cleanItemId } from './itemId.js' export interface PlayerFarmingContestStats { @@ -24,31 +25,37 @@ export interface FarmingContests { list: PlayerFarmingContestStats[] } -export function cleanFarmingContests(data: typedHypixelApi.SkyBlockProfileMember): FarmingContests { +export async function cleanFarmingContests(data: typedHypixelApi.SkyBlockProfileMember): Promise<FarmingContests> { if (!data.jacob2) return { talkedToJacob: false, list: [] } + let cropNames: Set<string> = new Set() + const contestsByDate: Record<string, PlayerFarmingContestStats['crops']> = {} for (const [contestName, contestData] of Object.entries(data.jacob2?.contests ?? {})) { const [year, monthDay, item] = contestName.split(':') const [month, day] = monthDay.split('_') const contestByDateKey = `${year}:${month}:${day}` + const cropId = cleanItemId(item) const cropData: PlayerFarmingContestStats['crops'][number] = { - item: cleanItemId(item), + item: cropId, amount: contestData.collected, // the api returns the position 0-indexed, so we add 1 position: contestData.claimed_position !== undefined ? contestData.claimed_position + 1 : null, claimed: contestData.claimed_rewards ?? null, participants: contestData.claimed_participants ?? null } + cropNames.add(cropId) if (!(contestByDateKey in contestsByDate)) contestsByDate[contestByDateKey] = [cropData] else contestsByDate[contestByDateKey].push(cropData) } + await addCrops(Array.from(cropNames)) + const contestsByDateEntries = Object.entries(contestsByDate) // this is to sort by newest first contestsByDateEntries.reverse() diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 6642976..57462ed 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -79,6 +79,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi const petsPromise = cleanPets(member) const harpPromise = cleanHarp(member) const inventoriesPromise = inventoriesIncluded ? cleanInventories(member) : Promise.resolve(undefined) + const farmingContestsPromise = cleanFarmingContests(member) return { uuid: member.uuid, @@ -106,7 +107,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi pets: await petsPromise, harp: await harpPromise, coopInvitation: await coopInvitationPromise, - farmingContests: cleanFarmingContests(member), + farmingContests: await farmingContestsPromise, left: (player.profiles?.find(profile => profile.uuid === profileId) === undefined) ?? false } diff --git a/src/cleaners/skyblock/slayers.ts b/src/cleaners/skyblock/slayers.ts index b5dda0b..6516bbf 100644 --- a/src/cleaners/skyblock/slayers.ts +++ b/src/cleaners/skyblock/slayers.ts @@ -66,7 +66,7 @@ export function cleanSlayers(data: typedHypixelApi.SkyBlockProfileMember): Slaye for (const slayerDataKey in slayerDataRaw) { // if a key starts with boss_kills_tier_ (boss_kills_tier_1), get the last number if (slayerDataKey.startsWith('boss_kills_tier_')) { - const slayerTierRaw = parseInt(slayerDataKey.substr('boss_kills_tier_'.length)) + const slayerTierRaw = parseInt(slayerDataKey.slice('boss_kills_tier_'.length)) const slayerTierKills = slayerDataRaw[slayerDataKey] ?? 0 // add 1 since hypixel is using 0 indexed tiers const slayerTier = slayerTierRaw + 1 diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts index 67099af..e5baa8f 100644 --- a/src/cleaners/skyblock/stats.ts +++ b/src/cleaners/skyblock/stats.ts @@ -9,6 +9,8 @@ const statCategories: { [key: string]: string[] | null } = { // sorted in order 'races': ['_best_time', '_best_time_2'], 'mythos': ['mythos_burrows_', 'mythos_kills'], + 'farming_contests': ['farming_contests_'], + 'collection': ['collection_'], 'skills': ['skill_'], 'slayer': ['slayer_'], @@ -37,16 +39,16 @@ export function categorizeStat(statNameRaw: string): StatCategory { for (const categoryMatch of statCategoryMatchers) { // ['deaths_'] let trailingEnd = categoryMatch[0] === '_' - let trailingStart = categoryMatch.substr(-1) === '_' + let trailingStart = categoryMatch.slice(-1) === '_' if (trailingStart && statNameRaw.startsWith(categoryMatch)) { return { category: statCategory, - name: statNameRaw.substr(categoryMatch.length) + name: statNameRaw.slice(categoryMatch.length) } } else if (trailingEnd && statNameRaw.endsWith(categoryMatch)) { return { category: statCategory, - name: statNameRaw.substr(0, statNameRaw.length - categoryMatch.length) + name: statNameRaw.slice(0, statNameRaw.length - categoryMatch.length) } } else if (statNameRaw == categoryMatch) { // if it matches exactly, we don't know the name. will be defaulted to category later on @@ -83,7 +85,7 @@ export function getStatUnit(name: string): string | null { for (const [unitName, statMatchers] of Object.entries(statUnits)) { for (const statMatch of statMatchers) { let trailingEnd = statMatch[0] === '_' - let trailingStart = statMatch.substr(-1) === '_' + let trailingStart = statMatch.slice(-1) === '_' if ( (trailingStart && name.startsWith(statMatch)) || (trailingEnd && name.endsWith(statMatch)) |