aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cleaners/skyblock/bank.ts14
-rw-r--r--src/cleaners/skyblock/member.ts11
-rw-r--r--src/cleaners/skyblock/profile.ts44
-rw-r--r--src/cleaners/skyblock/profiles.ts1
-rw-r--r--src/hypixel.ts30
-rw-r--r--src/hypixelApi.ts3
-rw-r--r--src/index.ts3
7 files changed, 59 insertions, 47 deletions
diff --git a/src/cleaners/skyblock/bank.ts b/src/cleaners/skyblock/bank.ts
new file mode 100644
index 0000000..7db7a37
--- /dev/null
+++ b/src/cleaners/skyblock/bank.ts
@@ -0,0 +1,14 @@
+import { cleanSkyblockProfileResponseLighter } from "./profile"
+
+export interface Bank {
+ balance: number
+ history: any[]
+}
+
+export function cleanBank(data: any): Bank {
+ return {
+ balance: data?.banking?.balance ?? 0,
+ // TODO: make transactions good
+ history: data?.banking?.transactions ?? []
+ }
+} \ No newline at end of file
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index 774dace..43bd9fd 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -1,6 +1,7 @@
import { Included } from '../../hypixel'
import * as cached from '../../hypixelCached'
import { CleanPlayer } from '../player'
+import { Bank, cleanBank } from './bank'
import { CleanMinion, cleanMinions } from './minions'
import { CleanProfileStats, cleanProfileStats } from './stats'
@@ -14,6 +15,7 @@ export interface CleanBasicMember {
export interface CleanMember extends CleanBasicMember {
stats?: CleanProfileStats
minions?: CleanMinion[]
+ bank?: Bank
}
@@ -27,8 +29,8 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu
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.crafted_generators) : undefined,
+ stats: statsIncluded ? cleanProfileStats(member?.stats) : undefined,
+ minions: statsIncluded ? cleanMinions(member?.crafted_generators) : undefined,
}
}
@@ -38,10 +40,7 @@ export interface CleanMemberProfilePlayer extends CleanPlayer {
profileName: string
first_join: number
last_save: number
- bank?: {
- balance: number
- history: any[]
- }
+ bank?: Bank
}
export interface CleanMemberProfile {
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts
index 8b59a9d..c61e6cf 100644
--- a/src/cleaners/skyblock/profile.ts
+++ b/src/cleaners/skyblock/profile.ts
@@ -1,6 +1,7 @@
-import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse } from './member'
+import { CleanBasicMember, CleanMember, CleanMemberProfile, cleanSkyBlockProfileMemberResponse } from './member'
import { CleanMinion, combineMinionArrays } from './minions'
-
+import * as cached from '../../hypixelCached'
+import { cleanBank } from './bank'
export interface CleanProfile extends CleanBasicProfile {
members?: CleanBasicMember[]
@@ -59,12 +60,7 @@ export async function cleanSkyblockProfileResponse(data: any): Promise<CleanFull
uuid: data.profile_id,
name: data.cute_name,
members: cleanedMembers,
- bank: {
- balance: data?.banking?.balance ?? 0,
-
- // TODO: make transactions good
- history: data?.banking?.transactions ?? []
- },
+ bank: cleanBank(data),
minions
}
}
@@ -77,3 +73,35 @@ export interface CleanBasicProfile {
name?: string
}
+// TODO: this should be moved and split up
+/**
+ * Fetch a CleanMemberProfile from a user and string
+ * This is safe to use many times as the results are cached!
+ * @param user A username or uuid
+ * @param profile A profile name or profile uuid
+ */
+export async function fetchMemberProfile(user: string, profile: string): Promise<CleanMemberProfile> {
+ const playerUuid = await cached.uuidFromUser(user)
+ const profileUuid = await cached.fetchProfileUuid(user, profile)
+
+ const player = await cached.fetchPlayer(playerUuid)
+
+ const cleanProfile = await cached.fetchProfile(playerUuid, profileUuid)
+
+ const member = cleanProfile.members.find(m => m.uuid === playerUuid)
+
+ return {
+ member: {
+ profileName: cleanProfile.name,
+ first_join: member.first_join,
+ last_save: member.last_save,
+ // add all other data relating to the hypixel player, such as username, rank, etc
+ ...player
+ },
+ profile: {
+ uuid: cleanProfile.uuid,
+ bank: cleanProfile.bank,
+ minions: cleanProfile.minions,
+ }
+ }
+}
diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts
index c942a14..5eea8fb 100644
--- a/src/cleaners/skyblock/profiles.ts
+++ b/src/cleaners/skyblock/profiles.ts
@@ -9,7 +9,6 @@ export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBl
name: profile.cute_name
})
}
- console.log('cleanPlayerSkyblockProfiles', profiles)
return profiles
}
diff --git a/src/hypixel.ts b/src/hypixel.ts
index 0d3e9ea..5a13845 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -116,33 +116,3 @@ export async function fetchUser({ user, uuid, username }: UserAny, included: Inc
}
}
-/**
- * Fetch a CleanMemberProfile from a user and string
- * This is safe to use many times as the results are cached!
- * @param user A username or uuid
- * @param profile A profile name or profile uuid
- */
-export async function fetchMemberProfile(user: string, profile: string): Promise<CleanMemberProfile> {
- const playerUuid = await cached.uuidFromUser(user)
- const profileUuid = await cached.fetchProfileUuid(user, profile)
-
- const player = await cached.fetchPlayer(playerUuid)
-
- const cleanProfile = await cached.fetchProfile(playerUuid, profileUuid)
-
- const member = cleanProfile.members.find(m => m.uuid === playerUuid)
-
- return {
- member: {
- profileName: cleanProfile.name,
- first_join: member.first_join,
- last_save: member.last_save,
-
- // add all other data relating to the hypixel player, such as username, rank, etc
- ...player
- },
- profile: {
- minions: cleanProfile.minions
- }
- }
-}
diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts
index 2f66343..8387f73 100644
--- a/src/hypixelApi.ts
+++ b/src/hypixelApi.ts
@@ -14,8 +14,8 @@ const httpsAgent = new Agent({
keepAlive: true
})
-/* Lower level code related to the Hypixel api */
+/** This array should only ever contain one item because using multiple hypixel api keys isn't allowed :) */
const apiKeys = process.env.hypixel_keys.split(' ')
interface KeyUsage {
@@ -29,6 +29,7 @@ const apiKeyUsage: { [ key: string ]: KeyUsage } = {}
const baseHypixelAPI = 'https://api.hypixel.net'
+
/** Choose the best current API key */
export function chooseApiKey(): string {
// find the api key with the lowest amount of uses
diff --git a/src/index.ts b/src/index.ts
index 4ceda01..6b55923 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,6 @@
+import { fetchMemberProfile } from './cleaners/skyblock/profile'
+import { fetchUser } from './hypixel'
import express from 'express'
-import { fetchMemberProfile, fetchUser } from './hypixel'
const app = express()