aboutsummaryrefslogtreecommitdiff
path: root/build/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'build/database.js')
-rw-r--r--build/database.js44
1 files changed, 41 insertions, 3 deletions
diff --git a/build/database.js b/build/database.js
index b40d30c..967828e 100644
--- a/build/database.js
+++ b/build/database.js
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.queueUpdateDatabaseMember = exports.updateDatabaseMember = exports.fetchMemberLeaderboardSpots = exports.fetchMemberLeaderboard = exports.fetchAllMemberLeaderboardAttributes = exports.fetchAllLeaderboardsCategorized = void 0;
+exports.queueUpdateDatabaseMember = exports.updateDatabaseMember = exports.fetchMemberLeaderboardSpots = exports.fetchMemberLeaderboard = exports.fetchAllMemberLeaderboardAttributes = exports.fetchSlayerLeaderboards = exports.fetchAllLeaderboardsCategorized = void 0;
const stats_1 = require("./cleaners/skyblock/stats");
const mongodb_1 = require("mongodb");
const cached = __importStar(require("./hypixelCached"));
@@ -34,6 +34,7 @@ const util_1 = require("./util");
const node_cache_1 = __importDefault(require("node-cache"));
const queue_promise_1 = __importDefault(require("queue-promise"));
const _1 = require(".");
+const slayers_1 = require("./cleaners/skyblock/slayers");
// don't update the user for 3 minutes
const recentlyUpdated = new node_cache_1.default({
stdTTL: 60 * 3,
@@ -74,6 +75,20 @@ function getMemberSkillAttributes(member) {
}
return skillAttributes;
}
+function getMemberSlayerAttributes(member) {
+ const slayerAttributes = {
+ slayer_total_xp: member.slayers.xp,
+ slayer_total_kills: member.slayers.kills,
+ };
+ for (const slayer of member.slayers.bosses) {
+ slayerAttributes[`slayer_${slayer.name}_total_xp`] = slayer.xp;
+ slayerAttributes[`slayer_${slayer.name}_total_kills`] = slayer.kills;
+ for (const tier of slayer.tiers) {
+ slayerAttributes[`slayer_${slayer.name}_${tier.tier}_kills`] = tier.kills;
+ }
+ }
+ return slayerAttributes;
+}
function getMemberLeaderboardAttributes(member) {
// if you want to add a new leaderboard for member attributes, add it here (and getAllLeaderboardAttributes)
return {
@@ -83,6 +98,8 @@ function getMemberLeaderboardAttributes(member) {
...getMemberCollectionAttributes(member),
// skill leaderboards
...getMemberSkillAttributes(member),
+ // slayer leaderboards
+ ...getMemberSlayerAttributes(member),
fairy_souls: member.fairy_souls.total,
first_join: member.first_join,
purse: member.purse,
@@ -105,6 +122,24 @@ async function fetchAllLeaderboardsCategorized() {
return categorizedLeaderboards;
}
exports.fetchAllLeaderboardsCategorized = fetchAllLeaderboardsCategorized;
+/** Fetch the raw names for the slayer leaderboards */
+async function fetchSlayerLeaderboards() {
+ const rawSlayerNames = await constants.fetchSlayers();
+ let leaderboardNames = [
+ 'slayer_total_xp',
+ 'slayer_total_kills'
+ ];
+ // we use the raw names (zombie, spider, wolf) instead of the clean names (revenant, tarantula, sven) because the raw names are guaranteed to never change
+ for (const slayerNameRaw of rawSlayerNames) {
+ leaderboardNames.push(`slayer_${slayerNameRaw}_total_xp`);
+ leaderboardNames.push(`slayer_${slayerNameRaw}_total_kills`);
+ for (let slayerTier = 1; slayerTier <= slayers_1.slayerLevels; slayerTier++) {
+ leaderboardNames.push(`slayer_${slayerNameRaw}_${slayerTier}_kills`);
+ }
+ }
+ return leaderboardNames;
+}
+exports.fetchSlayerLeaderboards = fetchSlayerLeaderboards;
/** Fetch the names of all the leaderboards */
async function fetchAllMemberLeaderboardAttributes() {
return [
@@ -114,6 +149,8 @@ async function fetchAllMemberLeaderboardAttributes() {
...(await constants.fetchCollections()).map(value => `collection_${value}`),
// skill leaderboards
...(await constants.fetchSkills()).map(value => `skill_${value}`),
+ // slayer leaderboards
+ ...await fetchSlayerLeaderboards(),
'fairy_souls',
'first_join',
'purse',
@@ -231,6 +268,7 @@ async function updateDatabaseMember(member, profile) {
await constants.addCollections(member.collections.map(coll => coll.name));
await constants.addSkills(member.skills.map(skill => skill.name));
await constants.addZones(member.visited_zones.map(zone => zone.name));
+ await constants.addSlayers(member.slayers.bosses.map(s => s.raw_name));
if (_1.debug)
console.log('done constants..');
const leaderboardAttributes = await getApplicableAttributes(member);
@@ -265,13 +303,13 @@ async function updateDatabaseMember(member, profile) {
console.log('added member to leaderboards', member.username, leaderboardAttributes);
}
exports.updateDatabaseMember = updateDatabaseMember;
-const queue = new queue_promise_1.default({
+const leaderboardUpdateQueue = new queue_promise_1.default({
concurrent: 1,
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));
+ leaderboardUpdateQueue.enqueue(async () => await updateDatabaseMember(member, profile));
}
exports.queueUpdateDatabaseMember = queueUpdateDatabaseMember;
/**