mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
fix(voice): prevent 24/7 rejoin spam when bot is not in guild or voice times out
- Check guild membership before BootRecovery and Watchdog sweeps; keep settings intact if bot is not in server - Wire up RejoinBackoff to apply exponential cooldown when voice joins time out - Stop redundant retry loops and deduplicate join failure logs
This commit is contained in:
1 parent
355f6b1129
commit
f2bfff59b5
5 files changed
+61
-8
No files matched your search
@@ -188,6 +188,18 @@ const BotVoiceMixin = {
|
||||
return;
|
||||
}
|
||||
|
||||
const guild = this.client?.guilds?.get?.(cleanG);
|
||||
if (!guild) {
|
||||
logger.voice247(`[247] Bot is not currently in guild ${cleanG} — skipping rejoin for ${cleanCh} (setting kept intact)`);
|
||||
return;
|
||||
}
|
||||
|
||||
const backoffRemaining = this.gatewayHandler?.rejoinBackoff?.remainingMs?.(cleanCh) ?? 0;
|
||||
if (backoffRemaining > 0 && delayMs === null) {
|
||||
logger.voice247(`[247] Channel ${cleanCh} in backoff cooldown (${Math.round(backoffRemaining / 1000)}s left) — skipping immediate rejoin`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._247RejoinTimers) this._247RejoinTimers = new Map();
|
||||
if (this._247RejoinTimers.has(cleanCh)) return;
|
||||
|
||||
@@ -407,8 +419,7 @@ const BotVoiceMixin = {
|
||||
this.players._pendingJoins.delete(cleanChannelId);
|
||||
}
|
||||
this.players.playerMap.delete(cleanChannelId);
|
||||
try { player.destroy(); } catch(e) { logger.warn("[_spawnPlayer] Cleanup destroy error:", e?.message); }
|
||||
logger.warn(`[_spawnPlayer] Failed to spawn player for channel ${cleanChannelId}:`, err.message);
|
||||
try { player.destroy(); } catch(e) {}
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -608,7 +608,7 @@ class Player extends EventEmitter {
|
||||
|
||||
} catch (e) {
|
||||
const causeStr = e.cause ? ` (Cause: ${e.cause})` : "";
|
||||
logger.error("[Player] Join failed:", e.message, causeStr);
|
||||
logger.warn("[Player] Join failed:", e.message, causeStr);
|
||||
|
||||
if (this._voiceConn) {
|
||||
try { await this._voiceConn.disconnect(); } catch(err) { logger.warn("[Player] voiceConn disconnect on join failure:", err?.message); }
|
||||
|
||||
@@ -19,6 +19,7 @@ import VoiceStateRouting from "./VoiceStateRouting.mjs";
|
||||
import GuildSync from "./GuildSync.mjs";
|
||||
import RejoinManager from "./RejoinManager.mjs";
|
||||
import Watchdog247 from "./Watchdog247.mjs";
|
||||
import RejoinBackoff from "./RejoinBackoff.mjs";
|
||||
|
||||
const RAW_GATEWAY_INTEREST =
|
||||
/"(?:t|op)":\s*(?:"(?:VOICE_STATE_UPDATE|VOICE_SERVER_UPDATE|GUILD_CREATE|READY|RESUMED)"|(?:7|9|10|12)\b)/;
|
||||
@@ -41,6 +42,8 @@ class GatewayHandler {
|
||||
this.presenceContents = remix.config.presenceContents ?? [];
|
||||
this.presenceInterval = remix.config.presenceInterval ?? 30_000;
|
||||
|
||||
this.rejoinBackoff = new RejoinBackoff();
|
||||
|
||||
this.wsListenerAttached = false;
|
||||
this.presenceTimer = null;
|
||||
this.presenceIndex = 0;
|
||||
@@ -521,6 +524,16 @@ class GatewayHandler {
|
||||
|
||||
for (let i = 0; i < channelsToRejoin.length; i++) {
|
||||
const { guildId, channelId, mode } = channelsToRejoin[i];
|
||||
const cleanG = cleanId(guildId);
|
||||
const cleanC = cleanId(channelId);
|
||||
|
||||
const guild = remix.client?.guilds?.get?.(cleanG);
|
||||
if (!guild) {
|
||||
logger.voice247(
|
||||
`[BootRecovery] Bot is not currently in guild ${cleanG} — skipping channel ${cleanC} (setting kept intact).`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
let staggerDelay = baseStagger;
|
||||
@@ -581,13 +594,15 @@ class GatewayHandler {
|
||||
const player = await this._attemptRejoin(channelId, guildId, 3, 5_000, "BootRecovery");
|
||||
|
||||
if (player) {
|
||||
this.rejoinBackoff?.recordSuccess?.(channelId);
|
||||
logger.voice247(
|
||||
`[BootRecovery] Successfully rejoined channel ${channelId} (mode: ${mode}) [${i + 1}/${channelsToRejoin.length}]`
|
||||
);
|
||||
} else {
|
||||
this.rejoinBackoff?.recordFailure?.(channelId);
|
||||
logger.warn(
|
||||
`[BootRecovery] Failed to rejoin channel ${channelId} in guild ${guildId} after retries — ` +
|
||||
`keeping 24/7 setting intact, will retry on next disconnect/restart.`
|
||||
`[BootRecovery] Could not rejoin channel ${channelId} in guild ${guildId} — ` +
|
||||
`keeping 24/7 setting intact (backed off).`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,7 @@ const RejoinManager = {
|
||||
}
|
||||
|
||||
logger.warn(
|
||||
`[${context}] Failed to rejoin channel ${channelId} (attempt ${attempt}/${maxRetries}): ${errMsg}` +
|
||||
(attempt > 1 ? ` (after ${attempt} attempts)` : '')
|
||||
`[${context}] Failed to rejoin channel ${channelId}: ${errMsg} — keeping 24/7 setting intact.`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
@@ -79,6 +78,17 @@ const RejoinManager = {
|
||||
const cleanGuildId = cleanId(guildId);
|
||||
const cleanChannelId = cleanId(channelId);
|
||||
|
||||
const guild = remix.client?.guilds?.get?.(cleanGuildId);
|
||||
if (!guild) {
|
||||
logger.voice247(`[Rejoin] Bot is not currently in guild ${cleanGuildId} — skipping ${cleanChannelId} (setting kept intact).`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.rejoinBackoff?.remainingMs?.(cleanChannelId) > 0) {
|
||||
logger.voice247(`[Rejoin] Channel ${cleanChannelId} in backoff cooldown — skipping.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._rejoinInProgress.has(cleanChannelId)) {
|
||||
logger.voice247(`[Rejoin] Channel ${cleanChannelId} rejoin already in progress — skipping.`);
|
||||
return;
|
||||
@@ -131,6 +141,7 @@ const RejoinManager = {
|
||||
const player = await this._attemptRejoin(cleanChannelId, cleanGuildId, maxRetries, 5_000, "Rejoin");
|
||||
if (player) {
|
||||
this._rejoinAttempts.delete(cleanChannelId);
|
||||
this.rejoinBackoff?.recordSuccess?.(cleanChannelId);
|
||||
try {
|
||||
await remix.restorePlayerStateForChannel?.(cleanGuildId, cleanChannelId, player);
|
||||
} catch (err) {
|
||||
@@ -138,6 +149,7 @@ const RejoinManager = {
|
||||
}
|
||||
} else {
|
||||
this._rejoinAttempts.delete(cleanChannelId);
|
||||
this.rejoinBackoff?.recordFailure?.(cleanChannelId);
|
||||
}
|
||||
return player;
|
||||
} finally {
|
||||
|
||||
@@ -167,7 +167,22 @@ const Watchdog247 = {
|
||||
}
|
||||
|
||||
for (const { guildId, channelId } of savedChannels) {
|
||||
if (remix.intentionalLeaves?.has?.(channelId)) {
|
||||
const cleanG = cleanId(guildId);
|
||||
const cleanCh = cleanId(channelId);
|
||||
|
||||
const guild = remix.client?.guilds?.get?.(cleanG);
|
||||
if (!guild) {
|
||||
// Bot is not in this guild — keep 24/7 setting intact for future invite, but skip sweep
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.rejoinBackoff?.remainingMs?.(cleanCh) > 0) {
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (remix.intentionalLeaves?.has?.(cleanCh)) {
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user