aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/cleaners/skyblock/bank.js5
-rw-r--r--build/cleaners/skyblock/member.js21
-rw-r--r--build/cleaners/skyblock/objectives.js16
-rw-r--r--build/cleaners/skyblock/profile.js2
-rw-r--r--build/cleaners/skyblock/skills.js18
-rw-r--r--build/cleaners/skyblock/stats.js9
-rw-r--r--build/hypixel.js10
-rw-r--r--src/cleaners/skyblock/bank.ts3
-rw-r--r--src/cleaners/skyblock/member.ts30
-rw-r--r--src/cleaners/skyblock/objectives.ts17
-rw-r--r--src/cleaners/skyblock/profile.ts10
-rw-r--r--src/cleaners/skyblock/skills.ts19
-rw-r--r--src/cleaners/skyblock/stats.ts8
-rw-r--r--src/hypixel.ts14
14 files changed, 150 insertions, 32 deletions
diff --git a/build/cleaners/skyblock/bank.js b/build/cleaners/skyblock/bank.js
index a3db577..9836685 100644
--- a/build/cleaners/skyblock/bank.js
+++ b/build/cleaners/skyblock/bank.js
@@ -2,11 +2,12 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanBank = void 0;
function cleanBank(data) {
- var _a, _b, _c, _d;
+ var _a, _b;
return {
balance: (_b = (_a = data === null || data === void 0 ? void 0 : data.banking) === null || _a === void 0 ? void 0 : _a.balance) !== null && _b !== void 0 ? _b : 0,
// TODO: make transactions good
- history: (_d = (_c = data === null || data === void 0 ? void 0 : data.banking) === null || _c === void 0 ? void 0 : _c.transactions) !== null && _d !== void 0 ? _d : []
+ // history: data?.banking?.transactions ?? []
+ history: []
};
}
exports.cleanBank = cleanBank;
diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js
index 4cd0425..9d10a5e 100644
--- a/build/cleaners/skyblock/member.js
+++ b/build/cleaners/skyblock/member.js
@@ -19,27 +19,36 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.cleanSkyBlockProfileMemberResponse = void 0;
+exports.cleanSkyBlockProfileMemberResponse = exports.cleanSkyBlockProfileMemberResponseBasic = void 0;
const cached = __importStar(require("../../hypixelCached"));
const fairysouls_1 = require("./fairysouls");
const inventory_1 = require("./inventory");
const minions_1 = require("./minions");
+const objectives_1 = require("./objectives");
const stats_1 = require("./stats");
+async function cleanSkyBlockProfileMemberResponseBasic(member, included = null) {
+ return {
+ uuid: member.uuid,
+ username: await cached.usernameFromUser(member.uuid),
+ last_save: member.last_save,
+ first_join: member.first_join,
+ };
+}
+exports.cleanSkyBlockProfileMemberResponseBasic = cleanSkyBlockProfileMemberResponseBasic;
/** Cleans up a member (from skyblock/profile) */
async function cleanSkyBlockProfileMemberResponse(member, included = null) {
// profiles.members[]
- const statsIncluded = included == null || included.includes('stats');
const inventoriesIncluded = included == null || included.includes('inventories');
return {
uuid: member.uuid,
username: await cached.usernameFromUser(member.uuid),
last_save: member.last_save,
first_join: member.first_join,
- // last_death: ??? idk how this is formatted,
- stats: statsIncluded ? stats_1.cleanProfileStats(member === null || member === void 0 ? void 0 : member.stats) : undefined,
- minions: statsIncluded ? minions_1.cleanMinions(member) : undefined,
- fairy_souls: statsIncluded ? fairysouls_1.cleanFairySouls(member) : undefined,
+ stats: stats_1.cleanProfileStats(member),
+ minions: minions_1.cleanMinions(member),
+ fairy_souls: fairysouls_1.cleanFairySouls(member),
inventories: inventoriesIncluded ? await inventory_1.cleanInventories(member) : undefined,
+ objectives: objectives_1.cleanObjectives(member),
};
}
exports.cleanSkyBlockProfileMemberResponse = cleanSkyBlockProfileMemberResponse;
diff --git a/build/cleaners/skyblock/objectives.js b/build/cleaners/skyblock/objectives.js
new file mode 100644
index 0000000..d45307c
--- /dev/null
+++ b/build/cleaners/skyblock/objectives.js
@@ -0,0 +1,16 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.cleanObjectives = void 0;
+function cleanObjectives(data) {
+ const rawObjectives = (data === null || data === void 0 ? void 0 : data.objectives) || {};
+ const objectives = [];
+ for (const rawObjectiveName in rawObjectives) {
+ const rawObjectiveValue = rawObjectives[rawObjectiveName];
+ objectives.push({
+ name: rawObjectiveName,
+ completed: rawObjectiveValue.status === 'COMPLETE',
+ });
+ }
+ return objectives;
+}
+exports.cleanObjectives = cleanObjectives;
diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js
index 7ef57ef..2b18ff8 100644
--- a/build/cleaners/skyblock/profile.js
+++ b/build/cleaners/skyblock/profile.js
@@ -12,7 +12,7 @@ async function cleanSkyblockProfileResponseLighter(data) {
const memberRaw = data.members[memberUUID];
memberRaw.uuid = memberUUID;
// we pass an empty array to make it not check stats
- promises.push(member_1.cleanSkyBlockProfileMemberResponse(memberRaw, []));
+ promises.push(member_1.cleanSkyBlockProfileMemberResponseBasic(memberRaw));
}
const cleanedMembers = await Promise.all(promises);
return {
diff --git a/build/cleaners/skyblock/skills.js b/build/cleaners/skyblock/skills.js
new file mode 100644
index 0000000..4ec5ec2
--- /dev/null
+++ b/build/cleaners/skyblock/skills.js
@@ -0,0 +1,18 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.cleanSkills = void 0;
+function cleanSkills(data) {
+ const skills = [];
+ for (const item in data) {
+ if (item.startsWith('experience_skill_')) {
+ const skillName = item.substr('experience_skill_'.length);
+ const skillValue = data[item];
+ skills.push({
+ name: skillName,
+ xp: skillValue
+ });
+ }
+ }
+ return skills;
+}
+exports.cleanSkills = cleanSkills;
diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js
index aa026db..80686c1 100644
--- a/build/cleaners/skyblock/stats.js
+++ b/build/cleaners/skyblock/stats.js
@@ -52,14 +52,17 @@ function categorizeStat(statNameRaw) {
name: statNameRaw
};
}
-function cleanProfileStats(statsRaw) {
+function cleanProfileStats(data) {
+ var _a;
// TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there)
const stats = {};
- for (let statNameRaw in statsRaw) {
+ const rawStats = (_a = data === null || data === void 0 ? void 0 : data.stats) !== null && _a !== void 0 ? _a : {};
+ for (const statNameRaw in rawStats) {
+ const statValue = rawStats[statNameRaw];
let { category: statCategory, name: statName } = categorizeStat(statNameRaw);
if (!stats[statCategory])
stats[statCategory] = {};
- stats[statCategory][statName || 'total'] = statsRaw[statNameRaw];
+ stats[statCategory][statName || 'total'] = statValue;
}
return stats;
}
diff --git a/build/hypixel.js b/build/hypixel.js
index 9c67fe6..5c6ce4c 100644
--- a/build/hypixel.js
+++ b/build/hypixel.js
@@ -110,6 +110,16 @@ async function fetchMemberProfile(user, profile) {
const player = await cached.fetchPlayer(playerUuid);
const cleanProfile = await cached.fetchProfile(playerUuid, profileUuid);
const member = cleanProfile.members.find(m => m.uuid === playerUuid);
+ // remove unnecessary member data
+ const simpleMembers = cleanProfile.members.map(m => {
+ return {
+ uuid: m.uuid,
+ username: m.username,
+ first_join: m.first_join,
+ last_save: m.last_save,
+ };
+ });
+ cleanProfile.members = simpleMembers;
return {
member: {
// the profile name is in member rather than profile since they sometimes differ for each member
diff --git a/src/cleaners/skyblock/bank.ts b/src/cleaners/skyblock/bank.ts
index 302f392..4735bec 100644
--- a/src/cleaners/skyblock/bank.ts
+++ b/src/cleaners/skyblock/bank.ts
@@ -7,6 +7,7 @@ export function cleanBank(data: any): Bank {
return {
balance: data?.banking?.balance ?? 0,
// TODO: make transactions good
- history: data?.banking?.transactions ?? []
+ // history: data?.banking?.transactions ?? []
+ history: []
}
} \ No newline at end of file
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index d7d0cd1..04aa476 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -5,6 +5,7 @@ import { Bank } from './bank'
import { cleanFairySouls, FairySouls } from './fairysouls'
import { cleanInventories, INVENTORIES } from './inventory'
import { CleanMinion, cleanMinions } from './minions'
+import { cleanObjectives, Objective } from './objectives'
import { CleanFullProfile } from './profile'
import { CleanProfileStats, cleanProfileStats } from './stats'
@@ -16,29 +17,38 @@ export interface CleanBasicMember {
}
export interface CleanMember extends CleanBasicMember {
- stats?: CleanProfileStats
- minions?: CleanMinion[]
- bank?: Bank
- fairy_souls?: FairySouls
+ stats: CleanProfileStats
+ minions: CleanMinion[]
+ fairy_souls: FairySouls
inventories: typeof INVENTORIES
+ objectives: Objective[]
}
+export async function cleanSkyBlockProfileMemberResponseBasic(member, included: Included[] = null): Promise<CleanBasicMember> {
+ return {
+ uuid: member.uuid,
+ username: await cached.usernameFromUser(member.uuid),
+ last_save: member.last_save,
+ first_join: member.first_join,
+ }
+}
/** Cleans up a member (from skyblock/profile) */
export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> {
// profiles.members[]
- const statsIncluded = included == null || included.includes('stats')
const inventoriesIncluded = included == null || included.includes('inventories')
return {
uuid: member.uuid,
username: await cached.usernameFromUser(member.uuid),
last_save: member.last_save,
first_join: member.first_join,
- // last_death: ??? idk how this is formatted,
- stats: statsIncluded ? cleanProfileStats(member?.stats) : undefined,
- minions: statsIncluded ? cleanMinions(member) : undefined,
- fairy_souls: statsIncluded ? cleanFairySouls(member) : undefined,
- inventories: inventoriesIncluded ? await cleanInventories(member) : undefined,
+
+ stats: cleanProfileStats(member),
+ minions: cleanMinions(member),
+ fairy_souls: cleanFairySouls(member),
+ inventories: inventoriesIncluded ? await cleanInventories(member) : undefined,
+ objectives: cleanObjectives(member),
+ // skills: statsIncluded ?
}
}
diff --git a/src/cleaners/skyblock/objectives.ts b/src/cleaners/skyblock/objectives.ts
new file mode 100644
index 0000000..3427f1f
--- /dev/null
+++ b/src/cleaners/skyblock/objectives.ts
@@ -0,0 +1,17 @@
+export interface Objective {
+ name: string
+ completed: boolean
+}
+
+export function cleanObjectives(data: any): Objective[] {
+ const rawObjectives = data?.objectives || {}
+ const objectives: Objective[] = []
+ for (const rawObjectiveName in rawObjectives) {
+ const rawObjectiveValue = rawObjectives[rawObjectiveName]
+ objectives.push({
+ name: rawObjectiveName,
+ completed: rawObjectiveValue.status === 'COMPLETE',
+ })
+ }
+ return objectives
+}
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts
index b4a8574..2b092a1 100644
--- a/src/cleaners/skyblock/profile.ts
+++ b/src/cleaners/skyblock/profile.ts
@@ -1,4 +1,4 @@
-import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse } from './member'
+import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse, cleanSkyBlockProfileMemberResponseBasic } from './member'
import { CleanMinion, combineMinionArrays, countUniqueMinions } from './minions'
import { Bank, cleanBank } from './bank'
import { ApiOptions } from '../../hypixel'
@@ -8,7 +8,7 @@ export interface CleanProfile extends CleanBasicProfile {
}
export interface CleanFullProfile extends CleanProfile {
- members: CleanMember[]
+ members: (CleanMember|CleanBasicMember)[]
bank: Bank
minions: CleanMinion[]
minion_count: number
@@ -17,16 +17,16 @@ export interface CleanFullProfile extends CleanProfile {
/** Return a `CleanProfile` instead of a `CleanFullProfile`, useful when we need to get members but don't want to waste much ram */
export async function cleanSkyblockProfileResponseLighter(data): Promise<CleanProfile> {
// We use Promise.all so it can fetch all the usernames at once instead of waiting for the previous promise to complete
- const promises: Promise<CleanMember>[] = []
+ const promises: Promise<CleanBasicMember>[] = []
for (const memberUUID in data.members) {
const memberRaw = data.members[memberUUID]
memberRaw.uuid = memberUUID
// we pass an empty array to make it not check stats
- promises.push(cleanSkyBlockProfileMemberResponse(memberRaw, []))
+ promises.push(cleanSkyBlockProfileMemberResponseBasic(memberRaw))
}
- const cleanedMembers: CleanMember[] = await Promise.all(promises)
+ const cleanedMembers: CleanBasicMember[] = await Promise.all(promises)
return {
uuid: data.profile_id,
diff --git a/src/cleaners/skyblock/skills.ts b/src/cleaners/skyblock/skills.ts
new file mode 100644
index 0000000..e283379
--- /dev/null
+++ b/src/cleaners/skyblock/skills.ts
@@ -0,0 +1,19 @@
+export interface Skill {
+ name: string
+ xp: number
+}
+
+export function cleanSkills(data: any): Skill[] {
+ const skills: Skill[] = []
+ for (const item in data) {
+ if (item.startsWith('experience_skill_')) {
+ const skillName = item.substr('experience_skill_'.length)
+ const skillValue = data[item]
+ skills.push({
+ name: skillName,
+ xp: skillValue
+ })
+ }
+ }
+ return skills
+}
diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts
index 1222582..99aa1f7 100644
--- a/src/cleaners/skyblock/stats.ts
+++ b/src/cleaners/skyblock/stats.ts
@@ -61,13 +61,15 @@ export interface CleanProfileStats {
}
}
-export function cleanProfileStats(statsRaw: any): CleanProfileStats {
+export function cleanProfileStats(data: any): CleanProfileStats {
// TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there)
const stats: CleanProfileStats = {}
- for (let statNameRaw in statsRaw) {
+ const rawStats = data?.stats ?? {}
+ for (const statNameRaw in rawStats) {
+ const statValue = rawStats[statNameRaw]
let { category: statCategory, name: statName } = categorizeStat(statNameRaw)
if (!stats[statCategory]) stats[statCategory] = {}
- stats[statCategory][statName || 'total'] = statsRaw[statNameRaw]
+ stats[statCategory][statName || 'total'] = statValue
}
return stats
}
diff --git a/src/hypixel.ts b/src/hypixel.ts
index cc01478..8a955ab 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -5,7 +5,7 @@
import { CleanPlayer, cleanPlayerResponse } from './cleaners/player'
import { chooseApiKey, HypixelResponse, sendApiRequest } from './hypixelApi'
import * as cached from './hypixelCached'
-import { CleanMemberProfile } from './cleaners/skyblock/member'
+import { CleanBasicMember, CleanMemberProfile } from './cleaners/skyblock/member'
import { cleanSkyblockProfileResponse, CleanProfile, CleanBasicProfile } from './cleaners/skyblock/profile'
import { cleanSkyblockProfilesResponse } from './cleaners/skyblock/profiles'
@@ -132,6 +132,18 @@ export async function fetchMemberProfile(user: string, profile: string): Promise
const member = cleanProfile.members.find(m => m.uuid === playerUuid)
+ // remove unnecessary member data
+ const simpleMembers: CleanBasicMember[] = cleanProfile.members.map(m => {
+ return {
+ uuid: m.uuid,
+ username: m.username,
+ first_join: m.first_join,
+ last_save: m.last_save,
+ }
+ })
+
+ cleanProfile.members = simpleMembers
+
return {
member: {
// the profile name is in member rather than profile since they sometimes differ for each member