From 0a31ac6943aef19fbc63b25163ecb3b4a3c9f81b Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 27 Mar 2022 19:38:44 -0500 Subject: Add coop invitation --- package-lock.json | 39 ++++++++-------- package.json | 5 +- src/cleaners/skyblock/coopInvitation.ts | 19 ++++++++ src/cleaners/skyblock/member.ts | 8 +++- test-data-generator/index.ts | 7 ++- test/data/constants/manual/skill_xp.json | 61 ------------------------- test/data/constants/manual/skill_xp_easier.json | 26 ----------- 7 files changed, 53 insertions(+), 112 deletions(-) create mode 100644 src/cleaners/skyblock/coopInvitation.ts delete mode 100644 test/data/constants/manual/skill_xp.json delete mode 100644 test/data/constants/manual/skill_xp_easier.json diff --git a/package-lock.json b/package-lock.json index 041b688..cc894e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "@types/node": "^17.0.21", "dotenv": "^16.0.0", "mocha": "^9.2.1", - "ts-node": "^10.5.0", + "ts-node": "^10.7.0", "typescript": "^4.6.3" }, "engines": { @@ -200,9 +200,9 @@ } }, "node_modules/acorn": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz", - "integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", + "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -212,9 +212,9 @@ } }, "node_modules/acorn-walk": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.1.1.tgz", - "integrity": "sha512-FbJdceMlPHEAWJOILDk1fXD8lnTlEIWFkqtfk+MvmL5q/qlHfN7GEHcsFZWt/Tea9jRNPWUZG4G976nqAAmU9w==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", "dev": true, "engines": { "node": ">=0.4.0" @@ -1873,9 +1873,9 @@ } }, "node_modules/ts-node": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.5.0.tgz", - "integrity": "sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==", + "version": "10.7.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", + "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", "dev": true, "dependencies": { "@cspotcode/source-map-support": "0.7.0", @@ -1895,6 +1895,7 @@ "bin": { "ts-node": "dist/bin.js", "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", "ts-node-script": "dist/bin-script.js", "ts-node-transpile-only": "dist/bin-transpile.js", "ts-script": "dist/bin-script-deprecated.js" @@ -2387,15 +2388,15 @@ } }, "acorn": { - "version": "8.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz", - "integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", + "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", "dev": true }, "acorn-walk": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.1.1.tgz", - "integrity": "sha512-FbJdceMlPHEAWJOILDk1fXD8lnTlEIWFkqtfk+MvmL5q/qlHfN7GEHcsFZWt/Tea9jRNPWUZG4G976nqAAmU9w==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", "dev": true }, "ajv": { @@ -3585,9 +3586,9 @@ } }, "ts-node": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.5.0.tgz", - "integrity": "sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==", + "version": "10.7.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", + "integrity": "sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==", "dev": true, "requires": { "@cspotcode/source-map-support": "0.7.0", diff --git a/package.json b/package.json index 1061b31..0500566 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "index.ts", "scripts": { "test": "mocha", + "generate-test-data": "node --experimental-specifier-resolution=node --loader ts-node/esm ./test-data-generator/index.ts", "compile": "tsc", "watch": "tsc -w", "start": "npm i --only=prod && node --trace-warnings build/index.js" @@ -48,8 +49,8 @@ "@types/node": "^17.0.21", "dotenv": "^16.0.0", "mocha": "^9.2.1", - "ts-node": "^10.5.0", + "ts-node": "^10.7.0", "typescript": "^4.6.3" }, "type": "module" -} +} \ No newline at end of file diff --git a/src/cleaners/skyblock/coopInvitation.ts b/src/cleaners/skyblock/coopInvitation.ts new file mode 100644 index 0000000..80c92bb --- /dev/null +++ b/src/cleaners/skyblock/coopInvitation.ts @@ -0,0 +1,19 @@ +import typedHypixelApi from 'typed-hypixel-api' + +export interface CoopInvitation { + invitedTimestamp: number + invitedByUuid: string + accepted: boolean + acceptedTimestamp: number | null +} + +export function cleanCoopInvitation(data: typedHypixelApi.SkyBlockProfileMember): null | CoopInvitation { + if (!data.coop_invitation) + return null + return { + invitedTimestamp: data.coop_invitation.timestamp, + invitedByUuid: data.coop_invitation.invited_by, + accepted: data.coop_invitation.confirmed, + acceptedTimestamp: data.coop_invitation.confirmed_timestamp ?? null + } +} \ No newline at end of file diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 99a4376..2acbd26 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -1,3 +1,4 @@ +import { cleanCoopInvitation, CoopInvitation } from './coopInvitation.js' import { cleanCollections, Collection } from './collections.js' import { cleanInventories, Inventories } from './inventory.js' import { cleanFairySouls, FairySouls } from './fairysouls.js' @@ -11,12 +12,12 @@ import { cleanVisitedZones, Zone } from './zones.js' import { cleanSkills, Skill } from './skills.js' import * as cached from '../../hypixelCached.js' import typedHypixelApi from 'typed-hypixel-api' +import { cleanPets, PetsData } from './pets.js' +import { cleanHarp, HarpData } from './harp.js' import * as constants from '../../constants.js' import { Included } from '../../hypixel.js' import { CleanPlayer } from '../player.js' import { CleanRank } from '../rank.js' -import { cleanPets, Pet, PetsData } from './pets.js' -import { cleanHarp, HarpData } from './harp.js' export interface CleanBasicMember { uuid: string @@ -41,6 +42,7 @@ export interface CleanMember extends CleanBasicMember { slayers: SlayerData pets: PetsData harp: HarpData + coopInvitation: CoopInvitation | null /** Whether the user left the coop */ left: boolean } @@ -93,6 +95,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi slayers: cleanSlayers(member), pets: await cleanPets(member), harp: await cleanHarp(member), + coopInvitation: cleanCoopInvitation(member), left: (player.profiles?.find(profile => profile.uuid === profileId) === undefined) ?? false } @@ -117,6 +120,7 @@ export interface CleanMemberProfilePlayer extends CleanPlayer { slayers: SlayerData pets: PetsData harp: HarpData + coopInvitation: CoopInvitation | null } export interface CleanMemberProfile { diff --git a/test-data-generator/index.ts b/test-data-generator/index.ts index f296c16..bf8f34b 100644 --- a/test-data-generator/index.ts +++ b/test-data-generator/index.ts @@ -20,12 +20,13 @@ const playerUuids = [ ] async function writeTestData(requestPath: string, name: string, contents: any) { - const dir = path.join(__dirname, '..', 'test', 'data', requestPath) + const dir = path.join(process.cwd(), '..', 'test', 'data', requestPath) await fs.mkdir(path.dirname(path.join(dir, `${name}.json`)), { recursive: true }) await fs.writeFile(path.join(dir, `${name}.json`), JSON.stringify(contents, null, 2)) } -async function addResponse(requestPath: keyof typedHypixelApi.Requests, args: { [ key: string ]: string }, name: string) { +async function addResponse(requestPath: keyof typedHypixelApi.Requests, args: { [key: string]: string }, name: string) { + console.log('Fetching', requestPath, args) const response = await hypixelApi.sendApiRequest(requestPath, { key: hypixelApi.chooseApiKey(), ...args, @@ -38,9 +39,11 @@ async function addConstants() { const constantNames = [ 'collections', 'minions', + 'pets', 'skills', 'slayers', 'stats', + 'values', 'zones', ] for (const constantName of constantNames) { diff --git a/test/data/constants/manual/skill_xp.json b/test/data/constants/manual/skill_xp.json deleted file mode 100644 index 2aee873..0000000 --- a/test/data/constants/manual/skill_xp.json +++ /dev/null @@ -1,61 +0,0 @@ -[ 50, - 175, - 375, - 675, - 1175, - 1925, - 2925, - 4425, - 6425, - 9925, - 14925, - 22425, - 32425, - 47425, - 67425, - 97425, - 147425, - 222425, - 322425, - 522425, - 822425, - 1222425, - 1722425, - 2322425, - 3022425, - 3822425, - 4722425, - 5722425, - 6822425, - 8022425, - 9322425, - 10722425, - 12222425, - 13822425, - 15522425, - 17322425, - 19222425, - 21222425, - 23322425, - 25522425, - 27822425, - 30222425, - 32722425, - 35322425, - 38072425, - 40972425, - 44072425, - 47472425, - 51172425, - 55172425, - 59472425, - 64072425, - 68972425, - 74172425, - 79672425, - 85472425, - 91572425, - 97972425, - 104672425, - 111672425 -] \ No newline at end of file diff --git a/test/data/constants/manual/skill_xp_easier.json b/test/data/constants/manual/skill_xp_easier.json deleted file mode 100644 index b1be10b..0000000 --- a/test/data/constants/manual/skill_xp_easier.json +++ /dev/null @@ -1,26 +0,0 @@ -[ 50, - 150, - 275, - 435, - 635, - 885, - 1200, - 1600, - 2100, - 2725, - 3510, - 4510, - 5760, - 7325, - 9325, - 11825, - 14950, - 18950, - 23950, - 30200, - 38050, - 47850, - 60100, - 75400, - 94450 -] \ No newline at end of file -- cgit