aboutsummaryrefslogtreecommitdiff
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
parentdd513537e240bbaf12c4f204d49db88111633d98 (diff)
downloadskyblock-api-5c9ef89af1ee9af380ea82072a3a48d5db0f2c7a.tar.gz
skyblock-api-5c9ef89af1ee9af380ea82072a3a48d5db0f2c7a.tar.bz2
skyblock-api-5c9ef89af1ee9af380ea82072a3a48d5db0f2c7a.zip
move some code to make more sense
-rw-r--r--build/cleaners/skyblock/fairysouls.js12
-rw-r--r--build/cleaners/skyblock/member.js4
-rw-r--r--build/cleaners/skyblock/minions.js5
-rw-r--r--build/cleaners/skyblock/profile.js56
-rw-r--r--build/hypixel.js27
-rw-r--r--build/hypixelApi.js3
-rw-r--r--build/index.js3
-rw-r--r--src/cleaners/skyblock/profile.ts40
-rw-r--r--src/hypixel.ts28
-rw-r--r--src/index.ts3
10 files changed, 83 insertions, 98 deletions
diff --git a/build/cleaners/skyblock/fairysouls.js b/build/cleaners/skyblock/fairysouls.js
new file mode 100644
index 0000000..1c6cef6
--- /dev/null
+++ b/build/cleaners/skyblock/fairysouls.js
@@ -0,0 +1,12 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.cleanFairySouls = void 0;
+function cleanFairySouls(data) {
+ var _a, _b, _c;
+ return {
+ total: (_a = data === null || data === void 0 ? void 0 : data.fairy_souls_collected) !== null && _a !== void 0 ? _a : 0,
+ unexchanged: (_b = data === null || data === void 0 ? void 0 : data.fairy_souls) !== null && _b !== void 0 ? _b : 0,
+ exchanges: (_c = data === null || data === void 0 ? void 0 : data.fairy_exchanges) !== null && _c !== void 0 ? _c : 0,
+ };
+}
+exports.cleanFairySouls = cleanFairySouls;
diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js
index 6c43cff..736593a 100644
--- a/build/cleaners/skyblock/member.js
+++ b/build/cleaners/skyblock/member.js
@@ -21,6 +21,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanSkyBlockProfileMemberResponse = void 0;
const cached = __importStar(require("../../hypixelCached"));
+const fairysouls_1 = require("./fairysouls");
const minions_1 = require("./minions");
const stats_1 = require("./stats");
/** Cleans up a member (from skyblock/profile) */
@@ -34,7 +35,8 @@ async function cleanSkyBlockProfileMemberResponse(member, included = null) {
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 === null || member === void 0 ? void 0 : member.crafted_generators) : undefined,
+ minions: statsIncluded ? minions_1.cleanMinions(member) : undefined,
+ fairy_souls: statsIncluded ? fairysouls_1.cleanFairySouls(member) : undefined
};
}
exports.cleanSkyBlockProfileMemberResponse = cleanSkyBlockProfileMemberResponse;
diff --git a/build/cleaners/skyblock/minions.js b/build/cleaners/skyblock/minions.js
index 777db9b..0543e92 100644
--- a/build/cleaners/skyblock/minions.js
+++ b/build/cleaners/skyblock/minions.js
@@ -6,9 +6,10 @@ const hypixel_1 = require("../../hypixel");
* Clean the minions provided by Hypixel
* @param minionsRaw The minion data provided by the Hypixel API
*/
-function cleanMinions(minionsRaw) {
+function cleanMinions(data) {
+ var _a;
const minions = [];
- for (const minionRaw of minionsRaw !== null && minionsRaw !== void 0 ? minionsRaw : []) {
+ for (const minionRaw of (_a = data === null || data === void 0 ? void 0 : data.crafted_generators) !== null && _a !== void 0 ? _a : []) {
// 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/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js
index 86e21a3..5804bb5 100644
--- a/build/cleaners/skyblock/profile.js
+++ b/build/cleaners/skyblock/profile.js
@@ -1,28 +1,8 @@
"use strict";
-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
-}) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
-}));
-var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
- Object.defineProperty(o, "default", { enumerable: true, value: v });
-}) : function(o, v) {
- o["default"] = v;
-});
-var __importStar = (this && this.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
- __setModuleDefault(result, mod);
- return result;
-};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.fetchMemberProfile = exports.cleanSkyblockProfileResponse = exports.cleanSkyblockProfileResponseLighter = void 0;
+exports.cleanSkyblockProfileResponse = exports.cleanSkyblockProfileResponseLighter = void 0;
const member_1 = require("./member");
const minions_1 = require("./minions");
-const cached = __importStar(require("../../hypixelCached"));
const bank_1 = require("./bank");
/** Return a `CleanProfile` instead of a `CleanFullProfile`, useful when we need to get members but don't want to waste much ram */
async function cleanSkyblockProfileResponseLighter(data) {
@@ -62,38 +42,8 @@ async function cleanSkyblockProfileResponse(data) {
name: data.cute_name,
members: cleanedMembers,
bank: bank_1.cleanBank(data),
- minions
+ minions: minions,
+ minion_count: minions_1.countUniqueMinions(minions)
};
}
exports.cleanSkyblockProfileResponse = cleanSkyblockProfileResponse;
-// 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
- */
-async function fetchMemberProfile(user, profile) {
- 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,
- 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,
- minion_count: minions_1.countUniqueMinions(cleanProfile.minions)
- }
- };
-}
-exports.fetchMemberProfile = fetchMemberProfile;
diff --git a/build/hypixel.js b/build/hypixel.js
index f651a66..847fbdb 100644
--- a/build/hypixel.js
+++ b/build/hypixel.js
@@ -22,7 +22,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.fetchUser = exports.sendCleanApiRequest = exports.maxMinion = exports.saveInterval = void 0;
+exports.fetchMemberProfile = exports.fetchUser = exports.sendCleanApiRequest = exports.maxMinion = exports.saveInterval = void 0;
const player_1 = require("./cleaners/player");
const hypixelApi_1 = require("./hypixelApi");
const cached = __importStar(require("./hypixelCached"));
@@ -108,3 +108,28 @@ async function fetchUser({ user, uuid, username }, included = ['player']) {
};
}
exports.fetchUser = fetchUser;
+/**
+ * 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
+ */
+async function fetchMemberProfile(user, profile) {
+ 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
+ };
+}
+exports.fetchMemberProfile = fetchMemberProfile;
diff --git a/build/hypixelApi.js b/build/hypixelApi.js
index c1fc87a..c9621eb 100644
--- a/build/hypixelApi.js
+++ b/build/hypixelApi.js
@@ -62,7 +62,8 @@ async function sendApiRequest({ path, key, args }) {
};
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 };
}
diff --git a/build/index.js b/build/index.js
index 7e5b89e..383ea1d 100644
--- a/build/index.js
+++ b/build/index.js
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-const profile_1 = require("./cleaners/skyblock/profile");
const hypixel_1 = require("./hypixel");
const express_1 = __importDefault(require("express"));
const app = express_1.default();
@@ -21,6 +20,6 @@ app.get('/player/:user', async (req, res) => {
res.json(await hypixel_1.fetchUser({ user: req.params.user }, ['profiles', 'player']));
});
app.get('/player/:user/:profile', async (req, res) => {
- res.json(await profile_1.fetchMemberProfile(req.params.user, req.params.profile));
+ res.json(await hypixel_1.fetchMemberProfile(req.params.user, req.params.profile));
});
app.listen(8080, () => console.log('App started :)'));
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()