aboutsummaryrefslogtreecommitdiff
path: root/src/database.ts
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-03-01 17:21:41 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-03-01 17:21:41 -0600
commit5967be8d5666b47cba169df5eb3a2eacd87fb844 (patch)
tree700eed4f41457c2f4bfef31a7d8a30b06d341286 /src/database.ts
parentd23e4988f1b3c92d1d6caf212927f6d3fca62e1a (diff)
downloadskyblock-api-5967be8d5666b47cba169df5eb3a2eacd87fb844.tar.gz
skyblock-api-5967be8d5666b47cba169df5eb3a2eacd87fb844.tar.bz2
skyblock-api-5967be8d5666b47cba169df5eb3a2eacd87fb844.zip
add skill leaderboards
Diffstat (limited to 'src/database.ts')
-rw-r--r--src/database.ts31
1 files changed, 30 insertions, 1 deletions
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))
}