/**
* Store data about members for leaderboards
*/
import { categorizeStat, getStatUnit } from './cleaners/skyblock/stats.js'
import { CleanFullProfile } from './cleaners/skyblock/profile.js'
import { SLAYER_TIERS } from './cleaners/skyblock/slayers.js'
import { Collection, Db, MongoClient, WithId } from 'mongodb'
import { CleanMember } from './cleaners/skyblock/member.js'
import * as cached from './hypixelCached.js'
import * as constants from './constants.js'
import { isUuid, letterFromColorCode, minecraftColorCodes, shuffle, sleep } from './util.js'
import * as discord from './discord.js'
import NodeCache from 'node-cache'
import { v4 as uuid4 } from 'uuid'
import { debug } from './index.js'
import Queue from 'queue-promise'
import { RANK_COLORS } from './cleaners/rank.js'
import { cleanItemId } from './cleaners/skyblock/itemId.js'
// don't update the user for 3 minutes
const recentlyUpdated = new NodeCache({
stdTTL: 60 * 3,
checkperiod: 60,
useClones: false,
})
// don't add stuff to the queue within the same 5 minutes
const recentlyQueued = new NodeCache({
stdTTL: 60 * 5,
checkperiod: 60,
useClones: false,
})
interface DatabaseMemberLeaderboardItem {
uuid: string
profile: string
/** The color code of this player's rank */
color: string
username: string
stats: Record<string, number>
lastUpdated: Date
}
interface DatabaseProfileLeaderboardItem {
uuid: string
/** The color codes of the players ranks */
colors: string[]
/** An array of uuids for each player in the profile */
players: string[]
usernames: string[]
stats: Record<string, number>
lastUpdated: Date
}
interface memberRawLeaderboardItem {
uuid: string
profile: string
color: string
username: string
value: number
}
interface profileRawLeaderboardItem {
uuid: string
/** An array of uuids for each player in the profile */
players: string[]
colors: string[]
usernames: string[]
value: number
}
interface MemberLeaderboardItem {
player: LeaderboardBasicPlayer
profileUuid: string
value: number
}
interface ProfileLeaderboardItem {
players: LeaderboardBasicPlayer[]
profileUuid: string
value: number
}
export const cachedRawLeaderboards: Map<string, (memberRawLeaderboardItem | profileRawLeaderboardItem)[]> = new Map()
const leaderboardMax = 100
const reversedLeaderboards = [
'first_join', 'last_save',
'_best_time', '_best_time_2',
'fastest_coop_join'
]
let client: MongoClient
let database: Db
interface SessionSchema {
_id?: string
refresh_token: string
discord_user: {
id: string
name: string
}
lastUpdated: Date
}
export interface AccountCustomization {
backgroundUrl?: string
pack?: string
blurBackground?: boolean
emoji?: string
}
export interface AccountSchema {
_id?: string
discordId: string
minecraftUuid?: string
customization?: AccountCustomization
}
let memberLeaderboardsCollection: Collection<DatabaseMemberLeaderboardItem>
let profileLeaderboardsCollection: Collection<DatabaseProfileLeaderboardItem>
let sessionsCollection: Collection<SessionSchema>
let accountsCollection: Collection<AccountSchema>
const leaderboardInfos: { [leaderboardName: string]: string } = {
highest_crit_damage: 'This leaderboard is capped at the integer limit. Look at the <a href="/leaderboard/highest_critical_damage">highest critical damage leaderboard</a> instead.',
highest_critical_damage: 'uhhhhh yeah idk either',
leaderboards_count: 'This leaderboard counts how many leaderboards a player is in the top 100 spot for.',
top_1_leaderboards_count: 'This leaderboard counts how many leaderboards a player is in