diff options
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | package-lock.json | 14 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/cleaners/skyblock/experimentation.ts | 70 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 9 | ||||
-rw-r--r-- | test/test.js | 2 |
6 files changed, 97 insertions, 10 deletions
@@ -19,3 +19,13 @@ If you (this is really just here for myself so I don't forget) are adding a new First, install the dependencies with `npm i`. Then to run it, do `tsc -w` in one terminal, `npx nodemon build` in another. This makes it automatically restart when you make a change. If you don't like it auto restarting, then just do `node build` instead of `npx nodemon build`. + + +## Terminology + +Here's some words frequently used in the codebase that might potentially get confused: + +- Profile: Sometimes known as a co-op, these contain one or more members. +- Member: Someone who is in a profile. +- Player: An individual account, it can be in multiple profiles and each instance of them in the profile is a different member. + diff --git a/package-lock.json b/package-lock.json index 1a12587..9883184 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "prismarine-nbt": "github:PrismarineJS/prismarine-nbt", "prom-client": "^14.0.1", "queue-promise": "^2.2.1", - "typed-hypixel-api": "^1.4.0", + "typed-hypixel-api": "^1.4.1", "uuid": "^8.3.2" }, "devDependencies": { @@ -2734,9 +2734,9 @@ } }, "node_modules/typed-hypixel-api": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/typed-hypixel-api/-/typed-hypixel-api-1.4.0.tgz", - "integrity": "sha512-XhU8CugljxGqleacjRjP7JBYDuxSuIofy+Fx+lHfn6UIzzXm9lQNBaPzSE5lZNV97l4XQafIU3qzbBG/9Ky79A==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/typed-hypixel-api/-/typed-hypixel-api-1.4.1.tgz", + "integrity": "sha512-38eNYG+YK+FCHcgs3I70noTVlapYbZUD2LlXZ96aQ1mVLvez/7L8BW1KWYIL2aPIiDYVJ3oKiWy7+A+alwvWOw==", "dependencies": { "typescript": "^4.6.3", "undici": "^4.16.0" @@ -5070,9 +5070,9 @@ } }, "typed-hypixel-api": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/typed-hypixel-api/-/typed-hypixel-api-1.4.0.tgz", - "integrity": "sha512-XhU8CugljxGqleacjRjP7JBYDuxSuIofy+Fx+lHfn6UIzzXm9lQNBaPzSE5lZNV97l4XQafIU3qzbBG/9Ky79A==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/typed-hypixel-api/-/typed-hypixel-api-1.4.1.tgz", + "integrity": "sha512-38eNYG+YK+FCHcgs3I70noTVlapYbZUD2LlXZ96aQ1mVLvez/7L8BW1KWYIL2aPIiDYVJ3oKiWy7+A+alwvWOw==", "requires": { "typescript": "^4.6.3", "undici": "^4.16.0" diff --git a/package.json b/package.json index 39e6cd8..6239cee 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "prismarine-nbt": "github:PrismarineJS/prismarine-nbt", "prom-client": "^14.0.1", "queue-promise": "^2.2.1", - "typed-hypixel-api": "^1.4.0", + "typed-hypixel-api": "^1.4.1", "uuid": "^8.3.2" }, "devDependencies": { diff --git a/src/cleaners/skyblock/experimentation.ts b/src/cleaners/skyblock/experimentation.ts new file mode 100644 index 0000000..d81fb3d --- /dev/null +++ b/src/cleaners/skyblock/experimentation.ts @@ -0,0 +1,70 @@ +import typedHypixelApi from 'typed-hypixel-api' +import { ExperimentationGame as ApiExperimentationGame } from 'typed-hypixel-api/build/responses/skyblock/_profile_member' +import * as constants from '../../constants.js' + +export interface ExperimentationGame { + /** `superpairs`, `chronomatron` or `ultrasequencer`. */ + id: string + last_attempt: number | undefined + last_claimed: number | undefined + types: { + attempts: number + claims: number + best_score: number + }[] +} + +const EXPERIMENTATION_GAME_IDS = { + pairings: 'superpairs', + simon: 'chronomatron', + numbers: 'ultrasequencer' +} as const + +// this should be in skyblock-constants, but i don't expect hypixel to add new experimentation games +const EXPERIMENTATION_GAME_TYPES_COUNT: Record<typeof EXPERIMENTATION_GAME_IDS[keyof typeof EXPERIMENTATION_GAME_IDS], number> = { + superpairs: 6, + chronomatron: 5, + ultrasequencer: 3 +} + +export interface Experimentation { + games: ExperimentationGame[] +} + +function cleanGame(apiId: string, game: ApiExperimentationGame | undefined): ExperimentationGame { + const gameId = EXPERIMENTATION_GAME_IDS[apiId] + + if (!game) + game = {} + + const types: ExperimentationGame['types'] = [] + + for (let i = 0; i < EXPERIMENTATION_GAME_TYPES_COUNT[gameId]; i++) { + const type_attempts = game[`attempts_${i}`] ?? 0 + const type_claims = game[`claims_${i}`] ?? 0 + const type_best_score = game[`best_score_${i}`] ?? 0 + + types.push({ + attempts: type_attempts, + claims: type_claims, + best_score: type_best_score + }) + } + + return { + id: gameId, + last_attempt: game.last_attempt || undefined, + last_claimed: game.last_claimed || undefined, + types + } +} + +export async function cleanExperimentation(data: typedHypixelApi.SkyBlockProfileMember): Promise<Experimentation> { + return { + games: [ + cleanGame('pairings', data.experimentation?.pairings), + cleanGame('simon', data.experimentation?.simon), + cleanGame('numbers', data.experimentation?.numbers) + ] + } +} diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index d69295e..9d68796 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -1,3 +1,5 @@ +import { AccessoryBagUpgrades, cleanAccessoryBagUpgrades } from './accessoryBagUpgrades.js' +import { cleanExperimentation, Experimentation } from './experimentation.js' import { cleanFarmingContests, FarmingContests } from './farmingContents.js' import { cleanCoopInvitation, CoopInvitation } from './coopInvitation.js' import { cleanCollections, Collection } from './collections.js' @@ -9,6 +11,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 { cleanEssence, Essence } from './essence.js' import { cleanVisitedZones, Zone } from './zones.js' import { cleanSkills, Skills } from './skills.js' import * as cached from '../../hypixelCached.js' @@ -19,8 +22,6 @@ import * as constants from '../../constants.js' import { Included } from '../../hypixel.js' import { CleanPlayer } from '../player.js' import { CleanRank } from '../rank.js' -import { AccessoryBagUpgrades, cleanAccessoryBagUpgrades } from './accessoryBagUpgrades.js' -import { cleanEssence, Essence } from './essence.js' export interface CleanBasicMember { uuid: string @@ -48,6 +49,8 @@ interface ExtraCleanMemberFields { coopInvitation: CoopInvitation | null farmingContests: FarmingContests accessoryBagUpgrades: AccessoryBagUpgrades + experimentation: Experimentation + /** Whether the user left the coop */ essence: Essence /** Whether the member left the coop. */ left: boolean @@ -87,6 +90,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi const harpPromise = cleanHarp(member) const inventoriesPromise = inventoriesIncluded ? cleanInventories(member) : Promise.resolve(undefined) const farmingContestsPromise = cleanFarmingContests(member) + const experimentationTablePromise = cleanExperimentation(member) return { uuid: member.uuid, @@ -118,6 +122,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi coopInvitation: await coopInvitationPromise, farmingContests: await farmingContestsPromise, accessoryBagUpgrades: cleanAccessoryBagUpgrades(member), + experimentation: await experimentationTablePromise, essence: cleanEssence(member), left: (player.profiles?.find(profile => profile.uuid === profileId) === undefined) ?? false diff --git a/test/test.js b/test/test.js index 5cbde19..6d30993 100644 --- a/test/test.js +++ b/test/test.js @@ -38,6 +38,8 @@ hypixelApi.mockSendApiRequest(async (path, options) => { } case 'resources/skyblock/items': return await readJsonData('resources/skyblock/items') + case 'resources/achievements': + return await readJsonData('resources/achievements') } }) |