aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat-1 <github@matdoes.dev>2021-03-01 23:22:14 +0000
committermat-1 <github@matdoes.dev>2021-03-01 23:22:14 +0000
commit8149ae89e8861679693536cddfd8a8f25374577d (patch)
tree78913de68e144f570453a60758364236e41d6c0a
parent5967be8d5666b47cba169df5eb3a2eacd87fb844 (diff)
downloadskyblock-api-8149ae89e8861679693536cddfd8a8f25374577d.tar.gz
skyblock-api-8149ae89e8861679693536cddfd8a8f25374577d.tar.bz2
skyblock-api-8149ae89e8861679693536cddfd8a8f25374577d.zip
Compiled TS into JS
-rw-r--r--build/cleaners/skyblock/stats.js3
-rw-r--r--build/database.js27
-rw-r--r--build/hypixel.js4
3 files changed, 30 insertions, 4 deletions
diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js
index d7aa984..9c6966f 100644
--- a/build/cleaners/skyblock/stats.js
+++ b/build/cleaners/skyblock/stats.js
@@ -6,9 +6,10 @@ const statCategories = {
'kills': ['kills_', 'kills'],
'fishing': ['items_fished_', 'items_fished', 'shredder_'],
'auctions': ['auctions_'],
- 'collection': ['collection_'],
'races': ['_best_time', '_best_time_2'],
'mythos': ['mythos_burrows_', 'mythos_kills'],
+ 'collection': ['collection_'],
+ 'skills': ['skill_'],
'misc': null // everything else goes here
};
function categorizeStat(statNameRaw) {
diff --git a/build/database.js b/build/database.js
index ec1cbb2..d28d934 100644
--- a/build/database.js
+++ b/build/database.js
@@ -25,13 +25,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.updateDatabaseMember = exports.fetchMemberLeaderboard = exports.fetchAllMemberLeaderboardAttributes = exports.fetchAllLeaderboardsCategorized = void 0;
+exports.queueUpdateDatabaseMember = exports.updateDatabaseMember = exports.fetchMemberLeaderboard = exports.fetchAllMemberLeaderboardAttributes = exports.fetchAllLeaderboardsCategorized = void 0;
const constants = __importStar(require("./constants"));
const cached = __importStar(require("./hypixelCached"));
const mongodb_1 = require("mongodb");
const node_cache_1 = __importDefault(require("node-cache"));
const util_1 = require("./util");
const stats_1 = require("./cleaners/skyblock/stats");
+const queue_promise_1 = __importDefault(require("queue-promise"));
// don't update the user for 3 minutes
const recentlyUpdated = new node_cache_1.default({
stdTTL: 60 * 3,
@@ -64,6 +65,14 @@ function getMemberCollectionAttributes(member) {
}
return collectionAttributes;
}
+function getMemberSkillAttributes(member) {
+ const skillAttributes = {};
+ for (const collection of member.skills) {
+ const skillLeaderboardName = `skill_${collection.name}`;
+ skillAttributes[skillLeaderboardName] = collection.xp;
+ }
+ return skillAttributes;
+}
function getMemberLeaderboardAttributes(member) {
// if you want to add a new leaderboard for member attributes, add it here (and getAllLeaderboardAttributes)
return {
@@ -71,6 +80,8 @@ function getMemberLeaderboardAttributes(member) {
...member.rawHypixelStats,
// collection leaderboards
...getMemberCollectionAttributes(member),
+ // skill leaderboards
+ ...getMemberSkillAttributes(member),
fairy_souls: member.fairy_souls.total,
first_join: member.first_join,
purse: member.purse,
@@ -100,6 +111,8 @@ async function fetchAllMemberLeaderboardAttributes() {
...await constants.fetchStats(),
// collection leaderboards
...(await constants.fetchCollections()).map(value => `collection_${value}`),
+ // skill leaderboards
+ ...(await constants.fetchSkills()).map(value => `skill_${value}`),
'fairy_souls',
'first_join',
'purse',
@@ -162,11 +175,13 @@ async function getApplicableAttributes(member) {
const requirement = await getMemberLeaderboardRequirement(attributeName);
if (!requirement || attributeValue > requirement)
applicableAttributes[attributeName] = attributeValue;
+ console.log(attributeName);
}
return applicableAttributes;
}
/** Update the member's leaderboard data on the server if applicable */
async function updateDatabaseMember(member, profile) {
+ console.log('updating', member.uuid);
if (!client)
return; // the db client hasn't been initialized
// the member's been updated too recently, just return
@@ -203,8 +218,18 @@ async function updateDatabaseMember(member, profile) {
.slice(0, 100);
cachedRawLeaderboards.set(attributeName, newRawLeaderboard);
}
+ console.log('updated', member.uuid);
}
exports.updateDatabaseMember = updateDatabaseMember;
+const queue = new queue_promise_1.default({
+ concurrent: 3,
+ interval: 500
+});
+/** Queue an update for the member's leaderboard data on the server if applicable */
+async function queueUpdateDatabaseMember(member, profile) {
+ queue.enqueue(async () => await updateDatabaseMember(member, profile));
+}
+exports.queueUpdateDatabaseMember = queueUpdateDatabaseMember;
/**
* Remove leaderboard attributes for members that wouldn't actually be on the leaderboard. This saves a lot of storage space
*/
diff --git a/build/hypixel.js b/build/hypixel.js
index 17d7355..1ea844a 100644
--- a/build/hypixel.js
+++ b/build/hypixel.js
@@ -156,7 +156,7 @@ async function fetchMemberProfileUncached(playerUuid, profileUuid) {
args: { profile: profileUuid }
}, null, { mainMemberUuid: playerUuid });
for (const member of profile.members)
- database_1.updateDatabaseMember(member, profile);
+ database_1.queueUpdateDatabaseMember(member, profile);
return profile;
}
exports.fetchMemberProfileUncached = fetchMemberProfileUncached;
@@ -172,7 +172,7 @@ async function fetchMemberProfilesUncached(playerUuid) {
});
for (const profile of profiles) {
for (const member of profile.members) {
- database_1.updateDatabaseMember(member, profile);
+ database_1.queueUpdateDatabaseMember(member, profile);
}
}
return profiles;