aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-02-13 16:23:28 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-02-13 16:23:28 -0600
commitdd513537e240bbaf12c4f204d49db88111633d98 (patch)
treee51cb050b2ff8748066420a78f15106770b237a4
parent43f194ff780d704834706ac6da454a8858098906 (diff)
downloadskyblock-api-dd513537e240bbaf12c4f204d49db88111633d98.tar.gz
skyblock-api-dd513537e240bbaf12c4f204d49db88111633d98.tar.bz2
skyblock-api-dd513537e240bbaf12c4f204d49db88111633d98.zip
add fairy souls
-rw-r--r--build/cleaners/skyblock/minions.js11
-rw-r--r--build/cleaners/skyblock/profile.js2
-rw-r--r--src/cleaners/skyblock/bank.ts2
-rw-r--r--src/cleaners/skyblock/fairysouls.ts14
-rw-r--r--src/cleaners/skyblock/member.ts5
-rw-r--r--src/cleaners/skyblock/minions.ts4
-rw-r--r--src/cleaners/skyblock/profile.ts12
-rw-r--r--src/hypixelApi.ts3
8 files changed, 39 insertions, 14 deletions
diff --git a/build/cleaners/skyblock/minions.js b/build/cleaners/skyblock/minions.js
index 289da1a..777db9b 100644
--- a/build/cleaners/skyblock/minions.js
+++ b/build/cleaners/skyblock/minions.js
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.combineMinionArrays = exports.cleanMinions = void 0;
+exports.countUniqueMinions = exports.combineMinionArrays = exports.cleanMinions = void 0;
const hypixel_1 = require("../../hypixel");
/**
* Clean the minions provided by Hypixel
@@ -61,3 +61,12 @@ function combineMinionArrays(minions) {
return resultMinions;
}
exports.combineMinionArrays = combineMinionArrays;
+function countUniqueMinions(minions) {
+ let uniqueMinions = 0;
+ for (const minion of minions) {
+ // find the number of times `true` is in the list and add it to uniqueMinions
+ uniqueMinions += minion.levels.filter(x => x).length;
+ }
+ return uniqueMinions;
+}
+exports.countUniqueMinions = countUniqueMinions;
diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js
index aa5433e..86e21a3 100644
--- a/build/cleaners/skyblock/profile.js
+++ b/build/cleaners/skyblock/profile.js
@@ -81,6 +81,7 @@ async function fetchMemberProfile(user, profile) {
const member = cleanProfile.members.find(m => m.uuid === playerUuid);
return {
member: {
+ // the profile name is in member rather than profile since they sometimes differ for each member
profileName: cleanProfile.name,
first_join: member.first_join,
last_save: member.last_save,
@@ -91,6 +92,7 @@ async function fetchMemberProfile(user, profile) {
uuid: cleanProfile.uuid,
bank: cleanProfile.bank,
minions: cleanProfile.minions,
+ minion_count: minions_1.countUniqueMinions(cleanProfile.minions)
}
};
}
diff --git a/src/cleaners/skyblock/bank.ts b/src/cleaners/skyblock/bank.ts
index 7db7a37..302f392 100644
--- a/src/cleaners/skyblock/bank.ts
+++ b/src/cleaners/skyblock/bank.ts
@@ -1,5 +1,3 @@
-import { cleanSkyblockProfileResponseLighter } from "./profile"
-
export interface Bank {
balance: number
history: any[]
diff --git a/src/cleaners/skyblock/fairysouls.ts b/src/cleaners/skyblock/fairysouls.ts
new file mode 100644
index 0000000..11bbc9e
--- /dev/null
+++ b/src/cleaners/skyblock/fairysouls.ts
@@ -0,0 +1,14 @@
+export interface FairySouls {
+ total: number
+ /** The number of fairy souls that haven't been exchanged yet */
+ unexchanged: number
+ exchanges: number
+}
+
+export function cleanFairySouls(data: any): FairySouls {
+ return {
+ total: data?.fairy_souls_collected ?? 0,
+ unexchanged: data?.fairy_souls ?? 0,
+ exchanges: data?.fairy_exchanges ?? 0,
+ }
+} \ No newline at end of file
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index 43bd9fd..8695b3f 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -2,6 +2,7 @@ import { Included } from '../../hypixel'
import * as cached from '../../hypixelCached'
import { CleanPlayer } from '../player'
import { Bank, cleanBank } from './bank'
+import { cleanFairySouls, FairySouls } from './fairysouls'
import { CleanMinion, cleanMinions } from './minions'
import { CleanProfileStats, cleanProfileStats } from './stats'
@@ -16,6 +17,7 @@ export interface CleanMember extends CleanBasicMember {
stats?: CleanProfileStats
minions?: CleanMinion[]
bank?: Bank
+ fairy_souls?: FairySouls
}
@@ -30,7 +32,8 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu
first_join: member.first_join,
// last_death: ??? idk how this is formatted,
stats: statsIncluded ? cleanProfileStats(member?.stats) : undefined,
- minions: statsIncluded ? cleanMinions(member?.crafted_generators) : undefined,
+ minions: statsIncluded ? cleanMinions(member) : undefined,
+ fairy_souls: statsIncluded ? cleanFairySouls(member) : undefined
}
}
diff --git a/src/cleaners/skyblock/minions.ts b/src/cleaners/skyblock/minions.ts
index b5ac85d..06e7752 100644
--- a/src/cleaners/skyblock/minions.ts
+++ b/src/cleaners/skyblock/minions.ts
@@ -10,9 +10,9 @@ export interface CleanMinion {
* Clean the minions provided by Hypixel
* @param minionsRaw The minion data provided by the Hypixel API
*/
-export function cleanMinions(minionsRaw: string[]): CleanMinion[] {
+export function cleanMinions(data: any): CleanMinion[] {
const minions: CleanMinion[] = []
- for (const minionRaw of minionsRaw ?? []) {
+ for (const minionRaw of data?.crafted_generators ?? []) {
// do some regex magic to get the minion name and level
// examples of potential minion names: CLAY_11, PIG_1, MAGMA_CUBE_4
const minionName = minionRaw.split(/_\d/)[0].toLowerCase()
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts
index 5d2b7a3..8389a0d 100644
--- a/src/cleaners/skyblock/profile.ts
+++ b/src/cleaners/skyblock/profile.ts
@@ -1,7 +1,8 @@
import { CleanBasicMember, CleanMember, CleanMemberProfile, cleanSkyBlockProfileMemberResponse } from './member'
import { CleanMinion, combineMinionArrays, countUniqueMinions } from './minions'
import * as cached from '../../hypixelCached'
-import { cleanBank } from './bank'
+import { Bank, cleanBank } from './bank'
+import { cleanFairySouls, FairySouls } from './fairysouls'
export interface CleanProfile extends CleanBasicProfile {
members?: CleanBasicMember[]
@@ -9,10 +10,7 @@ export interface CleanProfile extends CleanBasicProfile {
export interface CleanFullProfile extends CleanProfile {
members: CleanMember[]
- bank?: {
- balance: number
- history: any[]
- }
+ bank?: Bank
minions: CleanMinion[]
}
@@ -94,8 +92,8 @@ export async function fetchMemberProfile(user: string, profile: string): Promise
member: {
// the profile name is in member rather than profile since they sometimes differ for each member
profileName: cleanProfile.name,
- first_join: member.first_join,
- last_save: member.last_save,
+ // add all the member data
+ ...member,
// add all other data relating to the hypixel player, such as username, rank, etc
...player
},
diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts
index 8387f73..5b5e20f 100644
--- a/src/hypixelApi.ts
+++ b/src/hypixelApi.ts
@@ -152,7 +152,8 @@ export async function sendApiRequest({ path, key, args }): Promise<HypixelRespon
const fetchJsonParsed = await fetchResponse.json()
if (fetchJsonParsed.throttle) {
- apiKeyUsage[key].remaining = 0
+ if (apiKeyUsage[key])
+ apiKeyUsage[key].remaining = 0
console.log('throttled :(')
return { throttled: true }
}