aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-02-13 15:57:09 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-02-13 15:57:09 -0600
commit604cf4233e3d69d7769d330c4f31876950a0e83d (patch)
treeb28ae09a5e7a3d280d8a939d2f4bdcbe62d80c3d
parent07496ac87ce982200474cc0af4afdf9665e6480c (diff)
downloadskyblock-api-604cf4233e3d69d7769d330c4f31876950a0e83d.tar.gz
skyblock-api-604cf4233e3d69d7769d330c4f31876950a0e83d.tar.bz2
skyblock-api-604cf4233e3d69d7769d330c4f31876950a0e83d.zip
tsc
-rw-r--r--build/cleaners/skyblock/bank.js12
-rw-r--r--build/cleaners/skyblock/member.js4
-rw-r--r--build/cleaners/skyblock/profile.js59
-rw-r--r--build/cleaners/skyblock/profiles.js1
-rw-r--r--build/hypixel.js28
-rw-r--r--build/hypixelApi.js6
-rw-r--r--build/index.js5
7 files changed, 74 insertions, 41 deletions
diff --git a/build/cleaners/skyblock/bank.js b/build/cleaners/skyblock/bank.js
new file mode 100644
index 0000000..a3db577
--- /dev/null
+++ b/build/cleaners/skyblock/bank.js
@@ -0,0 +1,12 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.cleanBank = void 0;
+function cleanBank(data) {
+ var _a, _b, _c, _d;
+ 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 : []
+ };
+}
+exports.cleanBank = cleanBank;
diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js
index b10a619..6c43cff 100644
--- a/build/cleaners/skyblock/member.js
+++ b/build/cleaners/skyblock/member.js
@@ -33,8 +33,8 @@ async function cleanSkyBlockProfileMemberResponse(member, included = null) {
last_save: member.last_save,
first_join: member.first_join,
// last_death: ??? idk how this is formatted,
- stats: statsIncluded ? stats_1.cleanProfileStats(member.stats) : undefined,
- minions: statsIncluded ? minions_1.cleanMinions(member.crafted_generators) : undefined,
+ 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,
};
}
exports.cleanSkyBlockProfileMemberResponse = cleanSkyBlockProfileMemberResponse;
diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js
index fe6a8f2..aa5433e 100644
--- a/build/cleaners/skyblock/profile.js
+++ b/build/cleaners/skyblock/profile.js
@@ -1,8 +1,29 @@
"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.cleanSkyblockProfileResponse = exports.cleanSkyblockProfileResponseLighter = void 0;
+exports.fetchMemberProfile = 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) {
// We use Promise.all so it can fetch all the usernames at once instead of waiting for the previous promise to complete
@@ -23,7 +44,6 @@ async function cleanSkyblockProfileResponseLighter(data) {
exports.cleanSkyblockProfileResponseLighter = cleanSkyblockProfileResponseLighter;
/** This function is somewhat costly and shouldn't be called often. Use cleanSkyblockProfileResponseLighter if you don't need all the data */
async function cleanSkyblockProfileResponse(data) {
- var _a, _b, _c, _d;
const cleanedMembers = [];
for (const memberUUID in data.members) {
const memberRaw = data.members[memberUUID];
@@ -41,12 +61,37 @@ async function cleanSkyblockProfileResponse(data) {
uuid: data.profile_id,
name: data.cute_name,
members: cleanedMembers,
- bank: {
- 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 : []
- },
+ bank: bank_1.cleanBank(data),
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: {
+ 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,
+ }
+ };
+}
+exports.fetchMemberProfile = fetchMemberProfile;
diff --git a/build/cleaners/skyblock/profiles.js b/build/cleaners/skyblock/profiles.js
index b79fc56..b481e09 100644
--- a/build/cleaners/skyblock/profiles.js
+++ b/build/cleaners/skyblock/profiles.js
@@ -10,7 +10,6 @@ function cleanPlayerSkyblockProfiles(rawProfiles) {
name: profile.cute_name
});
}
- console.log('cleanPlayerSkyblockProfiles', profiles);
return profiles;
}
exports.cleanPlayerSkyblockProfiles = cleanPlayerSkyblockProfiles;
diff --git a/build/hypixel.js b/build/hypixel.js
index 61a8518..f651a66 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.fetchMemberProfile = exports.fetchUser = exports.sendCleanApiRequest = exports.maxMinion = exports.saveInterval = void 0;
+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,29 +108,3 @@ 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: {
- 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
- }
- };
-}
-exports.fetchMemberProfile = fetchMemberProfile;
diff --git a/build/hypixelApi.js b/build/hypixelApi.js
index 2d9d10d..c1fc87a 100644
--- a/build/hypixelApi.js
+++ b/build/hypixelApi.js
@@ -10,12 +10,14 @@ exports.sendApiRequest = exports.chooseApiKey = void 0;
const node_fetch_1 = __importDefault(require("node-fetch"));
const util_1 = require("./util");
const https_1 = require("https");
-require('dotenv').config();
+if (!process.env.hypixel_keys)
+ // if there's no hypixel keys in env, run dotenv
+ require('dotenv').config();
// We need to create an agent to prevent memory leaks and to only do dns lookups once
const httpsAgent = new https_1.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(' ');
const apiKeyUsage = {};
const baseHypixelAPI = 'https://api.hypixel.net';
diff --git a/build/index.js b/build/index.js
index 91fdc29..7e5b89e 100644
--- a/build/index.js
+++ b/build/index.js
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-const express_1 = __importDefault(require("express"));
+const profile_1 = require("./cleaners/skyblock/profile");
const hypixel_1 = require("./hypixel");
+const express_1 = __importDefault(require("express"));
const app = express_1.default();
app.use((req, res, next) => {
if (process.env.key && req.headers.key !== process.env.key)
@@ -20,6 +21,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 hypixel_1.fetchMemberProfile(req.params.user, req.params.profile));
+ res.json(await profile_1.fetchMemberProfile(req.params.user, req.params.profile));
});
app.listen(8080, () => console.log('App started :)'));