diff options
-rw-r--r-- | src/cleaners/skyblock/member.ts | 9 | ||||
-rw-r--r-- | src/cleaners/skyblock/profile.ts | 12 | ||||
-rw-r--r-- | src/constants.ts | 33 | ||||
-rw-r--r-- | src/index.ts | 7 |
4 files changed, 57 insertions, 4 deletions
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index cfa9a71..7a57975 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -9,6 +9,7 @@ import { cleanSlayers, SlayerData } from './slayers' import { cleanVisitedZones, Zone } from './zones' import { cleanSkills, Skill } from './skills' import * as cached from '../../hypixelCached' +import * as constants from '../../constants' import { Included } from '../../hypixel' import { CleanPlayer } from '../player' import { CleanRank } from '../rank' @@ -53,6 +54,12 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu const inventoriesIncluded = included === null || included.includes('inventories') const player = await cached.fetchPlayer(member.uuid) if (!player) return + + const fairySouls = cleanFairySouls(member) + const { max_fairy_souls: maxFairySouls } = await constants.fetchConstantValues() + if (fairySouls.total > (maxFairySouls ?? 0)) + await constants.setConstantValues({ max_fairy_souls: fairySouls.total }) + return { uuid: member.uuid, username: player.username, @@ -68,7 +75,7 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu rawHypixelStats: member.stats ?? {}, minions: await cleanMinions(member), - fairy_souls: cleanFairySouls(member), + fairy_souls: fairySouls, inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, objectives: cleanObjectives(member), skills: cleanSkills(member), diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts index 433471b..a796d8f 100644 --- a/src/cleaners/skyblock/profile.ts +++ b/src/cleaners/skyblock/profile.ts @@ -1,7 +1,8 @@ import { CleanBasicMember, CleanMember, cleanSkyBlockProfileMemberResponse, cleanSkyBlockProfileMemberResponseBasic } from './member' import { CleanMinion, combineMinionArrays, countUniqueMinions } from './minions' -import { Bank, cleanBank } from './bank' import { ApiOptions } from '../../hypixel' +import { Bank, cleanBank } from './bank' +import * as constants from '../../constants' export interface CleanProfile extends CleanBasicProfile { members?: CleanBasicMember[] @@ -78,6 +79,13 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio } const minions: CleanMinion[] = combineMinionArrays(memberMinions) + const { max_minions: maxUniqueMinions } = await constants.fetchConstantValues() + + const uniqueMinions = countUniqueMinions(minions) + console.log(uniqueMinions, (maxUniqueMinions ?? 0), uniqueMinions > (maxUniqueMinions ?? 0)) + if (uniqueMinions > (maxUniqueMinions ?? 0)) + await constants.setConstantValues({ max_minions: uniqueMinions }) + // return more detailed info return { uuid: data.profile_id, @@ -85,7 +93,7 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio members: cleanedMembers, bank: cleanBank(data), minions: minions, - minion_count: countUniqueMinions(minions) + minion_count: uniqueMinions } } diff --git a/src/constants.ts b/src/constants.ts index 14d94cd..52c104c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -124,7 +124,7 @@ async function editFile(file: GithubFile, message: string, newContent: string): }) } -export async function fetchJSONConstant(filename: string): Promise<string[]> { +export async function fetchJSONConstant(filename: string): Promise<any> { const file = await fetchFile(filename) try { return JSON.parse(file.content) @@ -229,3 +229,34 @@ export async function fetchMinions(): Promise<string[]> { export async function addMinions(addingMinions: string[]): Promise<void> { await constants.addJSONConstants('minions.json', addingMinions, 'minion') } + +interface constantValues { + max_minions?: number + max_fairy_souls?: number +} + +export async function fetchConstantValues(): Promise<constantValues> { + return await constants.fetchJSONConstant('values.json') +} + +export async function setConstantValues(newValues: constantValues) { + let file: GithubFile = await fetchFile('values.json') + if (!file.path) return + let oldValues: constantValues + try { + oldValues = JSON.parse(file.content) + } catch { + // invalid json, set it as an empty array + oldValues = {} + } + const updatedStats = { ...oldValues, ...newValues } + + // there's not actually any new stats, just return + // TODO: optimize this? might be fine already though, idk + if (JSON.stringify(updatedStats) === JSON.stringify(oldValues)) return + + const commitMessage = 'Update values' + try { + await editFile(file, commitMessage, JSON.stringify(updatedStats, null, 2)) + } catch {} +}
\ No newline at end of file diff --git a/src/index.ts b/src/index.ts index d25efc9..1652428 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { fetchAllLeaderboardsCategorized, fetchLeaderboard, fetchMemberLeaderboardSpots } from './database' import { fetchMemberProfile, fetchUser } from './hypixel' import rateLimit from 'express-rate-limit' +import * as constants from './constants' import express from 'express' const app = express() @@ -68,6 +69,12 @@ app.get('/leaderboards', async(req, res) => { ) }) +app.get('/constants', async(req, res) => { + res.json( + await constants.fetchConstantValues() + ) +}) + // only run the server if it's not doing tests if (!globalThis.isTest) |