Skip to content

Commit

Permalink
refactor: !ww command
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Apr 21, 2023
1 parent 1249e4a commit adcf0ea
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
4 changes: 3 additions & 1 deletion data/skyblockNotifer.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
"Blitz Duo 3rd Iteration Tournament Results! | https://hypixel.net/threads/blitz-duo-3rd-iteration-tournament-results.5318905/",
"SkyBlock Update 0.18.2 - Garden and Stranded Update | https://hypixel.net/threads/skyblock-update-0-18-2-garden-and-stranded-update.5317809/",
"[March 24] Various Grammatical Fixes | https://hypixel.net/threads/march-24-various-grammatical-fixes.5314082/",
"10 Year Anniversary Contests - Results + Surprise Gift! | https://hypixel.net/threads/10-year-anniversary-contests-results-surprise-gift.5333726/"
"10 Year Anniversary Contests - Results + Surprise Gift! | https://hypixel.net/threads/10-year-anniversary-contests-results-surprise-gift.5333726/",
"SkyBlock Patch 0.18.3 - Garden Crop Growth & Presets, Bazaar & Sack Additions, Bug Fixes, & More | https://hypixel.net/threads/skyblock-patch-0-18-3-garden-crop-growth-presets-bazaar-sack-additions-bug-fixes-more.5324136/",
"UHC Modifiers, Achievements & Bug fixes | https://hypixel.net/threads/uhc-modifiers-achievements-bug-fixes.4035874/"
]
}
13 changes: 8 additions & 5 deletions src/contracts/minecraftCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ class minecraftCommand {
const listener = async (msg) => {
if (msg.toString().includes('You are sending commands too fast! Please slow down.') && !msg.toString().includes(':')) {
bot.removeListener("message", listener);
n++;

if (n === 5) {
n++;
if (n >= 5) {
return this.send("/gc Command failed to send message after 5 attempts. Please try again later.");
}

await delay(1000);
await delay(69.420);
return this.send(message);
}

else if (msg.toString().includes("You cannot say the same message twice!") === true && msg.toString().includes(":") === false && message.startsWith("/gc") === true) {
bot.removeListener("message", listener);
n++;

if (n === 5) {
if (n >= 5) {
return this.send("/gc Command failed to send message after 5 attempts. Please try again later.");
}

Expand All @@ -47,7 +48,9 @@ class minecraftCommand {
bot.chat(message);

setTimeout(() => {
bot.removeListener("message", listener);
if (bot.listenerCount("message") > 0) {
bot.removeListener("message", listener);
}
}, 500);
}

Expand Down
4 changes: 3 additions & 1 deletion src/minecraft/commands/skyblockCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class SkyblockCommand extends minecraftCommand {

this.send(
`/gc ${username}'s Level: ${
data.profile.leveling.experience / 100
data.profile.leveling?.experience
? data.profile.leveling.experience / 100
: 0
} | Senither Weight: ${senitherWeight} | Lily Weight: ${lilyWeight} | Skill Average: ${skillAverage} | Slayer: ${slayerXp} | Catacombs: ${catacombsLevel} | Class Average: ${classAverage} | Networth: ${networthValue} | Accessories: ${talismanCount} | Recombobulated: ${recombobulatedCount} | Enriched: ${enrichmentCount}`
);
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion src/minecraft/commands/skyblockLevelCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class CatacombsCommand extends minecraftCommand {

this.send(
`/gc ${username}'s Skyblock Level: ${
data.profile.leveling.experience / 100
data.profile.leveling?.experience
? data.profile.leveling.experience / 100
: 0
}`
);
} catch (error) {
Expand Down
38 changes: 14 additions & 24 deletions src/minecraft/commands/woolwarsCommand.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const minecraftCommand = require("../../contracts/minecraftCommand.js");
const config = require("../../../config.json");
const axios = require("axios");
const { toFixed } = require("../../contracts/helperFunctions.js");
const { getUUID } = require("../../contracts/API/PlayerDBAPI.js");
const hypixel = require("../../contracts/API/HypixelRebornAPI.js");

class WoolwarsCommand extends minecraftCommand {
constructor(minecraft) {
Expand All @@ -24,42 +21,35 @@ class WoolwarsCommand extends minecraftCommand {
try {
username = this.getArgs(message)[0] || username;

const uuid = await getUUID(username);
const response = (
await axios.get(
`https://api.hypixel.net/player?key=${config.minecraft.API.hypixelAPIkey}&uuid=${uuid}`
)
).data;
const response = await hypixel.getPlayer(username, { raw: true });

if (response.player === null) {
// eslint-disable-next-line no-throw-literal
throw "This player has never joined Hypixel.";
}

const woolWars = response?.player?.stats?.WoolGames?.wool_wars;
const woolWars = response?.player?.stats?.WoolGames?.wool_wars?.stats;

if (woolWars == undefined) {
// eslint-disable-next-line no-throw-literal
throw "This player has never played WoolWars.";
}

const level =
getWoolWarsStar(
response?.player?.stats?.WoolGames?.progression?.experience
) || 0;
const experience =
response.player?.stats?.WoolGames?.progression?.experience ?? 0;
const level = getWoolWarsStar(experience);

this.send(
`/gc [${toFixed(level, 0)}✫] ${username}: W: ${
woolWars.stats.wins
} | WLR: ${toFixed(
woolWars.stats.wins / woolWars.stats.games_played,
`/gc [${Math.floor(level)}✫] ${username}: W: ${woolWars.wins} | WLR: ${(
woolWars.wins / woolWars.games_played
).toFixed(2)} | KDR: ${(woolWars.kills / woolWars.deaths).toFixed(
2
)} | KDR: ${toFixed(
woolWars.stats.kills / woolWars.stats.deaths,
)} | BB: ${woolWars.blocks_broken} | WP: ${
woolWars.wool_placed
} | WPP: ${(woolWars.wool_placed / woolWars.games_played).toFixed(
2
)} | BB: ${woolWars.stats.blocks_broken} | WP: ${
woolWars.stats.wool_placed
}`
)} | WPG: ${(woolWars.wool_placed / woolWars.blocks_broken).toFixed(2)}
`
);
} catch (error) {
this.send(`/gc Error: ${error}`);
Expand Down

0 comments on commit adcf0ea

Please sign in to comment.