aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-02-13 16:28:26 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-02-13 16:28:26 -0600
commit5c9ef89af1ee9af380ea82072a3a48d5db0f2c7a (patch)
tree8d3f2fc286a7f18931b1d561cf376b897e8f6d18 /src
parentdd513537e240bbaf12c4f204d49db88111633d98 (diff)
downloadskyblock-api-5c9ef89af1ee9af380ea82072a3a48d5db0f2c7a.tar.gz
skyblock-api-5c9ef89af1ee9af380ea82072a3a48d5db0f2c7a.tar.bz2
skyblock-api-5c9ef89af1ee9af380ea82072a3a48d5db0f2c7a.zip
move some code to make more sense
Diffstat (limited to 'src')
-rw-r--r--src/cleaners/skyblock/profile.ts40
-rw-r--r--src/hypixel.ts28
-rw-r--r--src/index.ts3
3 files changed, 33 insertions, 38 deletions
diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts
index 8389a0d..742c9ed 100644
--- a/src/cleaners/skyblock/profile.ts
+++ b/src/cleaners/skyblock/profile.ts
@@ -10,8 +10,9 @@ export interface CleanProfile extends CleanBasicProfile {
export interface CleanFullProfile extends CleanProfile {
members: CleanMember[]
- bank?: Bank
+ bank: Bank
minions: CleanMinion[]
+ minion_count: number
}
/** Return a `CleanProfile` instead of a `CleanFullProfile`, useful when we need to get members but don't want to waste much ram */
@@ -59,7 +60,8 @@ export async function cleanSkyblockProfileResponse(data: any): Promise<CleanFull
name: data.cute_name,
members: cleanedMembers,
bank: cleanBank(data),
- minions
+ minions: minions,
+ minion_count: countUniqueMinions(minions)
}
}
@@ -71,37 +73,3 @@ 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: {
- // the profile name is in member rather than profile since they sometimes differ for each member
- profileName: cleanProfile.name,
- // add all the member data
- ...member,
- // 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,
- minion_count: countUniqueMinions(cleanProfile.minions)
- }
- }
-}
diff --git a/src/hypixel.ts b/src/hypixel.ts
index 5a13845..bbfc7d2 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -116,3 +116,31 @@ 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: {
+ // the profile name is in member rather than profile since they sometimes differ for each member
+ profileName: cleanProfile.name,
+ // add all the member data
+ ...member,
+ // add all other data relating to the hypixel player, such as username, rank, etc
+ ...player
+ },
+ profile: cleanProfile
+ }
+}
diff --git a/src/index.ts b/src/index.ts
index 6b55923..c0047ad 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,4 @@
-import { fetchMemberProfile } from './cleaners/skyblock/profile'
-import { fetchUser } from './hypixel'
+import { fetchMemberProfile, fetchUser } from './hypixel'
import express from 'express'
const app = express()