Updated and cleaned up files

This commit is contained in:
2023-11-15 19:08:13 +01:00
parent b897670c97
commit 325d310de5
8 changed files with 114 additions and 118 deletions

View File

@@ -1,5 +1,4 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const getuuid = require('../utils/functions');
module.exports = { module.exports = {
name: 'dev-info', name: 'dev-info',

View File

@@ -3,7 +3,7 @@ const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require("../co
const hypixelApiKey = process.env.HYPIXELAPIKEY; const hypixelApiKey = process.env.HYPIXELAPIKEY;
const { color } = require("../config/options.json"); const { color } = require("../config/options.json");
const fetch = require("axios"); const fetch = require("axios");
const { getExactLevel, skywarsLevel, getLevelForExp } = require("../utils/functions.js"); const { hypixelLevel, bedwarsLevel, skywarsLevel } = require("../utils/utils.js");
module.exports = { module.exports = {
name: "check", name: "check",
@@ -97,7 +97,7 @@ module.exports = {
//bedwars level //bedwars level
const hsbwexp = stats.data.player.stats.Bedwars.Experience; const hsbwexp = stats.data.player.stats.Bedwars.Experience;
const hsbwstars = getLevelForExp(hsbwexp); const hsbwstars = bedwarsLevel(hsbwexp);
// bedwars fkdr // bedwars fkdr
const hsbwfk = stats.data.player.stats.Bedwars.final_kills_bedwars; const hsbwfk = stats.data.player.stats.Bedwars.final_kills_bedwars;
const hsbwfd = stats.data.player.stats.Bedwars.final_deaths_bedwars; const hsbwfd = stats.data.player.stats.Bedwars.final_deaths_bedwars;
@@ -124,7 +124,7 @@ module.exports = {
const hsduelswlr = hsduelswins / hsduelslosses; const hsduelswlr = hsduelswins / hsduelslosses;
// network level // network level
const hypixelExp = stats.data.player.networkExp; const hypixelExp = stats.data.player.networkExp;
const level = getExactLevel(hypixelExp); const level = hypixelLevel(hypixelExp);
if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) { if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) {
var bwtitle = var bwtitle =

View File

@@ -3,7 +3,7 @@ const fetch = require('axios');
const guildapp = require('../../schemas/guildAppSchema.js'); const guildapp = require('../../schemas/guildAppSchema.js');
const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require('../../config/reqs.json'); const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require('../../config/reqs.json');
const hypixelApiKey = process.env.HYPIXELAPIKEY; const hypixelApiKey = process.env.HYPIXELAPIKEY;
const { getExactLevel, skywarsLevel, getLevelForExp } = require("../../utils/functions.js"); const { hypixelLevel, bedwarsLevel, skywarsLevel } = require("../../utils/utils.js");
module.exports = { module.exports = {
name: 'checkstats', name: 'checkstats',
@@ -80,7 +80,7 @@ module.exports = {
//bedwars level //bedwars level
const hsbwexp = stats.data.player.stats.Bedwars.Experience; const hsbwexp = stats.data.player.stats.Bedwars.Experience;
const hsbwstars = getLevelForExp(hsbwexp); const hsbwstars = bedwarsLevel(hsbwexp);
// bedwars fkdr // bedwars fkdr
const hsbwfk = stats.data.player.stats.Bedwars.final_kills_bedwars; const hsbwfk = stats.data.player.stats.Bedwars.final_kills_bedwars;
const hsbwfd = stats.data.player.stats.Bedwars.final_deaths_bedwars; const hsbwfd = stats.data.player.stats.Bedwars.final_deaths_bedwars;
@@ -107,7 +107,7 @@ module.exports = {
const hsduelswlr = hsduelswins / hsduelslosses; const hsduelswlr = hsduelswins / hsduelslosses;
// network level // network level
const hypixelExp = stats.data.player.networkExp; const hypixelExp = stats.data.player.networkExp;
const level = getExactLevel(hypixelExp); const level = hypixelLevel(hypixelExp);
if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) { if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) {
var bwtitle = "<a:cross_a:1087808606897983539> This player does not meet the BedWars requirements." var bwtitle = "<a:cross_a:1087808606897983539> This player does not meet the BedWars requirements."

View File

@@ -1,111 +0,0 @@
/* ---------- bedwars level ---------- */
function getExpForLevel(level) {
if (level == 0) return 0;
var respectedLevel = getLevelRespectingPrestige(level);
if (respectedLevel > EASY_LEVELS) {
return 5000;
}
switch (respectedLevel) {
case 1:
return 500;
case 2:
return 1000;
case 3:
return 2000;
case 4:
return 3500;
}
return 5000;
}
function getLevelRespectingPrestige(level) {
if (level > HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE) {
return level - HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE;
}
else {
return level % LEVELS_PER_PRESTIGE;
}
}
const EASY_LEVELS = 4;
const EASY_LEVELS_XP = 7000;
const XP_PER_PRESTIGE = 96 * 5000 + EASY_LEVELS_XP;
const LEVELS_PER_PRESTIGE = 100;
const HIGHEST_PRESTIGE = 50;
function getLevelForExp(exp) {
var prestiges = Math.floor(exp / XP_PER_PRESTIGE);
var level = prestiges * LEVELS_PER_PRESTIGE;
var expWithoutPrestiges = exp - (prestiges * XP_PER_PRESTIGE);
for (let i = 1; i <= EASY_LEVELS; ++i) {
var expForEasyLevel = getExpForLevel(i);
if (expWithoutPrestiges < expForEasyLevel) {
break;
}
level++;
expWithoutPrestiges -= expForEasyLevel;
}
return level + expWithoutPrestiges / 5000
}
// hypixel
const BASE = 10000;
const GROWTH = 2500;
const HALF_GROWTH = 0.5 * GROWTH;
const REVERSE_PQ_PREFIX = -(BASE - 0.5 * GROWTH) / GROWTH;
const REVERSE_CONST = REVERSE_PQ_PREFIX * REVERSE_PQ_PREFIX;
const GROWTH_DIVIDES_2 = 2 / GROWTH;
function getLevel(exp) {
return exp <= 1 ? 1 : Math.floor(1 + REVERSE_PQ_PREFIX + Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp));
}
function getExactLevel(exp) {
return getLevel(exp) + getPercentageToNextLevel(exp);
}
function getExpFromLevelToNext(level) {
return level < 1 ? BASE : GROWTH * (level - 1) + BASE;
}
function getTotalExpToLevel(level) {
const lv = Math.floor(level); const
x0 = getTotalExpToFullLevel(lv);
if (level === lv) return x0;
return (getTotalExpToFullLevel(lv + 1) - x0) * (level % 1) + x0;
}
function getTotalExpToFullLevel(level) {
return (HALF_GROWTH * (level - 2) + BASE) * (level - 1);
}
function getPercentageToNextLevel(exp) {
const lv = getLevel(exp);
const x0 = getTotalExpToLevel(lv);
return (exp - x0) / (getTotalExpToLevel(lv + 1) - x0);
}
/* ---------- skywars level ---------- */
function skywarsLevel(xp) {
var xps = [0, 20, 70, 150, 250, 500, 1000, 2000, 3500, 6000, 10000, 15000];
let exactLevel = 0
if (xp >= 15000) {
exactLevel = (xp - 15000) / 10000 + 12;
return exactLevel;
} else {
for (i = 0; i < xps.length; i++) {
if (xp < xps[i]) {
exactLevel = i + (xp - xps[i - 1]) / (xps[i] - xps[i - 1]);
return exactLevel;
}
}
}
}
module.exports = {
getExactLevel,
skywarsLevel,
getLevelForExp
}

View File

@@ -0,0 +1,52 @@
function getExpForLevel(level) {
if (level == 0) return 0;
var respectedLevel = getLevelRespectingPrestige(level);
if (respectedLevel > EASY_LEVELS) {
return 5000;
}
switch (respectedLevel) {
case 1:
return 500;
case 2:
return 1000;
case 3:
return 2000;
case 4:
return 3500;
}
return 5000;
}
function getLevelRespectingPrestige(level) {
if (level > HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE) {
return level - HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE;
}
else {
return level % LEVELS_PER_PRESTIGE;
}
}
const EASY_LEVELS = 4;
const EASY_LEVELS_XP = 7000;
const XP_PER_PRESTIGE = 96 * 5000 + EASY_LEVELS_XP;
const LEVELS_PER_PRESTIGE = 100;
const HIGHEST_PRESTIGE = 50;
function bedwarsLevel(exp) {
var prestiges = Math.floor(exp / XP_PER_PRESTIGE);
var level = prestiges * LEVELS_PER_PRESTIGE;
var expWithoutPrestiges = exp - (prestiges * XP_PER_PRESTIGE);
for (let i = 1; i <= EASY_LEVELS; ++i) {
var expForEasyLevel = getExpForLevel(i);
if (expWithoutPrestiges < expForEasyLevel) {
break;
}
level++;
expWithoutPrestiges -= expForEasyLevel;
}
return level + expWithoutPrestiges / 5000
}
module.exports = { bedwarsLevel }

View File

@@ -0,0 +1,34 @@
const BASE = 10000;
const GROWTH = 2500;
const HALF_GROWTH = 0.5 * GROWTH;
const REVERSE_PQ_PREFIX = -(BASE - 0.5 * GROWTH) / GROWTH;
const REVERSE_CONST = REVERSE_PQ_PREFIX * REVERSE_PQ_PREFIX;
const GROWTH_DIVIDES_2 = 2 / GROWTH;
function getLevel(exp) {
return exp <= 1 ? 1 : Math.floor(1 + REVERSE_PQ_PREFIX + Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp));
}
function hypixelLevel(exp) {
return getLevel(exp) + getPercentageToNextLevel(exp);
}
function getTotalExpToLevel(level) {
const lv = Math.floor(level); const
x0 = getTotalExpToFullLevel(lv);
if (level === lv) return x0;
return (getTotalExpToFullLevel(lv + 1) - x0) * (level % 1) + x0;
}
function getTotalExpToFullLevel(level) {
return (HALF_GROWTH * (level - 2) + BASE) * (level - 1);
}
function getPercentageToNextLevel(exp) {
const lv = getLevel(exp);
const x0 = getTotalExpToLevel(lv);
return (exp - x0) / (getTotalExpToLevel(lv + 1) - x0);
}
module.exports = { hypixelLevel }

View File

@@ -0,0 +1,17 @@
function skywarsLevel(xp) {
var xps = [0, 20, 70, 150, 250, 500, 1000, 2000, 3500, 6000, 10000, 15000];
let exactLevel = 0
if (xp >= 15000) {
exactLevel = (xp - 15000) / 10000 + 12;
return exactLevel;
} else {
for (i = 0; i < xps.length; i++) {
if (xp < xps[i]) {
exactLevel = i + (xp - xps[i - 1]) / (xps[i] - xps[i - 1]);
return exactLevel;
}
}
}
}
module.exports = { skywarsLevel }

5
utils/utils.js Normal file
View File

@@ -0,0 +1,5 @@
const { skywarsLevel } = require('./functions/skywars.js')
const { bedwarsLevel } = require('./functions/bedwars.js')
const { hypixelLevel } = require('./functions/hypixel.js')
module.exports = { skywarsLevel, bedwarsLevel, hypixelLevel }