diff options
author | mat <github@matdoes.dev> | 2022-03-31 21:58:54 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-31 21:58:54 -0500 |
commit | 4b706d309e30d92b7b143d1879d9298fdba53141 (patch) | |
tree | 12794ef1791dad68ddbe5c468011181cc1967a0b /src | |
parent | c3f939df6f95fa92862628102f6278f3de72e3ba (diff) | |
download | skyblock-api-4b706d309e30d92b7b143d1879d9298fdba53141.tar.gz skyblock-api-4b706d309e30d92b7b143d1879d9298fdba53141.tar.bz2 skyblock-api-4b706d309e30d92b7b143d1879d9298fdba53141.zip |
don't show slayer tier 5 for nonexistent bosses
Diffstat (limited to 'src')
-rw-r--r-- | src/cleaners/skyblock/slayers.ts | 11 | ||||
-rw-r--r-- | src/database.ts | 10 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/cleaners/skyblock/slayers.ts b/src/cleaners/skyblock/slayers.ts index 782ec95..b5dda0b 100644 --- a/src/cleaners/skyblock/slayers.ts +++ b/src/cleaners/skyblock/slayers.ts @@ -1,6 +1,5 @@ import typedHypixelApi from 'typed-hypixel-api' -export const slayerLevels = 5 const SLAYER_NAMES = { spider: 'tarantula', @@ -9,6 +8,14 @@ const SLAYER_NAMES = { enderman: 'voidgloom_seraph' } as const +// todo: put this in skyblock-constants since it can be determined from other people's profiles +export const SLAYER_TIERS: Record<keyof typeof SLAYER_NAMES, number> = { + spider: 4, + zombie: 5, + enderman: 4, + wolf: 4 +} + type SlayerName = (typeof SLAYER_NAMES)[keyof typeof SLAYER_NAMES] interface SlayerTier { @@ -75,7 +82,7 @@ export function cleanSlayers(data: typedHypixelApi.SkyBlockProfileMember): Slaye } // if the slayer tier length is less than the max, add more empty ones - while (slayerTiers.length < slayerLevels) + while (slayerTiers.length < SLAYER_TIERS[slayerName]) slayerTiers.push({ tier: slayerTiers.length + 1, kills: 0 diff --git a/src/database.ts b/src/database.ts index 394b58b..9c2978b 100644 --- a/src/database.ts +++ b/src/database.ts @@ -4,9 +4,9 @@ import { categorizeStat, getStatUnit } from './cleaners/skyblock/stats.js' import { CleanFullProfile } from './cleaners/skyblock/profile.js' -import { slayerLevels } from './cleaners/skyblock/slayers.js' +import { SLAYER_TIERS } from './cleaners/skyblock/slayers.js' +import { Collection, Db, MongoClient, WithId } from 'mongodb' import { CleanMember } from './cleaners/skyblock/member.js' -import { Collection, Db, Filter, MongoClient, WithId } from 'mongodb' import { CleanPlayer } from './cleaners/player.js' import * as cached from './hypixelCached.js' import * as constants from './constants.js' @@ -14,8 +14,8 @@ import { shuffle, sleep } from './util.js' import * as discord from './discord.js' import NodeCache from 'node-cache' import { v4 as uuid4 } from 'uuid' -import Queue from 'queue-promise' import { debug } from './index.js' +import Queue from 'queue-promise' // don't update the user for 3 minutes const recentlyUpdated = new NodeCache({ @@ -256,7 +256,7 @@ export async function fetchSlayerLeaderboards(): Promise<string[]> { for (const slayerNameRaw of rawSlayerNames) { leaderboardNames.push(`slayer_${slayerNameRaw}_total_xp`) leaderboardNames.push(`slayer_${slayerNameRaw}_total_kills`) - for (let slayerTier = 1; slayerTier <= slayerLevels; slayerTier++) { + for (let slayerTier = 1; slayerTier <= SLAYER_TIERS[slayerNameRaw]; slayerTier++) { leaderboardNames.push(`slayer_${slayerNameRaw}_${slayerTier}_kills`) } } @@ -652,6 +652,8 @@ async function getApplicableProfileLeaderboardAttributes(profile: CleanFullProfi * deleted. This only makes one database call if there's no profiles to delete. */ export async function removeDeletedProfilesFromLeaderboards(memberUuid: string, profilesUuids: string[]) { + if (!client) return + const leaderboardProfilesInDatabase = (await (await memberLeaderboardsCollection.find({ uuid: memberUuid, })).toArray()) |