diff --git a/public/resources/ts/themes.ts b/public/resources/ts/themes.ts index 0e60d0f229..c90458ff65 100644 --- a/public/resources/ts/themes.ts +++ b/public/resources/ts/themes.ts @@ -1,4 +1,4 @@ -export const themes = new Map>(); +export const THEMES = new Map>(); /** * converts a hex color to it's rgb components @@ -33,12 +33,12 @@ async function fetchTheme(urlString: string): Promise { } export function getTheme(urlString: string): Promise { - const themeFromMap = themes.get(urlString); + const themeFromMap = THEMES.get(urlString); if (themeFromMap !== undefined) { return themeFromMap; } else { const themeFromFetch = fetchTheme(urlString); - themes.set(urlString, themeFromFetch); + THEMES.set(urlString, themeFromFetch); return themeFromFetch; } } diff --git a/src/app.js b/src/app.js index fdd4af41bb..af361e6362 100644 --- a/src/app.js +++ b/src/app.js @@ -1,6 +1,6 @@ // this file never runs on the master thread import * as lib from "./lib.js"; -import { getFileHashes, getFileHash, hashedDirectories } from "./hashes.js"; +import { getFileHashes, getFileHash, HASHED_DIRECTORIES } from "./hashes.js"; import fetch from "node-fetch"; import express from "express"; @@ -69,7 +69,7 @@ if (process.env.NODE_ENV == "development") { watch("public/resources/css", { recursive: true }, async (evt, name) => { const [, , directory, fileName] = name.split(/\/|\\/); - if (hashedDirectories.includes(directory)) { + if (HASHED_DIRECTORIES.includes(directory)) { fileHashes[directory][fileName] = await getFileHash(name); } }); diff --git a/src/constants/accessories.js b/src/constants/accessories.js index 7723d3ec57..eaa83737cb 100644 --- a/src/constants/accessories.js +++ b/src/constants/accessories.js @@ -108,7 +108,7 @@ const ignoredAccessories = [ "GENERAL_MEDALLION", ]; -export const accessoryAliases = { +export const ACCESSORY_ALIASES = { WEDDING_RING_0: ["WEDDING_RING_1"], WEDDING_RING_2: ["WEDDING_RING_3"], WEDDING_RING_4: ["WEDDING_RING_5", "WEDDING_RING_6"], @@ -193,7 +193,7 @@ export function getAllAccessories() { const output = items.reduce((accessory, item) => { if (ignoredAccessories.includes(item.id)) return accessory; - if (Object.values(accessoryAliases).find((list) => list.includes(item.id))) return accessory; + if (Object.values(ACCESSORY_ALIASES).find((list) => list.includes(item.id))) return accessory; accessory.push({ ...item, diff --git a/src/constants/misc.js b/src/constants/misc.js index b9720f6da0..8c3dee5ef6 100644 --- a/src/constants/misc.js +++ b/src/constants/misc.js @@ -6,20 +6,9 @@ export const BLOCKED_PLAYERS = [ "fc7e31ef7bfe41e7aa5d7e2db14bedd0", // Kazius1 (Admin) ]; -// Number of kills required for each level of expertise -export const EXPERTISE_KILLS_LADDER = [50, 100, 250, 500, 1000, 2500, 5500, 10000, 15000]; - // Walking distance required for each rarity level of the prehistoric egg export const PREHISTORIC_EGG_BLOCKS_WALKED_LADDER = [4000, 10000, 20000, 40000, 100000]; -// Number of S runs required for each level of hecatomb -export const hecatomb_s_runs_ladder = [2, 5, 10, 20, 30, 40, 60, 80, 100]; - -// xp required for each level of champion -export const champion_xp_ladder = [50000, 100000, 250000, 500000, 1000000, 1500000, 2000000, 2500000, 3000000]; - -export const cultivating_crops_ladder = [1000, 5000, 25000, 100000, 300000, 1500000, 5000000, 20000000, 100000000]; - // api names and their max value from the profile upgrades export const PROFILE_UPGRADES = { island_size: 10, @@ -730,3 +719,20 @@ export const PET_MILESTONES = { sea_creatures_killed: [250, 1000, 2500, 5000, 10000], ores_mined: [2500, 7500, 20000, 100000, 250000], }; + +export const ENCHANTMENT_LADDERS = { + // Number of S runs required for each level of hecatomb + hecatomb_s_runs: [2, 5, 10, 20, 30, 40, 60, 80, 100], + + // Number of xp required for each level of champion + champion_xp: [50000, 100000, 250000, 500000, 1000000, 1500000, 2000000, 2500000, 3000000], + + // Number of crops harvested for each level of cultivating crops + cultivating_crops: [1000, 5000, 25000, 100000, 300000, 1500000, 5000000, 20000000, 100000000], + + // Number of kills required for each level of expertise + expertise_kills: [50, 100, 250, 500, 1000, 2500, 5500, 10000, 15000], + + // Number of ores mined required for each level of compact ores + compact_ores: [100, 500, 1500, 5000, 15000, 50000, 150000, 500000, 1000000], +}; diff --git a/src/credentials.js b/src/credentials.js index 6b15064984..91eaec0a3c 100644 --- a/src/credentials.js +++ b/src/credentials.js @@ -43,33 +43,33 @@ function writeFile(newValue) { let hasBeenModified = false; /** @type {Credentials} */ -const credentials = readFile() ?? {}; +const CREDENTIALS = readFile() ?? {}; for (const key in defaultCredentials) { - if (credentials[key] == undefined) { - credentials[key] = defaultCredentials[key]; + if (CREDENTIALS[key] == undefined) { + CREDENTIALS[key] = defaultCredentials[key]; hasBeenModified = true; } } if (hasBeenModified) { - writeFile(credentials); + writeFile(CREDENTIALS); } if (process.env.HYPIXEL_API_KEY) { - credentials.hypixel_api_key = process.env.HYPIXEL_API_KEY; + CREDENTIALS.hypixel_api_key = process.env.HYPIXEL_API_KEY; } if (process.env.MONGO_CONNECTION_STRING) { - credentials.dbUrl = process.env.MONGO_CONNECTION_STRING; + CREDENTIALS.dbUrl = process.env.MONGO_CONNECTION_STRING; } if (process.env.REDIS_CONNECTION_STRING) { - credentials.redisUrl = process.env.REDIS_CONNECTION_STRING; + CREDENTIALS.redisUrl = process.env.REDIS_CONNECTION_STRING; } if (process.env.DISCORD_WEBHOOK) { - credentials.discord_webhook = process.env.DISCORD_WEBHOOK; + CREDENTIALS.discord_webhook = process.env.DISCORD_WEBHOOK; } -export default credentials; +export default CREDENTIALS; diff --git a/src/hashes.js b/src/hashes.js index 8265f31630..db1134d0d7 100644 --- a/src/hashes.js +++ b/src/hashes.js @@ -6,7 +6,7 @@ import { promisify } from "util"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -export const hashedDirectories = ["css"]; +export const HASHED_DIRECTORIES = ["css"]; export function getFileHash(filename) { return new Promise((resolve, reject) => { @@ -26,7 +26,7 @@ export function getFileHash(filename) { } export function getFileHashes() { - const directoryPromises = hashedDirectories.map(async (directory) => { + const directoryPromises = HASHED_DIRECTORIES.map(async (directory) => { const readdirPromise = promisify(fs.readdir); const fileNames = await readdirPromise(path.join(__dirname, "../public/resources", directory)); @@ -49,8 +49,8 @@ export function getFileHashes() { return Promise.all(directoryPromises).then((directories) => { const directoriesObject = {}; - for (let i = 0; i < hashedDirectories.length; i++) { - directoriesObject[hashedDirectories[i]] = directories[i]; + for (let i = 0; i < HASHED_DIRECTORIES.length; i++) { + directoriesObject[HASHED_DIRECTORIES[i]] = directories[i]; } return directoriesObject; diff --git a/src/helper.js b/src/helper.js index a0b4411563..a8b793c14c 100644 --- a/src/helper.js +++ b/src/helper.js @@ -624,9 +624,9 @@ export function getClusterId(fullName = false) { return cluster.isWorker ? `w${cluster.worker.id}` : "m"; } -export const generateDebugId = (endpointName = "unknown") => { +export function generateDebugId(endpointName = "unknown") { return `${getClusterId()}/${endpointName}_${Date.now()}.${Math.floor(Math.random() * 9000 + 1000)}`; -}; +} export function generateUUID() { let u = "", @@ -661,22 +661,22 @@ export function parseItemGems(gems, rarity) { const parsed = []; for (const [key, value] of Object.entries(gems)) { - const slot_type = key.split("_")[0]; + const slotType = key.split("_")[0]; - if (slots.ignore.includes(key) || (slots.special.includes(slot_type) && key.endsWith("_gem"))) { + if (slots.ignore.includes(key) || (slots.special.includes(slotType) && key.endsWith("_gem"))) { continue; } - if (slots.special.includes(slot_type)) { + if (slots.special.includes(slotType)) { parsed.push({ - slot_type, + slot_type: slotType, slot_number: +key.split("_")[1], gem_type: gems[`${key}_gem`], gem_tier: value?.quality || value, }); - } else if (slots.normal.includes(slot_type)) { + } else if (slots.normal.includes(slotType)) { parsed.push({ - slot_type, + slot_type: slotType, slot_number: +key.split("_")[1], gem_type: key.split("_")[0], gem_tier: value?.quality || value, @@ -713,19 +713,19 @@ export function generateGemLore(type, tier, rarity) { // Gem stats if (rarity) { - const gemstone_stats = GEMSTONES[type.toUpperCase()]?.stats?.[tier.toUpperCase()]; - if (gemstone_stats) { - Object.keys(gemstone_stats).forEach((stat) => { - let stat_value = gemstone_stats[stat][rarityNameToInt(rarity)]; + const gemstoneStats = GEMSTONES[type.toUpperCase()]?.stats?.[tier.toUpperCase()]; + if (gemstoneStats) { + Object.keys(gemstoneStats).forEach((stat) => { + let statValue = gemstoneStats[stat][rarityNameToInt(rarity)]; // Fallback since skyblock devs didn't code all gemstone stats for divine rarity yet // ...they didn't expect people to own divine tier items other than divan's drill - if (rarity.toUpperCase() === "DIVINE" && stat_value === null) { - stat_value = gemstone_stats[stat][rarityNameToInt("MYTHIC")]; + if (rarity.toUpperCase() === "DIVINE" && statValue === null) { + statValue = gemstoneStats[stat][rarityNameToInt("MYTHIC")]; } - if (stat_value) { - stats.push(["§", STATS_DATA[stat].color, "+", stat_value, " ", STATS_DATA[stat].symbol].join("")); + if (statValue) { + stats.push(["§", STATS_DATA[stat].color, "+", statValue, " ", STATS_DATA[stat].symbol].join("")); } else { stats.push("§c§oMISSING VALUE§r"); } @@ -775,7 +775,7 @@ export function generateItem(data) { }; } - const default_data = { + const DEFAULT_DATA = { id: 389, Damage: 0, Count: 1, @@ -807,7 +807,7 @@ export function generateItem(data) { } // Creating final item - return Object.assign(default_data, data); + return Object.assign(DEFAULT_DATA, data); } /** @@ -1080,7 +1080,7 @@ export function getCommitHash() { */ } -export function RGBtoHex(rgb) { +export function rgbToHex(rgb) { const [r, g, b] = rgb.split(",").map((c) => parseInt(c.trim())); return [r, g, b].map((c) => c.toString(16).padStart(2, "0")).join(""); diff --git a/src/mongo.js b/src/mongo.js index 206549031f..069eb7e7db 100644 --- a/src/mongo.js +++ b/src/mongo.js @@ -1,3 +1,4 @@ +/* eslint-disable */ import { MongoClient } from "mongodb"; import credentials from "./credentials.js"; diff --git a/src/redis.js b/src/redis.js index 8a53f19e72..cbee1a4872 100644 --- a/src/redis.js +++ b/src/redis.js @@ -1,3 +1,4 @@ +/* eslint-disable */ import Redis from "ioredis"; import credentials from "./credentials.js"; diff --git a/src/stats/items/accessories.js b/src/stats/items/accessories.js index dda14e623c..f974e045a6 100644 --- a/src/stats/items/accessories.js +++ b/src/stats/items/accessories.js @@ -86,12 +86,12 @@ export function getAccessories(userProfile, armor, accessoryBag, inventory, ende }); // mark accessory aliases as inactive - const accessoryAliases = constants.accessoryAliases; - if (id in accessoryAliases || Object.keys(accessoryAliases).find((a) => accessoryAliases[a].includes(id))) { - let accessoryDuplicates = constants.accessoryAliases[id]; + const ACCESSORY_ALIASES = constants.ACCESSORY_ALIASES; + if (id in ACCESSORY_ALIASES || Object.keys(ACCESSORY_ALIASES).find((a) => ACCESSORY_ALIASES[a].includes(id))) { + let accessoryDuplicates = constants.ACCESSORY_ALIASES[id]; if (accessoryDuplicates === undefined) { - const aliases = Object.keys(accessoryAliases).filter((a) => accessoryAliases[a].includes(id)); - accessoryDuplicates = aliases.concat(constants.accessoryAliases[aliases]); + const aliases = Object.keys(ACCESSORY_ALIASES).filter((a) => ACCESSORY_ALIASES[a].includes(id)); + accessoryDuplicates = aliases.concat(constants.ACCESSORY_ALIASES[aliases]); } for (const duplicate of accessoryDuplicates) { diff --git a/src/stats/items/processing.js b/src/stats/items/processing.js index d45daaf4ca..243cba192d 100644 --- a/src/stats/items/processing.js +++ b/src/stats/items/processing.js @@ -111,7 +111,7 @@ export async function processItems(base64, source, customTextures = false, packs const type = ["helmet", "chestplate", "leggings", "boots"][itemData.id - 298]; if (hypixelItem?.color !== undefined) { - const color = helper.RGBtoHex(hypixelItem.color) ?? "955e3b"; + const color = helper.rgbToHex(hypixelItem.color) ?? "955e3b"; itemData.texture_path = `/leather/${type}/${color}`; } @@ -136,9 +136,9 @@ export async function processItems(base64, source, customTextures = false, packs } if (item.tag?.ExtraAttributes?.rarity_upgrades != undefined) { - const { rarity_upgrades } = item.tag.ExtraAttributes; + const rarityUpgrades = item.tag.ExtraAttributes.rarity_upgrades; - if (rarity_upgrades > 0) { + if (rarityUpgrades > 0) { item.extra.recombobulated = true; } } @@ -152,42 +152,50 @@ export async function processItems(base64, source, customTextures = false, packs } if (item.tag?.ExtraAttributes?.expertise_kills != undefined) { - const { expertise_kills } = item.tag.ExtraAttributes; + const expertiseKills = item.tag.ExtraAttributes.expertise_kills; - if (expertise_kills > 0) { - item.extra.expertise_kills = expertise_kills; + if (expertiseKills > 0) { + item.extra.expertise_kills = expertiseKills; + } + } + + if (item.tag?.ExtraAttributes?.compact_blocks !== undefined) { + const compactBlocks = item.tag.ExtraAttributes.compact_blocks; + + if (compactBlocks > 0) { + item.extra.compact_blocks = compactBlocks; } } if (item.tag?.ExtraAttributes?.hecatomb_s_runs != undefined) { - const { hecatomb_s_runs } = item.tag.ExtraAttributes; + const hecatombSRuns = item.tag.ExtraAttributes.hecatomb_s_runs; - if (hecatomb_s_runs > 0) { - item.extra.hecatomb_s_runs = hecatomb_s_runs; + if (hecatombSRuns > 0) { + item.extra.hecatomb_s_runs = hecatombSRuns; } } if (item.tag?.ExtraAttributes?.champion_combat_xp != undefined) { - const { champion_combat_xp } = item.tag.ExtraAttributes; + const championCombatXp = item.tag.ExtraAttributes.champion_combat_xp; - if (champion_combat_xp > 0) { - item.extra.champion_combat_xp = champion_combat_xp; + if (championCombatXp > 0) { + item.extra.champion_combat_xp = championCombatXp; } } if (item.tag?.ExtraAttributes?.farmed_cultivating != undefined) { - const { farmed_cultivating } = item.tag.ExtraAttributes; + const farmedCultivating = item.tag.ExtraAttributes.farmed_cultivating; - if (farmed_cultivating > 0) { - item.extra.farmed_cultivating = item.tag?.ExtraAttributes?.mined_crops?.toString() ?? farmed_cultivating; + if (farmedCultivating > 0) { + item.extra.farmed_cultivating = farmedCultivating.toString(); } } if (item.tag?.ExtraAttributes?.blocks_walked != undefined) { - const { blocks_walked } = item.tag.ExtraAttributes; + const blocksWalked = item.tag.ExtraAttributes.blocks_walked; - if (blocks_walked > 0) { - item.extra.blocks_walked = blocks_walked; + if (blocksWalked > 0) { + item.extra.blocks_walked = blocksWalked; } } @@ -323,9 +331,9 @@ export async function processItems(base64, source, customTextures = false, packs // Lore stuff const itemLore = item?.tag?.display?.Lore ?? []; - const lore_raw = [...itemLore]; + const loreRaw = [...itemLore]; - const lore = lore_raw != null ? lore_raw.map((a) => (a = helper.getRawLore(a))) : []; + const lore = loreRaw != null ? loreRaw.map((a) => (a = helper.getRawLore(a))) : []; item.rarity = null; item.categories = []; @@ -359,18 +367,38 @@ export async function processItems(base64, source, customTextures = false, packs ); } + if (item.extra?.compact_blocks) { + const compactBlocks = item.extra.compact_blocks; + + if (loreRaw) { + itemLore.push("", `§7Ores Mined: §c${compactBlocks.toLocaleString()}`); + if (compactBlocks >= 15000) { + itemLore.push(`§8MAXED OUT!`); + } else { + let toNextLevel = 0; + for (const e of constants.ENCHANTMENT_LADDERS.compact_ores) { + if (compactBlocks < e) { + toNextLevel = e - compactBlocks; + break; + } + } + itemLore.push(`§8${toNextLevel.toLocaleString()} ores to tier up!`); + } + } + } + if (item.extra?.expertise_kills) { - const expertise_kills = item.extra.expertise_kills; + const expertiseKills = item.extra.expertise_kills; - if (lore_raw) { - itemLore.push("", `§7Expertise Kills: §c${expertise_kills.toLocaleString()}`); - if (expertise_kills >= 15000) { + if (loreRaw) { + itemLore.push("", `§7Expertise Kills: §c${expertiseKills.toLocaleString()}`); + if (expertiseKills >= 15000) { itemLore.push(`§8MAXED OUT!`); } else { let toNextLevel = 0; - for (const e of constants.EXPERTISE_KILLS_LADDER) { - if (expertise_kills < e) { - toNextLevel = e - expertise_kills; + for (const e of constants.ENCHANTMENT_LADDERS.expertise_kills) { + if (expertiseKills < e) { + toNextLevel = e - expertiseKills; break; } } @@ -380,17 +408,17 @@ export async function processItems(base64, source, customTextures = false, packs } if (item.extra?.hecatomb_s_runs) { - const hecatomb_s_runs = item.extra.hecatomb_s_runs; + const hecatombSRuns = item.extra.hecatomb_s_runs; - if (lore_raw) { - itemLore.push("", `§7Hecatomb Runs: §c${hecatomb_s_runs.toLocaleString()}`); - if (hecatomb_s_runs >= 100) { + if (loreRaw) { + itemLore.push("", `§7Hecatomb Runs: §c${hecatombSRuns.toLocaleString()}`); + if (hecatombSRuns >= 100) { itemLore.push(`§8MAXED OUT!`); } else { let toNextLevel = 0; - for (const e of constants.hecatomb_s_runs_ladder) { - if (hecatomb_s_runs < e) { - toNextLevel = e - hecatomb_s_runs; + for (const e of constants.ENCHANTMENT_LADDERS.hecatomb_s_runs) { + if (hecatombSRuns < e) { + toNextLevel = e - hecatombSRuns; break; } } @@ -400,17 +428,17 @@ export async function processItems(base64, source, customTextures = false, packs } if (item.extra?.champion_combat_xp) { - const champion_combat_xp = Math.floor(item.extra.champion_combat_xp); + const championCombatXp = Math.floor(item.extra.champion_combat_xp); - if (lore_raw) { - itemLore.push("", `§7Champion XP: §c${champion_combat_xp.toLocaleString()}`); - if (champion_combat_xp >= 3000000) { + if (loreRaw) { + itemLore.push("", `§7Champion XP: §c${championCombatXp.toLocaleString()}`); + if (championCombatXp >= 3000000) { itemLore.push(`§8MAXED OUT!`); } else { let toNextLevel = 0; - for (const e of constants.champion_xp_ladder) { - if (champion_combat_xp < e) { - toNextLevel = Math.floor(e - champion_combat_xp); + for (const e of constants.ENCHANTMENT_LADDERS.champion_xp) { + if (championCombatXp < e) { + toNextLevel = Math.floor(e - championCombatXp); break; } } @@ -420,17 +448,17 @@ export async function processItems(base64, source, customTextures = false, packs } if (item.extra?.farmed_cultivating) { - const farmed_cultivating = Math.floor(item.extra.farmed_cultivating); + const farmedCultivating = Math.floor(item.extra.farmed_cultivating); - if (lore_raw) { - itemLore.push("", `§7Cultivating Crops: §c${farmed_cultivating.toLocaleString()}`); - if (farmed_cultivating >= 100000000) { + if (loreRaw) { + itemLore.push("", `§7Cultivating Crops: §c${farmedCultivating.toLocaleString()}`); + if (farmedCultivating >= 100000000) { itemLore.push(`§8MAXED OUT!`); } else { let toNextLevel = 0; - for (const e of constants.cultivating_crops_ladder) { - if (farmed_cultivating < e) { - toNextLevel = Math.floor(e - farmed_cultivating); + for (const e of constants.ENCHANTMENT_LADDERS.cultivating_crops) { + if (farmedCultivating < e) { + toNextLevel = Math.floor(e - farmedCultivating); break; } } @@ -440,17 +468,17 @@ export async function processItems(base64, source, customTextures = false, packs } if (item.extra?.blocks_walked) { - const blocks_walked = item.extra.blocks_walked; + const blocksWalked = item.extra.blocks_walked; - if (lore_raw) { - itemLore.push("", `§7Blocks Walked: §c${blocks_walked.toLocaleString()}`); - if (blocks_walked >= 100000) { + if (loreRaw) { + itemLore.push("", `§7Blocks Walked: §c${blocksWalked.toLocaleString()}`); + if (blocksWalked >= 100000) { itemLore.push(`§8MAXED OUT!`); } else { let toNextLevel = 0; for (const e of constants.PREHISTORIC_EGG_BLOCKS_WALKED_LADDER) { - if (blocks_walked < e) { - toNextLevel = e - blocks_walked; + if (blocksWalked < e) { + toNextLevel = e - blocksWalked; break; } } diff --git a/src/stats/missing.js b/src/stats/missing.js index a36bc5541d..23b05444b6 100644 --- a/src/stats/missing.js +++ b/src/stats/missing.js @@ -38,9 +38,9 @@ function getMissing(accessories) { const unique = ACCESSORIES.map(({ id, tier: rarity }) => ({ id, rarity })); for (const { id } of unique) { - if (id in constants.accessoryAliases === false) continue; + if (id in constants.ACCESSORY_ALIASES === false) continue; - for (const duplicate of constants.accessoryAliases[id]) { + for (const duplicate of constants.ACCESSORY_ALIASES[id]) { if (hasAccessory(accessories, duplicate, { ignoreRarity: true }) === true) { getAccessory(accessories, duplicate).id = id; } diff --git a/views/stats.ejs b/views/stats.ejs index 5abe176a87..ed9a737c46 100644 --- a/views/stats.ejs +++ b/views/stats.ejs @@ -552,10 +552,10 @@ const metaDescription = getMetaDescription()