Updated dir structure
This commit is contained in:
86
src/utils/Hypixel/account.ts
Normal file
86
src/utils/Hypixel/account.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import fetch from "axios"
|
||||
import env from "utils/Env"
|
||||
import { Player, PlayerData } from "interfaces"
|
||||
import { Guild, GuildData } from "interfaces"
|
||||
const apikey = env.prod.hypixelapikey
|
||||
const mojang = "https://api.mojang.com/users/profiles/minecraft/"
|
||||
const mojanguuid = "https://sessionserver.mojang.com/session/minecraft/profile/"
|
||||
const hypixel = "https://api.hypixel.net/player"
|
||||
const guild = "https://api.hypixel.net/guild"
|
||||
const minotar = "https://minotar.net/helm/"
|
||||
type GuildQuerqType = "player" | "name" | "id"
|
||||
|
||||
type Profile = {
|
||||
data: {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
}
|
||||
|
||||
type Profile2 = {
|
||||
data: {
|
||||
id: string
|
||||
name: string
|
||||
properties: { name: string; value: string }[]
|
||||
profileActions: []
|
||||
}
|
||||
}
|
||||
|
||||
async function getUUID(ign: string): Promise<string | null> {
|
||||
try {
|
||||
const req: Profile = await fetch(mojang + ign)
|
||||
return req.data.id
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function getIGN(uuid: string): Promise<string | null> {
|
||||
try {
|
||||
const req: Profile2 = await fetch(mojanguuid + uuid)
|
||||
return req.data.name
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function getPlayer(uuid: string): Promise<PlayerData | null> {
|
||||
const playerReq: Player = await fetch(hypixel, {
|
||||
params: {
|
||||
key: apikey,
|
||||
uuid: uuid,
|
||||
},
|
||||
})
|
||||
|
||||
if (!playerReq.data.player) {
|
||||
return null
|
||||
}
|
||||
|
||||
return playerReq.data.player
|
||||
}
|
||||
|
||||
async function getGuild(
|
||||
query: string,
|
||||
type?: GuildQuerqType,
|
||||
): Promise<GuildData | null> {
|
||||
const reqType = type ? type : "player"
|
||||
|
||||
const guildReq: Guild = await fetch(guild, {
|
||||
params: {
|
||||
key: apikey,
|
||||
[reqType]: query,
|
||||
},
|
||||
})
|
||||
|
||||
if (!guildReq.data.guild) {
|
||||
return null
|
||||
}
|
||||
|
||||
return guildReq.data.guild
|
||||
}
|
||||
|
||||
async function getHeadURL(ign: string): Promise<string | null> {
|
||||
return minotar + ign
|
||||
}
|
||||
|
||||
export { getUUID, getIGN, getPlayer, getGuild, getHeadURL }
|
||||
54
src/utils/Hypixel/bedwars.ts
Normal file
54
src/utils/Hypixel/bedwars.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function getExpForLevel(level: number): number {
|
||||
if (level == 0) return 0
|
||||
|
||||
const 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: number): number {
|
||||
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: number): number {
|
||||
const prestiges = Math.floor(exp / XP_PER_PRESTIGE)
|
||||
let level = prestiges * LEVELS_PER_PRESTIGE
|
||||
let expWithoutPrestiges = exp - prestiges * XP_PER_PRESTIGE
|
||||
|
||||
for (let i = 1; i <= EASY_LEVELS; ++i) {
|
||||
const expForEasyLevel = getExpForLevel(i)
|
||||
if (expWithoutPrestiges < expForEasyLevel) {
|
||||
break
|
||||
}
|
||||
level++
|
||||
expWithoutPrestiges -= expForEasyLevel
|
||||
}
|
||||
return level + expWithoutPrestiges / 5000
|
||||
}
|
||||
|
||||
export { bedwarsLevel }
|
||||
48
src/utils/Hypixel/guild.ts
Normal file
48
src/utils/Hypixel/guild.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function guildLevel(exp: number): number {
|
||||
const EXP_NEEDED = [
|
||||
100000, 150000, 250000, 500000, 750000, 1000000, 1250000, 1500000,
|
||||
2000000, 2500000, 2500000, 2500000, 2500000, 2500000, 3000000,
|
||||
]
|
||||
|
||||
let level = 0
|
||||
|
||||
// Increments by one from zero to the level cap
|
||||
for (let i = 0; i <= 1000; i += 1) {
|
||||
// need is the required exp to get to the next level
|
||||
let need = 0
|
||||
if (i >= EXP_NEEDED.length) {
|
||||
need = EXP_NEEDED[EXP_NEEDED.length - 1]
|
||||
} else {
|
||||
need = EXP_NEEDED[i]
|
||||
}
|
||||
|
||||
// If the required exp to get to the next level isn't met returns
|
||||
// the current level plus progress towards the next (unused exp/need)
|
||||
// Otherwise increments the level and substracts the used exp from exp var
|
||||
if (exp - need < 0) {
|
||||
return Math.round((level + exp / need) * 100) / 100
|
||||
}
|
||||
level += 1
|
||||
exp -= need
|
||||
}
|
||||
|
||||
// Returns the level cap - currently 1000
|
||||
// If changed here, also change in for loop above
|
||||
return 1000
|
||||
}
|
||||
/*
|
||||
Code used from the hypixel-guild-bot project https://github.com/SimplyNo/hypixel-guild-bot
|
||||
*/
|
||||
function scaledGEXP(input: number): number {
|
||||
if (input <= 200000) return Number(input)
|
||||
if (input <= 700000)
|
||||
return Number(Math.round((input - 200000) / 10 + 200000))
|
||||
if (input > 700000)
|
||||
return Number(Math.round((input - 700000) / 33 + 250000))
|
||||
return 0
|
||||
}
|
||||
|
||||
export { guildLevel, scaledGEXP }
|
||||
42
src/utils/Hypixel/hypixel.ts
Normal file
42
src/utils/Hypixel/hypixel.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
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: number): number {
|
||||
return exp <= 1
|
||||
? 1
|
||||
: Math.floor(
|
||||
1 +
|
||||
REVERSE_PQ_PREFIX +
|
||||
Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp),
|
||||
)
|
||||
}
|
||||
|
||||
function hypixelLevel(exp: number): number {
|
||||
return getLevel(exp) + getPercentageToNextLevel(exp)
|
||||
}
|
||||
|
||||
function getTotalExpToLevel(level: number): number {
|
||||
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: number): number {
|
||||
return (HALF_GROWTH * (level - 2) + BASE) * (level - 1)
|
||||
}
|
||||
|
||||
function getPercentageToNextLevel(exp: number): number {
|
||||
const lv = getLevel(exp)
|
||||
const x0 = getTotalExpToLevel(lv)
|
||||
return (exp - x0) / (getTotalExpToLevel(lv + 1) - x0)
|
||||
}
|
||||
|
||||
export { hypixelLevel }
|
||||
12
src/utils/Hypixel/index.ts
Normal file
12
src/utils/Hypixel/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export { skywarsLevel } from "./skywars"
|
||||
export { bedwarsLevel } from "./bedwars"
|
||||
export { hypixelLevel } from "./hypixel"
|
||||
export { formatUuid } from "./uuid"
|
||||
export { guildLevel, scaledGEXP } from "./guild"
|
||||
export {
|
||||
getUUID,
|
||||
getIGN,
|
||||
getPlayer,
|
||||
getGuild,
|
||||
getHeadURL,
|
||||
} from "./account"
|
||||
22
src/utils/Hypixel/skywars.ts
Normal file
22
src/utils/Hypixel/skywars.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function skywarsLevel(xp: number): number {
|
||||
const 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 if (xp < 15000) {
|
||||
for (let i = 0; i < xps.length; i++) {
|
||||
if (xp < xps[i]) {
|
||||
exactLevel = i + (xp - xps[i - 1]) / (xps[i] - xps[i - 1])
|
||||
return exactLevel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
export { skywarsLevel }
|
||||
5
src/utils/Hypixel/uuid.ts
Normal file
5
src/utils/Hypixel/uuid.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
function formatUuid(uuid: string): string {
|
||||
return uuid.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5")
|
||||
}
|
||||
|
||||
export { formatUuid }
|
||||
Reference in New Issue
Block a user