Skip to content

Commit 2fed066

Browse files
committed
Rewrite Officer Commands
1 parent 7371273 commit 2fed066

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+165
-202
lines changed

src/contracts/minecraftCommand.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const config = require("../../config.json");
55
class minecraftCommand {
66
constructor(minecraft) {
77
this.minecraft = minecraft;
8+
this.officer = false;
89
}
910

1011
getArgs(message) {
@@ -15,7 +16,7 @@ class minecraftCommand {
1516
return args;
1617
}
1718

18-
send(message, officer = false, n = 1) {
19+
send(message, n = 1) {
1920
if (bot === undefined && bot._client.chat === undefined) {
2021
return;
2122
}
@@ -30,12 +31,12 @@ class minecraftCommand {
3031

3132
if (n >= 5) {
3233
return this.send(
33-
`/${officer ? "oc" : "gc"} Command failed to send message after 5 attempts. Please try again later.`,
34+
"Command failed to send message after 5 attempts. Please try again later.",
3435
);
3536
}
3637

3738
await delay(250);
38-
return this.send(`/${officer ? "oc" : "gc"} ${message}`);
39+
return this.send(`${message}`);
3940
} else if (
4041
msg.toString().includes("You cannot say the same message twice!") === true &&
4142
msg.toString().includes(":") === false
@@ -45,27 +46,27 @@ class minecraftCommand {
4546

4647
if (n >= 5) {
4748
return this.send(
48-
`/${officer ? "oc" : "gc"} Command failed to send message after 5 attempts. Please try again later.`,
49+
`Command failed to send message after 5 attempts. Please try again later.`,
4950
);
5051
}
5152

5253
await delay(250);
5354
return this.send(
54-
`/${officer ? "oc" : "gc"} ${message} - ${helperFunctions.generateID(config.minecraft.bot.messageRepeatBypassLength)}`,
55+
`${message} - ${helperFunctions.generateID(config.minecraft.bot.messageRepeatBypassLength)}`,
5556
n + 1,
5657
);
5758
}
5859
};
5960

6061
bot.once("message", listener);
61-
bot.chat(`/${officer ? "oc" : "gc"} ${message}`);
62+
bot.chat(`/${this.officer ? "oc" : "gc"} ${message}`);
6263

6364
setTimeout(() => {
6465
bot.removeListener("message", listener);
6566
}, 500);
6667
}
6768

68-
onCommand(player, message, officer) {
69+
onCommand(player, message) {
6970
throw new Error("Command onCommand method is not implemented yet!");
7071
}
7172
}

src/minecraft/CommandHandler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class CommandHandler {
3434
return;
3535
}
3636

37+
command.officer = officer;
3738
Logger.minecraftMessage(`${player} - [${command.name}] ${message}`);
38-
command.onCommand(player, message, officer);
39+
command.onCommand(player, message);
3940
} else if (message.startsWith("-") && message.startsWith("- ") === false) {
4041
if (config.minecraft.commands.soopy === false || message.at(1) === "-") {
4142
return;

src/minecraft/commands/8ballCommand.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class EightBallCommand extends minecraftCommand {
1717
];
1818
}
1919

20-
async onCommand(username, message, officer) {
20+
async onCommand(username, message) {
2121
try {
2222
if (this.getArgs(message).length === 0) {
2323
// eslint-disable-next-line no-throw-literal
@@ -26,9 +26,9 @@ class EightBallCommand extends minecraftCommand {
2626

2727
const { data } = await axios.get(`https://www.eightballapi.com/api`);
2828

29-
this.send(`${data.reading}`, officer);
29+
this.send(`${data.reading}`);
3030
} catch (error) {
31-
this.send(`[ERROR] ${error}`, officer);
31+
this.send(`[ERROR] ${error}`);
3232
}
3333
}
3434
}

src/minecraft/commands/UHCStatsCommmand.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@ class UHCStatsCommand extends minecraftCommand {
1717
];
1818
}
1919

20-
async onCommand(username, message, officer) {
20+
async onCommand(username, message) {
2121
try {
2222
username = this.getArgs(message)[0] || username;
2323

2424
const player = await hypixel.getPlayer(username);
2525

2626
const { starLevel, KDRatio, wins, headsEaten } = player.stats.uhc;
2727

28-
this.send(`[${starLevel}✫] ${player.nickname} | KDR: ${KDRatio} | W: ${wins} | Heads: ${headsEaten}`, officer);
28+
this.send(`[${starLevel}✫] ${player.nickname} | KDR: ${KDRatio} | W: ${wins} | Heads: ${headsEaten}`);
2929
} catch (error) {
3030
this.send(
3131
`${error
3232
.toString()
3333
.replace("[hypixel-api-reborn] ", "")
3434
.replace("For help join our Discord Server https://discord.gg/NSEBNMM", "")
3535
.replace("Error:", "[ERROR]")}`,
36-
officer,
3736
);
3837
}
3938
}

src/minecraft/commands/accessoriesCommand.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AccessoriesCommand extends minecraftCommand {
1919
];
2020
}
2121

22-
async onCommand(username, message, officer) {
22+
async onCommand(username, message) {
2323
try {
2424
username = this.getArgs(message)[0] || username;
2525

@@ -50,10 +50,9 @@ class AccessoriesCommand extends minecraftCommand {
5050
`${username}'s Accessories: ${talismans?.total ?? 0} (${rarities}), Recombed: ${
5151
talismans?.recombed ?? 0
5252
}, Enriched: ${talismans?.enriched ?? 0} | Reforge: ${talismans.power} | Magic Power: ${talismans.magicPower}`,
53-
officer,
5453
);
5554
} catch (error) {
56-
this.send(`[ERROR] ${error}`, officer);
55+
this.send(`[ERROR] ${error}`);
5756
}
5857
}
5958
}

src/minecraft/commands/auctionHouseCommand.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AuctionHouseCommand extends minecraftCommand {
2323
];
2424
}
2525

26-
async onCommand(username, message, officer) {
26+
async onCommand(username, message) {
2727
try {
2828
username = this.getArgs(message)[0] || username;
2929

@@ -41,7 +41,7 @@ class AuctionHouseCommand extends minecraftCommand {
4141
const player = playerResponse.data?.player || {};
4242

4343
if (auctions.length === 0) {
44-
return this.send("This player has no active auctions.", officer);
44+
return this.send("This player has no active auctions.");
4545
}
4646

4747
const activeAuctions = auctions.filter((auction) => auction.end >= Date.now());
@@ -91,10 +91,10 @@ class AuctionHouseCommand extends minecraftCommand {
9191
}
9292

9393
imgurUrl = string;
94-
this.send(`/gc $${username}'s Active Auctions: Check Discord Bridge for image.`, officer);
94+
this.send(`/gc $${username}'s Active Auctions: Check Discord Bridge for image.`);
9595
} catch (error) {
9696
console.log(error);
97-
this.send(`[ERROR] ${error}`, officer);
97+
this.send(`[ERROR] ${error}`);
9898
}
9999
}
100100
}

src/minecraft/commands/bedwarsStatsCommand.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BedwarsCommand extends minecraftCommand {
1818
];
1919
}
2020

21-
async onCommand(username, message, officer) {
21+
async onCommand(username, message) {
2222
try {
2323
const msg = this.getArgs(message).map((arg) => arg.replaceAll("/", ""));
2424
const modes = ["solo", "doubles", "threes", "fours", "4v4"];
@@ -36,7 +36,6 @@ class BedwarsCommand extends minecraftCommand {
3636
`[${level}✫] ${player.nickname} FK: ${formatNumber(finalKills)} FKDR: ${finalKDRatio} W: ${formatNumber(
3737
wins,
3838
)} WLR: ${WLRatio} BB: ${formatNumber(broken)} BLR: ${BLRatio} WS: ${winstreak}`,
39-
officer,
4039
);
4140
} else if (mode !== undefined) {
4241
const { level } = player.stats.bedwars;
@@ -49,10 +48,9 @@ class BedwarsCommand extends minecraftCommand {
4948
)} FKDR: ${finalKDRatio} Wins: ${formatNumber(wins)} WLR: ${WLRatio} BB: ${formatNumber(
5049
broken,
5150
)} BLR: ${BLRatio} WS: ${winstreak}`,
52-
officer,
5351
);
5452
} else {
55-
this.send("Invalid mode. Valid modes: overall, solo, doubles, threes, fours, 4v4", officer);
53+
this.send("Invalid mode. Valid modes: overall, solo, doubles, threes, fours, 4v4");
5654
}
5755
} catch (error) {
5856
this.send(
@@ -61,7 +59,6 @@ class BedwarsCommand extends minecraftCommand {
6159
.replace("[hypixel-api-reborn] ", "")
6260
.replace("For help join our Discord Server https://discord.gg/NSEBNMM", "")
6361
.replace("Error:", "[ERROR]")}`,
64-
officer,
6562
);
6663
}
6764
}

src/minecraft/commands/bestiaryCommand.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BestiaryCommand extends minecraftCommand {
1919
];
2020
}
2121

22-
async onCommand(username, message, officer) {
22+
async onCommand(username, message) {
2323
try {
2424
const args = this.getArgs(message);
2525

@@ -33,7 +33,7 @@ class BestiaryCommand extends minecraftCommand {
3333

3434
const bestiary = getBestiary(data.profile);
3535
if (bestiary === null) {
36-
return this.send("This player has not yet joined SkyBlock since the bestiary update.", officer);
36+
return this.send("This player has not yet joined SkyBlock since the bestiary update.");
3737
}
3838

3939
if (mob) {
@@ -44,7 +44,6 @@ class BestiaryCommand extends minecraftCommand {
4444
`${username}'s ${mobData.name} Bestiary: ${mobData.kills} / ${mobData.nextTierKills} (${
4545
mobData.nextTierKills - mobData.kills
4646
})`,
47-
officer,
4847
);
4948

5049
await new Promise((resolve) => setTimeout(resolve, 1000));
@@ -53,7 +52,6 @@ class BestiaryCommand extends minecraftCommand {
5352

5453
this.send(
5554
`${username}'s Bestiary Milestone: ${bestiary.milestone} / ${bestiary.maxMilestone} | Unlocked Tiers: ${bestiary.tiersUnlocked} / ${bestiary.totalTiers}`,
56-
officer,
5755
);
5856

5957
if (playerUsername === username) {
@@ -68,11 +66,11 @@ class BestiaryCommand extends minecraftCommand {
6866

6967
await new Promise((resolve) => setTimeout(resolve, 1000));
7068

71-
this.send(`Closest to level up: ${topFiveMobs.join(", ")}`, officer);
69+
this.send(`Closest to level up: ${topFiveMobs.join(", ")}`);
7270
}
7371
} catch (error) {
7472
console.log(error);
75-
this.send(`[ERROR] ${error}`, officer);
73+
this.send(`[ERROR] ${error}`);
7674
}
7775
}
7876

src/minecraft/commands/boopCommand.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BoopCommand extends minecraftCommand {
1919
this.isOnCooldown = false;
2020
}
2121

22-
async onCommand(username, message, officer) {
22+
async onCommand(username, message) {
2323
// CREDITS: by @Zickles (https://github.com/Zickles)
2424
try {
2525
if (this.getArgs(message).length === 0) {
@@ -28,14 +28,14 @@ class BoopCommand extends minecraftCommand {
2828
}
2929

3030
if (this.isOnCooldown) {
31-
return this.send(`${this.name} Command is on cooldown`, officer);
31+
return this.send(`${this.name} Command is on cooldown`);
3232
}
3333

3434
bot.chat(`/boop ${this.getArgs(message)[0]}`);
3535
await delay(690);
3636
bot.chat(`/msg ${this.getArgs(message)[0]} ${username} Booped You!`);
3737
await delay(690);
38-
this.send(`Booped ${this.getArgs(message)[0]}!`, officer);
38+
this.send(`Booped ${this.getArgs(message)[0]}!`);
3939
this.isOnCooldown = true;
4040
// CREDITS: @jaxieflaxie for finding this cooldown reset
4141
setTimeout(() => {
@@ -51,7 +51,7 @@ class BoopCommand extends minecraftCommand {
5151
}, 30000);
5252
this.isOnCooldown = false;
5353
} catch (error) {
54-
this.send(`[ERROR] ${error}`, officer);
54+
this.send(`[ERROR] ${error}`);
5555
}
5656
}
5757
}

src/minecraft/commands/calculateCommand.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ class CalculateCommand extends minecraftCommand {
1717
];
1818
}
1919

20-
onCommand(username, message, officer) {
20+
onCommand(username, message) {
2121
try {
2222
const calculation = message.replace(/[^-()\d/*+.]/g, "");
2323
const answer = eval(calculation);
2424

2525
if (answer === Infinity) {
26-
return this.send("Something went wrong.. Somehow you broke it (the answer was infinity)", officer);
26+
return this.send("Something went wrong.. Somehow you broke it (the answer was infinity)");
2727
}
2828

29-
this.send(`${calculation} = ${formatNumber(answer)} (${answer.toLocaleString()})`, officer);
29+
this.send(`${calculation} = ${formatNumber(answer)} (${answer.toLocaleString()})`);
3030
} catch (error) {
31-
this.send(`[ERROR] ${error}`, officer);
31+
this.send(`[ERROR] ${error}`);
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)