aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cleaners/skyblock/stats.ts5
-rw-r--r--src/database.ts31
-rw-r--r--src/hypixel.ts6
3 files changed, 37 insertions, 5 deletions
diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts
index 6c274bc..7d8da57 100644
--- a/src/cleaners/skyblock/stats.ts
+++ b/src/cleaners/skyblock/stats.ts
@@ -3,9 +3,12 @@ const statCategories: { [ key: string ]: string[] | null } = { // sorted in orde
'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
}
diff --git a/src/database.ts b/src/database.ts
index ce95578..29760ef 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -10,7 +10,8 @@ import { CleanMember } from './cleaners/skyblock/member'
import { CleanPlayer } from './cleaners/player'
import { shuffle, sleep } from './util'
import { CleanFullProfile } from './cleaners/skyblock/profile'
-import { categorizeStat, StatCategory } from './cleaners/skyblock/stats'
+import { categorizeStat } from './cleaners/skyblock/stats'
+import Queue from 'queue-promise'
// don't update the user for 3 minutes
const recentlyUpdated = new NodeCache({
@@ -62,6 +63,15 @@ function getMemberCollectionAttributes(member: CleanMember) {
return collectionAttributes
}
+function getMemberSkillAttributes(member: CleanMember) {
+ const skillAttributes = {}
+ for (const collection of member.skills) {
+ const skillLeaderboardName = `skill_${collection.name}`
+ skillAttributes[skillLeaderboardName] = collection.xp
+ }
+ return skillAttributes
+}
+
function getMemberLeaderboardAttributes(member: CleanMember) {
// if you want to add a new leaderboard for member attributes, add it here (and getAllLeaderboardAttributes)
return {
@@ -71,6 +81,9 @@ function getMemberLeaderboardAttributes(member: CleanMember) {
// collection leaderboards
...getMemberCollectionAttributes(member),
+ // skill leaderboards
+ ...getMemberSkillAttributes(member),
+
fairy_souls: member.fairy_souls.total,
first_join: member.first_join,
purse: member.purse,
@@ -107,6 +120,9 @@ export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> {
// collection leaderboards
...(await constants.fetchCollections()).map(value => `collection_${value}`),
+ // skill leaderboards
+ ...(await constants.fetchSkills()).map(value => `skill_${value}`),
+
'fairy_souls',
'first_join',
'purse',
@@ -176,12 +192,14 @@ async function getApplicableAttributes(member): Promise<{ [key: string]: number
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 */
export async function updateDatabaseMember(member: CleanMember, profile: CleanFullProfile) {
+ console.log('updating', member.uuid)
if (!client) return // the db client hasn't been initialized
// the member's been updated too recently, just return
if (recentlyUpdated.get(profile.uuid + member.uuid))
@@ -225,6 +243,17 @@ export async function updateDatabaseMember(member: CleanMember, profile: CleanFu
.slice(0, 100)
cachedRawLeaderboards.set(attributeName, newRawLeaderboard)
}
+ console.log('updated', member.uuid)
+}
+
+const queue = new Queue({
+ concurrent: 3,
+ interval: 500
+})
+
+/** Queue an update for the member's leaderboard data on the server if applicable */
+export async function queueUpdateDatabaseMember(member: CleanMember, profile: CleanFullProfile) {
+ queue.enqueue(async() => await updateDatabaseMember(member, profile))
}
diff --git a/src/hypixel.ts b/src/hypixel.ts
index b230575..a5b8f93 100644
--- a/src/hypixel.ts
+++ b/src/hypixel.ts
@@ -9,7 +9,7 @@ import { CleanBasicMember, CleanMemberProfile } from './cleaners/skyblock/member
import { cleanSkyblockProfileResponse, CleanProfile, CleanBasicProfile, CleanFullProfile, CleanFullProfileBasicMembers } from './cleaners/skyblock/profile'
import { cleanSkyblockProfilesResponse } from './cleaners/skyblock/profiles'
import { debug } from '.'
-import { updateDatabaseMember } from './database'
+import { queueUpdateDatabaseMember } from './database'
export type Included = 'profiles' | 'player' | 'stats' | 'inventories'
@@ -183,7 +183,7 @@ export async function fetchMemberProfileUncached(playerUuid: string, profileUuid
{ mainMemberUuid: playerUuid }
)
for (const member of profile.members)
- updateDatabaseMember(member, profile)
+ queueUpdateDatabaseMember(member, profile)
return profile
}
@@ -202,7 +202,7 @@ export async function fetchMemberProfilesUncached(playerUuid: string): Promise<C
)
for (const profile of profiles) {
for (const member of profile.members) {
- updateDatabaseMember(member, profile)
+ queueUpdateDatabaseMember(member, profile)
}
}
return profiles