Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Case Changing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Aug 15, 2024
1 parent 4b2e9e4 commit 44c3d5f
Show file tree
Hide file tree
Showing 28 changed files with 165 additions and 156 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"eamodio.gitlens",
"aaron-bond.better-comments"
"aaron-bond.better-comments",
"vitest.explorer"
]
}
21 changes: 14 additions & 7 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ import API from './API';
const clients: Client[] = [];

Check warning on line 8 in src/Client.ts

View workflow job for this annotation

GitHub Actions / check linting (eslint)

'Client' was used before it was defined

class Client {
readonly key: string;

declare options: ClientOptions;
declare requests: Requests;
declare cacheHandler: CacheHandler;
declare updater: Updater;
declare errors: Errors;

declare options: ClientOptions;
readonly key: string;

constructor(key: string, options?: ClientOptions) {
this.key = key;
declare interval: NodeJS.Timeout;

constructor(key: string, options?: ClientOptions) {
this.options = this.parasOptions(options);
this.requests = new Requests(this);
this.cacheHandler = new CacheHandler(this);
this.updater = new Updater(this);
this.errors = new Errors();

this.key = key;
if (!this.key.length) throw new Error(this.errors.NO_API_KEY);

for (const func in API) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
Expand All @@ -43,10 +45,9 @@ class Client {
}

if (this.options.checkForUpdates) {
setInterval(
this.interval = setInterval(
() => {
this.updater.checkForUpdates();
// 3600000 ms = 1 hour
},
1000 * 60 * (this.options.checkForUpdatesInterval ?? 60)
);
Expand All @@ -55,6 +56,12 @@ class Client {
clients.push(this);
}

destroy() {
const clientIndex = clients.findIndex((client) => client.key === this.key);
if (-1 !== clientIndex) clients.splice(clientIndex, 1);
if (this.interval) clearInterval(this.interval);
}

private parasOptions(options?: ClientOptions): ClientOptions {
return {
cache: options?.cache ?? true,
Expand Down
3 changes: 3 additions & 0 deletions src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class Errors {
INVALID_API_KEY: string =
'[Hypixel-API-Reborn] Invalid API Key! For help join our Discord Server https://discord.gg/NSEBNMM';
NO_API_KEY: string =
'[Hypixel-API-Reborn] No API Key specified! For help join our Discord Server https://discord.gg/NSEBNMM';
ERROR_CODE_CAUSE: string =
'[Hypixel-API-Reborn] Code: {code} - {cause}! For help join our Discord Server https://discord.gg/NSEBNMM';
ERROR_STATUSTEXT: string =
Expand All @@ -11,6 +13,7 @@ class Errors {
NO_UUID: string = '[Hypixel-API-Reborn] No uuid specified.';
UUID_NICKNAME_MUST_BE_A_STRING: string = '[Hypixel-API-Reborn] Nickname or uuid must be a string.';
MALFORMED_UUID: string = '[Hypixel-API-Reborn] Malformed UUID!';
PLAYER_HAS_NEVER_LOGGED: string = '[Hypixel-API-Reborn] Player has never logged into Hypixel.';
NO_GUILD_QUERY: string = '[Hypixel-API-Reborn] No guild search query specified.';
INVALID_GUILD_ID: string = '[Hypixel-API-Reborn] Specified Guild ID is invalid.';
INVALID_GUILD_SEARCH_PARAMETER: string =
Expand Down
22 changes: 11 additions & 11 deletions src/structures/MiniGames/Arcade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { removeSnakeCaseString } from '../../utils/removeSnakeCase';
import { weekAB, monthAB } from '../../utils/oscillation';
import divide from '../../utils/divide';
import Divide from '../../utils/Divide';

Check failure on line 5 in src/structures/MiniGames/Arcade.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../utils/Divide' or its corresponding type declarations.

function parseZombiesKills(data: Record<string, any>): Record<string, number> {
const matches = Array.from(Object.keys(data))
Expand Down Expand Up @@ -68,9 +68,9 @@ class Zombies {
this.killsByZombie = parseZombiesKills(data);
this.bulletsHit = data.bullets_hit_zombies || 0;
this.bulletsShot = data.bullets_shot_zombies || 0;
this.gunAccuracy = divide(this.bulletsHit, this.bulletsShot);
this.gunAccuracy = Divide(this.bulletsHit, this.bulletsShot);
this.headshots = data.headshots_zombies || 0;
this.headshotAccuracy = divide(this.headshots, this.bulletsShot);
this.headshotAccuracy = Divide(this.headshots, this.bulletsShot);
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ class BountyHunters {
this.wins = data.wins_oneinthequiver || 0;
this.kills = data.kills_oneinthequiver || 0;
this.deaths = data.deaths_oneinthequiver || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.bountyKills = data.bounty_kills_oneinthequiver || 0;
this.bowKills = data.bow_kills_oneinthequiver || 0;
this.swordKills = data.sword_kills_oneinthequiver || 0;
Expand All @@ -139,11 +139,11 @@ class CaptureTheWool {
constructor(data: Record<string, any>) {
this.wins = data.woolhunt_participated_wins || 0;
this.losses = data.woolhunt_participated_losses || 0;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.draws = data.woolhunt_participated_draws || 0;
this.kills = data.woolhunt_kills || 0;
this.deaths = data.woolhunt_deaths || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.assists = data.woolhunt_assists || 0;
this.woolPickedUp = data.woolhunt_wools_stolen || 0;
this.woolCaptured = data.woolhunt_wools_captured || 0;
Expand Down Expand Up @@ -371,13 +371,13 @@ class MiniWalls {
this.wins = data.wins_mini_walls || 0;
this.kills = data.kills_mini_walls || 0;
this.deaths = data.deaths_mini_walls || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.finalKills = data.final_kills_mini_walls || 0;
this.witherKills = data.wither_kills_mini_walls || 0;
this.witherDamage = data.wither_damage_mini_walls || 0;
this.arrowsShot = data.arrows_shot_mini_walls || 0;
this.arrowsHit = data.arrows_hit_mini_walls || 0;
this.bowAccuracy = divide(this.arrowsHit, this.arrowsShot);
this.bowAccuracy = Divide(this.arrowsHit, this.arrowsShot);
}
}
/**
Expand Down Expand Up @@ -407,7 +407,7 @@ class PixelPartyGameMode {
this.wins = data?.[`wins_${modeName}`] || 0;
this.gamesPlayed = data?.[`games_played_${modeName}`] || 0;
this.losses = this.gamesPlayed - this.wins;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.roundsPlayed = data?.[`rounds_completed_${modeName}`] || 0;
this.powerUpsCollected = data?.[`power_ups_collected_${modeName}`] || 0;
}
Expand All @@ -431,7 +431,7 @@ class PixelParty {
this.wins = data?.pixel_party?.wins || 0;
this.gamesPlayed = data?.pixel_party?.games_played || 0;
this.losses = this.gamesPlayed - this.wins;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.roundsPlayed = data?.pixel_party?.rounds_completed || 0;
this.powerUpsCollected = data?.pixel_party?.power_ups_collected || 0;
this.normal = new PixelPartyGameMode(data.pixel_party, 'normal');
Expand All @@ -453,7 +453,7 @@ class ThrowOut {
this.wins = data.wins_throw_out || 0;
this.kills = data.kills_throw_out || 0;
this.deaths = data.deaths_throw_out || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
}
}
/**
Expand Down
6 changes: 3 additions & 3 deletions src/structures/MiniGames/ArenaBrawl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import divide from '../../utils/divide';
import Divide from '../../utils/Divide';

Check failure on line 1 in src/structures/MiniGames/ArenaBrawl.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../utils/Divide' or its corresponding type declarations.

class ArenaBrawlMode {
damage: number;
Expand All @@ -15,11 +15,11 @@ class ArenaBrawlMode {
this.damage = data[`damage_${mode}`];
this.kills = data[`kills_${mode}`];
this.deaths = data[`deaths_${mode}`];
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.healed = data[`healed_${mode}`];
this.wins = data[`wins_${mode}`];
this.losses = data[`losses_${mode}`];
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.games = data[`games_${mode}`];
this.winstreak = data[`win_streaks_${mode}`];
}
Expand Down
30 changes: 15 additions & 15 deletions src/structures/MiniGames/BedWars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import divide from '../../utils/divide';
import Divide from '../../utils/Divide';

Check failure on line 1 in src/structures/MiniGames/BedWars.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../utils/Divide' or its corresponding type declarations.

export type BedWarsPrestige =
| 'Stone'
Expand Down Expand Up @@ -167,18 +167,18 @@ function generateStatsForMode(data: Record<string, any>, mode: string): BedWarsM
beds: {
broken: data[`${mode}_beds_broken_bedwars`] || 0,
lost: data[`${mode}_beds_lost_bedwars`] || 0,
BLRatio: divide(data[`${mode}_beds_broken_bedwars`], data[`${mode}_beds_lost_bedwars`])
BLRatio: Divide(data[`${mode}_beds_broken_bedwars`], data[`${mode}_beds_lost_bedwars`])
},

avg: {
kills: divide(data[`${mode}_kills_bedwars`], data[`${mode}_games_played_bedwars`]),
finalKills: divide(data[`${mode}_final_kills_bedwars`], data[`${mode}_games_played_bedwars`]),
bedsBroken: divide(data[`${mode}_beds_broken_bedwars`], data[`${mode}_games_played_bedwars`])
kills: Divide(data[`${mode}_kills_bedwars`], data[`${mode}_games_played_bedwars`]),
finalKills: Divide(data[`${mode}_final_kills_bedwars`], data[`${mode}_games_played_bedwars`]),
bedsBroken: Divide(data[`${mode}_beds_broken_bedwars`], data[`${mode}_games_played_bedwars`])
},

KDRatio: divide(data[`${mode}_kills_bedwars`], data[`${mode}_deaths_bedwars`]),
WLRatio: divide(data[`${mode}_wins_bedwars`], data[`${mode}_losses_bedwars`]),
finalKDRatio: divide(data[`${mode}_final_kills_bedwars`], data[`${mode}_final_deaths_bedwars`])
KDRatio: Divide(data[`${mode}_kills_bedwars`], data[`${mode}_deaths_bedwars`]),
WLRatio: Divide(data[`${mode}_wins_bedwars`], data[`${mode}_losses_bedwars`]),
finalKDRatio: Divide(data[`${mode}_final_kills_bedwars`], data[`${mode}_final_deaths_bedwars`])
};
}

Expand Down Expand Up @@ -428,16 +428,16 @@ class BedWars {
this.beds = {
lost: data.beds_lost_bedwars || 0,
broken: data.beds_broken_bedwars || 0,
BLRatio: divide(data.beds_broken_bedwars, data.beds_lost_bedwars)
BLRatio: Divide(data.beds_broken_bedwars, data.beds_lost_bedwars)
};
this.avg = {
kills: divide(this.kills, this.playedGames),
finalKills: divide(this.finalKills, this.playedGames),
bedsBroken: divide(this.beds.broken, this.playedGames)
kills: Divide(this.kills, this.playedGames),
finalKills: Divide(this.finalKills, this.playedGames),
bedsBroken: Divide(this.beds.broken, this.playedGames)
};
this.KDRatio = divide(this.kills, this.deaths);
this.finalKDRatio = divide(this.finalKills, this.finalDeaths);
this.WLRatio = divide(this.wins, this.losses);
this.KDRatio = Divide(this.kills, this.deaths);
this.finalKDRatio = Divide(this.finalKills, this.finalDeaths);
this.WLRatio = Divide(this.wins, this.losses);
this.solo = generateStatsForMode(data, 'eight_one');
this.doubles = generateStatsForMode(data, 'eight_two');
this.threes = generateStatsForMode(data, 'four_three');
Expand Down
14 changes: 7 additions & 7 deletions src/structures/MiniGames/BlitzSurvivalGames.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import divide from '../../utils/divide';
import Divide from '../../utils/Divide';

Check failure on line 1 in src/structures/MiniGames/BlitzSurvivalGames.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../utils/Divide' or its corresponding type declarations.

class BlitzSGKit {
level: number;
Expand All @@ -25,14 +25,14 @@ class BlitzSGKit {
this.exp = data[`exp_${kitName}`] || 0;
this.kills = data[`kills_${kitName}`] || 0;
this.deaths = data[`deaths_${kitName}`] || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.wins = data[`wins_${kitName}`] || 0;
this.gamesPlayed = data[`games_played_${kitName}`] || 0;
this.losses = this.gamesPlayed - this.wins;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.arrowsShot = data[`arrows_fired_${kitName}`] || 0;
this.arrowsHit = data[`arrows_hit_${kitName}`] || 0;
this.bowAccuracy = divide(this.arrowsHit, this.arrowsShot);
this.bowAccuracy = Divide(this.arrowsHit, this.arrowsShot);
this.damage = data[`damage_${kitName}`] || 0;
this.damageTaken = data[`damage_taken_${kitName}`] || 0;
this.potionsDrunk = data[`potions_drunk_${kitName}`] || 0;
Expand Down Expand Up @@ -115,16 +115,16 @@ class BlitzSurvivalGames {
this.killsSolo = data.kills_solo_normal || 0;
this.killsTeams = data.kills_teams_normal || 0;
this.deaths = data.deaths || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.wins = data.wins || 0;
this.winsSolo = data.wins_solo_normal || 0;
this.winsTeam = data.wins_teams || 0;
this.gamesPlayed = data.games_played || 0;
this.losses = this.gamesPlayed - this.wins;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.arrowsShot = data.arrows_fired || 0;
this.arrowsHit = data.arrows_hit || 0;
this.bowAccuracy = divide(this.arrowsHit, this.arrowsShot);
this.bowAccuracy = Divide(this.arrowsHit, this.arrowsShot);
this.damage = data.damage || 0;
this.damageTaken = data.damage_taken || 0;
this.potionsDrunk = data.potions_drunk || 0;
Expand Down
4 changes: 2 additions & 2 deletions src/structures/MiniGames/BuildBattle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import divide from '../../utils/divide';
import Divide from '../../utils/Divide';

Check failure on line 1 in src/structures/MiniGames/BuildBattle.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../utils/Divide' or its corresponding type declarations.

export interface BuildBattleWins {
solo: number;
Expand All @@ -23,7 +23,7 @@ class BuildBattle {
this.score = data.score || 0;
this.totalWins = data.wins || 0;
this.games = data.games_played || 0;
this.WLRatio = divide(this.totalWins, this.games);
this.WLRatio = Divide(this.totalWins, this.games);
this.superVotes = data.super_votes || 0;
this.coins = data.coins || 0;
this.totalVotes = data.total_votes || 0;
Expand Down
18 changes: 9 additions & 9 deletions src/structures/MiniGames/CopsAndCrims.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import divide from '../../utils/divide';
import Divide from '../../utils/Divide';

Check failure on line 1 in src/structures/MiniGames/CopsAndCrims.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../utils/Divide' or its corresponding type declarations.
/**
* Cops and crims Defusal class
*/
Expand All @@ -23,11 +23,11 @@ class CopsAndCrimsDefusal {
this.headshotKills = data.headshot_kills || 0;
this.assists = data.assists || 0;
this.deaths = data.deaths || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.wins = data.game_wins || 0;
this.gamesPlayed = data.game_plays || 0;
this.losses = this.gamesPlayed - this.wins;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.roundWins = data.round_wins || 0;
this.shotsFired = data.shots_fired || 0;
this.bombsDefused = data.bombs_defused || 0;
Expand All @@ -54,11 +54,11 @@ class CopsAndCrimsDeathmatch {
this.kills = data.kills_deathmatch || 0;
this.assists = data.assists_deathmatch || 0;
this.deaths = data.deaths_deathmatch || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.wins = data.game_wins_deathmatch || 0;
this.gamesPlayed = data.game_plays_deathmatch || 0;
this.losses = this.gamesPlayed - this.wins;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.killsAsCrim = data.criminal_kills_deathmatch || 0;
this.killsAsCop = data.cop_kills_deathmatch || 0;
}
Expand All @@ -82,11 +82,11 @@ class CopsAndCrimsGunGame {
this.kills = data.kills_gungame || 0;
this.assists = data.assists_gungame || 0;
this.deaths = data.deaths_gungame || 0;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.wins = data.game_wins_gungame || 0;
this.gamesPlayed = data.game_plays_gungame || 0;
this.losses = this.gamesPlayed - this.wins;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.killsAsCrim = data.criminal_kills_gungame || 0;
this.killsAsCop = data.cop_kills_gungame || 0;
this.fastestWin = data.fastest_win_gungame || 0;
Expand Down Expand Up @@ -122,11 +122,11 @@ class CopsAndCrims {
this.kills = this.defusal.kills + this.deathmath.kills + this.gunGame.kills;
this.assists = this.defusal.assists + this.deathmath.assists + this.gunGame.assists;
this.deaths = this.defusal.deaths + this.deathmath.deaths + this.gunGame.deaths;
this.KDRatio = divide(this.kills, this.deaths);
this.KDRatio = Divide(this.kills, this.deaths);
this.wins = this.defusal.wins + this.deathmath.wins + this.gunGame.wins;
this.gamesPlayed = this.defusal.gamesPlayed + this.deathmath.gamesPlayed + this.gunGame.gamesPlayed;
this.losses = this.gamesPlayed - this.wins;
this.WLRatio = divide(this.wins, this.losses);
this.WLRatio = Divide(this.wins, this.losses);
this.killsAsCrim = this.defusal.killsAsCrim + this.deathmath.killsAsCrim + this.gunGame.killsAsCrim;
this.killsAsCop = this.defusal.killsAsCop + this.deathmath.killsAsCop + this.gunGame.killsAsCop;
this.prefixColor = data.lobbyPrefixColor || '';
Expand Down
Loading

0 comments on commit 44c3d5f

Please sign in to comment.