Skip to content

Commit

Permalink
fix: solve some of the eslint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Nov 21, 2023
1 parent e157487 commit 5b8bd52
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 116 deletions.
6 changes: 3 additions & 3 deletions public/resources/ts/themes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const themes = new Map<string, Promise<Theme>>();
export const THEMES = new Map<string, Promise<Theme>>();

/**
* converts a hex color to it's rgb components
Expand Down Expand Up @@ -33,12 +33,12 @@ async function fetchTheme(urlString: string): Promise<Theme> {
}

export function getTheme(urlString: string): Promise<Theme> {
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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/constants/accessories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 17 additions & 11 deletions src/constants/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
};
18 changes: 9 additions & 9 deletions src/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 4 additions & 4 deletions src/hashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { promisify } from "util";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Check warning on line 7 in src/hashes.js

View workflow job for this annotation

GitHub Actions / check linting (es-lint)

Variable name `__dirname` must match one of the following formats: camelCase, UPPER_CASE

export const hashedDirectories = ["css"];
export const HASHED_DIRECTORIES = ["css"];

export function getFileHash(filename) {
return new Promise((resolve, reject) => {
Expand All @@ -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));
Expand All @@ -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;
Expand Down
38 changes: 19 additions & 19 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -775,7 +775,7 @@ export function generateItem(data) {
};
}

const default_data = {
const DEFAULT_DATA = {
id: 389,
Damage: 0,
Count: 1,
Expand Down Expand Up @@ -807,7 +807,7 @@ export function generateItem(data) {
}

// Creating final item
return Object.assign(default_data, data);
return Object.assign(DEFAULT_DATA, data);
}

/**
Expand Down Expand Up @@ -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("");
Expand Down
1 change: 1 addition & 0 deletions src/mongo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { MongoClient } from "mongodb";
import credentials from "./credentials.js";

Expand Down
1 change: 1 addition & 0 deletions src/redis.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import Redis from "ioredis";
import credentials from "./credentials.js";

Expand Down
10 changes: 5 additions & 5 deletions src/stats/items/accessories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 5b8bd52

Please sign in to comment.