diff options
author | mat <github@matdoes.dev> | 2022-03-30 17:36:44 +0000 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-30 17:36:44 +0000 |
commit | 5b86305771230e238c20c2311dd3ceef7bd858e6 (patch) | |
tree | 1a2b843c69a2b9926e489fe662d841cfa5e4b3b3 /src/cleaners/skyblock | |
parent | 7ac9e12332bba402d5ff2898735f331e5b291381 (diff) | |
download | skyblock-api-5b86305771230e238c20c2311dd3ceef7bd858e6.tar.gz skyblock-api-5b86305771230e238c20c2311dd3ceef7bd858e6.tar.bz2 skyblock-api-5b86305771230e238c20c2311dd3ceef7bd858e6.zip |
add farming contest stuff
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/farmingContents.ts | 65 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 4 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/cleaners/skyblock/farmingContents.ts b/src/cleaners/skyblock/farmingContents.ts new file mode 100644 index 0000000..c10408d --- /dev/null +++ b/src/cleaners/skyblock/farmingContents.ts @@ -0,0 +1,65 @@ +import typedHypixelApi from 'typed-hypixel-api' + +export interface PlayerFarmingContestStats { + year: number + month: number + day: number + crops: { + item: string + amount: number + /** The position (1-indexed) that the user got on the contest. */ + position: number | null + /** Whether the player has claimed their rewards. */ + claimed: boolean | null + /** + * The number of people who participated in this contest. + */ + participants: number | null + }[] +} + +export interface FarmingContests { + talkedToJacob: boolean + list: PlayerFarmingContestStats[] +} + +export function cleanFarmingContest(data: typedHypixelApi.SkyBlockProfileMember): FarmingContests { + if (!data.jacob2) return { + talkedToJacob: false, + list: [] + } + + 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 cropData: PlayerFarmingContestStats['crops'][number] = { + item, + amount: contestData.collected, + // the api returns the position 0-indexed, so we add 1 + position: contestData.claimed_position ? contestData.claimed_position + 1 : null, + claimed: contestData.claimed_rewards ?? null, + participants: contestData.claimed_participants ?? null + } + if (!(contestByDateKey in contestsByDate)) + contestsByDate[contestByDateKey] = [cropData] + else + contestsByDate[contestByDateKey].push(cropData) + } + + const contests: PlayerFarmingContestStats[] = Object.entries(contestsByDate).map(([contestDateKey, crops]) => { + const [year, month, day] = contestDateKey.split(':') + return { + year: parseInt(year), + month: parseInt(month), + day: parseInt(day), + crops + } + }) + + return { + talkedToJacob: data.jacob2?.talked ?? false, + list: contests + } +}
\ No newline at end of file diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index c7c9a2e..a2010da 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -8,6 +8,7 @@ import { cleanProfileStats, StatItem } from './stats.js' import { CleanMinion, cleanMinions } from './minions.js' import { cleanSlayers, SlayerData } from './slayers.js' import { AccountCustomization } from '../../database.js' +import { cleanFarmingContest, FarmingContests } from './farmingContents.js' import { cleanVisitedZones, Zone } from './zones.js' import { cleanSkills, Skill } from './skills.js' import * as cached from '../../hypixelCached.js' @@ -43,6 +44,7 @@ export interface CleanMember extends CleanBasicMember { pets: PetsData harp: HarpData coopInvitation: CoopInvitation | null + farmingContest: FarmingContests /** Whether the user left the coop */ left: boolean } @@ -96,6 +98,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi pets: await cleanPets(member), harp: await cleanHarp(member), coopInvitation: cleanCoopInvitation(member), + farmingContest: cleanFarmingContest(member), left: (player.profiles?.find(profile => profile.uuid === profileId) === undefined) ?? false } @@ -121,6 +124,7 @@ export interface CleanMemberProfilePlayer extends CleanPlayer { pets: PetsData harp: HarpData coopInvitation: CoopInvitation | null + farmingContest: FarmingContests } export interface CleanMemberProfile { |