Skip to content

Commit 4f5d781

Browse files
committed
fix: slayer
1 parent f996f95 commit 4f5d781

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/contracts/minecraftCommand.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,26 @@ class minecraftCommand {
2424
/**
2525
* Sends a message in the Minecraft chat.
2626
* @param {string} message
27-
* @returns
27+
* @param {number} maxRetries - Maximum number of retries (default: 5)
2828
*/
29-
async send(message) {
29+
async send(message, maxRetries = 5) {
3030
if (!bot?._client?.chat) {
3131
return;
3232
}
3333

34+
const startTime = Date.now();
35+
const maxExecutionTime = 10000;
36+
3437
if (message.length > 256) {
3538
const messages = splitMessage(message, 256);
3639
for (const msg of messages) {
3740
await delay(1000);
38-
await this.send(msg);
41+
await this.send(msg, maxRetries);
42+
43+
if (Date.now() - startTime > maxExecutionTime) {
44+
console.error("Message sending timed out after 10 seconds");
45+
return;
46+
}
3947
}
4048
return;
4149
}
@@ -70,15 +78,20 @@ class minecraftCommand {
7078
);
7179
};
7280

73-
for (let i = 0; i < 5; i++) {
81+
for (let i = 0; i < maxRetries; i++) {
7482
try {
7583
await sendMessage();
7684
return;
7785
} catch (error) {
86+
if (Date.now() - startTime > maxExecutionTime) {
87+
console.error("Message sending timed out after 30 seconds");
88+
return;
89+
}
90+
7891
// @ts-ignore
7992
if (error.message === "rate-limited") {
80-
if (i === 4) {
81-
this.send("Command failed to send message after 5 attempts. Please try again later.");
93+
if (i === maxRetries - 1) {
94+
this.send(`Command failed to send message after ${maxRetries} attempts. Please try again later.`);
8295
return;
8396
}
8497
await delay(2000);

src/minecraft/commands/slayersCommand.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SlayersCommand extends minecraftCommand {
3232
async onCommand(player, message) {
3333
try {
3434
const args = this.getArgs(message);
35-
const slayer = ["zombie", "rev", "spider", "tara", "wolf", "sven", "eman", "enderman", "blaze", "demonlord", "vamp", "vampire"];
35+
const slayer = ["zombie", "spider", "wolf", "enderman", "blaze", "vampire"];
3636

3737
const slayerType = slayer.includes(args[1]) ? args[1] : null;
3838
player = args[0] || player;
@@ -47,13 +47,14 @@ class SlayersCommand extends minecraftCommand {
4747
if (slayerType) {
4848
this.send(`${username}'s ${titleCase(slayerType)} - ${slayerData[slayerType].level} Levels | Experience: ${formatNumber(slayerData[slayerType].xp)}`);
4949
} else {
50-
const slayer = Object.keys(profile).reduce(
50+
const slayer = Object.keys(slayerData).reduce(
5151
(acc, slayer) => `${acc} | ${titleCase(slayer)}: ${slayerData[slayer].level} (${formatNumber(slayerData[slayer].xp)})`,
5252
""
5353
);
5454
this.send(`${username}'s Slayer: ${slayer.slice(3)}`);
5555
}
5656
} catch (error) {
57+
console.log(error);
5758
this.send(`[ERROR] ${error}`);
5859
}
5960
}

0 commit comments

Comments
 (0)