fix: adjust AFK retry delay handling and improve scheduling logic

This commit is contained in:
ZareMate 2026-04-01 18:54:09 +02:00
parent f3380220d8
commit 922ca38511

17
afk.js
View File

@ -31,7 +31,8 @@ const LOG_FILE = path.join(
`afk-${toSafeFilePart(runtimeUsername)}.log`, `afk-${toSafeFilePart(runtimeUsername)}.log`,
); );
const TELEPORT_DETECT_REGEX = /you teleported to\b/i; const TELEPORT_DETECT_REGEX = /you teleported to\b/i;
const AFK_RETRY_DELAY_MS = 7500; const AFK_INITIAL_CHECK_DELAY_MS = 5000;
const AFK_POST_COMMAND_CHECK_DELAY_MS = 7000;
const AFK_MIN_NUMBER = 1; const AFK_MIN_NUMBER = 1;
const AFK_MAX_NUMBER = 50; const AFK_MAX_NUMBER = 50;
@ -57,7 +58,7 @@ function clearAfkRetryTimer() {
} }
} }
function scheduleAfkRetryCheck() { function scheduleAfkRetryCheck(delayMs) {
clearAfkRetryTimer(); clearAfkRetryTimer();
afkRetryTimer = setTimeout(() => { afkRetryTimer = setTimeout(() => {
@ -65,14 +66,12 @@ function scheduleAfkRetryCheck() {
const randomNumber = getRandomIntInclusive(AFK_MIN_NUMBER, AFK_MAX_NUMBER); const randomNumber = getRandomIntInclusive(AFK_MIN_NUMBER, AFK_MAX_NUMBER);
const command = `/afk ${randomNumber}`; const command = `/afk ${randomNumber}`;
log( log(`No teleport detected after ${delayMs}ms; sending: ${command}`);
`No teleport detected after ${AFK_RETRY_DELAY_MS}ms; sending: ${command}`,
);
bot.chat(command); bot.chat(command);
// Keep checking every delay window until teleport is detected. // Teleport feedback can lag a few seconds after issuing /afk.
scheduleAfkRetryCheck(); scheduleAfkRetryCheck(AFK_POST_COMMAND_CHECK_DELAY_MS);
}, AFK_RETRY_DELAY_MS); }, delayMs);
} }
function toPlainText(value) { function toPlainText(value) {
@ -138,7 +137,7 @@ bot.on("spawn", () => {
log("Teleport already confirmed before spawn; skipping AFK retry schedule"); log("Teleport already confirmed before spawn; skipping AFK retry schedule");
return; return;
} }
scheduleAfkRetryCheck(); scheduleAfkRetryCheck(AFK_INITIAL_CHECK_DELAY_MS);
}); });
bot.on("error", (err) => { bot.on("error", (err) => {