From ea05777390e0db8390c724e34fc1a9d52ded4b89 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Fri, 11 Sep 2026 02:34:49 +0300 Subject: [PATCH] ... --- commands/forceleave.mjs | 3 ++- src/core/Bot.mjs | 6 ++--- src/core/BotVoiceMixin.mjs | 4 ++-- src/music/PlayerLifecycleMixin.mjs | 6 ++--- src/utils/Helpers247.mjs | 37 +++++++++++++++++++++++++++++ src/voice/gateway/RejoinManager.mjs | 8 +++++-- src/voice/gateway/Watchdog247.mjs | 12 +++++++--- 7 files changed, 62 insertions(+), 14 deletions(-) diff --git a/commands/forceleave.mjs b/commands/forceleave.mjs index 640ef91..a4334ca 100644 --- a/commands/forceleave.mjs +++ b/commands/forceleave.mjs @@ -5,6 +5,7 @@ import { CommandBuilder } from "../src/commands/index.mjs"; import { cleanId } from "../src/ui/index.mjs"; +import { resolveChannelCached } from "../src/utils/Helpers247.mjs"; /** * @type {CommandBuilder} @@ -33,7 +34,7 @@ export const command = new CommandBuilder() */ export async function run(msg, data) { const cid = cleanId(data.get("channelId").value); - const targetChannel = this.client.channels.get(cid); + const targetChannel = await resolveChannelCached(this.client, cid); if (!targetChannel) return msg.reply(this.t(msg, "responses.forceleave.channelNotFound")); if (cleanId(msg.message?.guildId) !== cleanId(targetChannel.guildId)) return msg.reply(this.t(msg, "responses.forceleave.wrongServer")); diff --git a/src/core/Bot.mjs b/src/core/Bot.mjs index 894f85d..f624277 100644 --- a/src/core/Bot.mjs +++ b/src/core/Bot.mjs @@ -142,9 +142,9 @@ class Remix { const client = new Client({ waitForGuilds: true, cache: { - guilds: 2_000, - channels: 5_000, - users: 10_000, + guilds: 10_000, + channels: 100_000, + users: 200_000, members: 5_000, messages: 20, }, diff --git a/src/core/BotVoiceMixin.mjs b/src/core/BotVoiceMixin.mjs index 85e613e..fc38eb4 100644 --- a/src/core/BotVoiceMixin.mjs +++ b/src/core/BotVoiceMixin.mjs @@ -13,7 +13,7 @@ import { EmbedBuilder } from "@fluxerjs/core"; import { getVoiceManager } from "@fluxerjs/voice"; import { getGlobalColor, PageBuilder } from "../ui/index.mjs"; import { cleanId } from "../utils/Utils.mjs"; -import { remove247ChannelMode, isPlayerConnectionDead, detachPlayerFromManager } from "../utils/Helpers247.mjs"; +import { remove247ChannelMode, isPlayerConnectionDead, detachPlayerFromManager, resolveChannelCached } from "../utils/Helpers247.mjs"; import { logger } from "./Logger.mjs"; import { Dashboard } from "../dashboard/Dashboard.mjs"; @@ -258,7 +258,7 @@ const BotVoiceMixin = { if (!this.lavalink) throw new Error("Audio node not ready yet — try again in a moment"); - const channel = this.client?.channels?.get?.(cleanChannelId); + const channel = await resolveChannelCached(this.client, cleanChannelId); if (!channel) throw new Error("Channel not found"); if (channel.type !== 2) throw new Error("Not a voice channel"); diff --git a/src/music/PlayerLifecycleMixin.mjs b/src/music/PlayerLifecycleMixin.mjs index e1a5e48..9d31436 100644 --- a/src/music/PlayerLifecycleMixin.mjs +++ b/src/music/PlayerLifecycleMixin.mjs @@ -14,7 +14,7 @@ import Player from "./player/index.mjs"; import { cleanId } from "../utils/Utils.mjs"; import { logger } from "../core/Logger.mjs"; -import { get247ChannelMode, isPlayerConnectionDead, detachPlayerFromManager } from "../utils/Helpers247.mjs"; +import { get247ChannelMode, isPlayerConnectionDead, detachPlayerFromManager, resolveChannelCached } from "../utils/Helpers247.mjs"; import { EmbedBuilder, PermissionFlags } from "@fluxerjs/core"; import { getVoiceManager } from "@fluxerjs/voice"; import { getGlobalColor, getMessageGuildId } from "../ui/index.mjs"; @@ -265,9 +265,9 @@ const PlayerLifecycleMixin = { } }, - /** Create a new Player, join the voice channel, and set up events. @async @this {import('./PlayerManager.mjs').PlayerManager} @param {object} message @param {string} cid @returns {Promise} The spawned player, or null on failure. */ + /** Create a new Player, join the voice channel, and set up events. The target channel is resolved cache-first with a REST fallback (the channels cache is FIFO-bounded, so a miss does not prove the channel is gone). @async @this {import('./PlayerManager.mjs').PlayerManager} @param {object} message @param {string} cid @returns {Promise} The spawned player, or null on failure. */ async initPlayer(message, cid) { - const channel = this.commands.client?.channels?.get(cid); + const channel = await resolveChannelCached(this.commands.client, cid); if (!channel) { message.reply( diff --git a/src/utils/Helpers247.mjs b/src/utils/Helpers247.mjs index d607fab..3ff498c 100644 --- a/src/utils/Helpers247.mjs +++ b/src/utils/Helpers247.mjs @@ -73,6 +73,43 @@ export function remove247ChannelMode(set, channelId, currentChannels) { export function set247ChannelMode(set, channelId, mode) { } +/** + * Resolve a channel by ID with a REST fallback. The client's channels cache + * is FIFO-bounded (OOM fix): on large fleets the bound can still be exceeded + * transiently, so a cache miss does NOT prove the channel is gone — the bot + * may simply have evicted it while caching traffic from other guilds. This + * helper tries the cache first and, on a miss, REST-fetches the channel + * (which also re-caches it for subsequent lookups). + * + * Used by PlayerManager.initPlayer (%join/%play), Remix._spawnPlayer (24/7 + * boot recovery + rejoin) and the forceleave command. The watchdog's + * _resolve247Channel() wraps the same idea but also distinguishes + * definitive 404s from transient network errors for pruning decisions. + * + * @param {object|null} client - Bot client (needs channels.get/channels.fetch). + * @param {string} channelId - The channel ID to resolve. + * @returns {Promise} The channel object, or null when it cannot + * be resolved from cache or REST. + */ +export async function resolveChannelCached(client, channelId) { + const clean = cleanId(channelId); + if (!clean) return null; + + const channels = client?.channels ?? null; + const cached = channels?.get?.(clean) ?? null; + if (cached) return cached; + + if (channels && typeof channels.fetch === "function") { + try { + return (await channels.fetch(clean)) ?? null; + } catch (_) { + return null; + } + } + + return null; +} + /** * Evict a player from every manager index (playerMap active + home keys, * guild index, pending scrobble timers) WITHOUT destroying it. Shared by the diff --git a/src/voice/gateway/RejoinManager.mjs b/src/voice/gateway/RejoinManager.mjs index 8749a3a..5190c0a 100644 --- a/src/voice/gateway/RejoinManager.mjs +++ b/src/voice/gateway/RejoinManager.mjs @@ -109,9 +109,13 @@ const RejoinManager = { return; } - const channel = remix.client?.channels?.get?.(cleanChannelId); + const { channel, definitive } = await this._resolve247Channel(cleanChannelId); if (!channel) { - logger.voice247(`[Rejoin] Channel ${cleanChannelId} no longer exists — skipping.`); + if (definitive) { + logger.voice247(`[Rejoin] Channel ${cleanChannelId} no longer exists — skipping.`); + } else { + logger.warn(`[Rejoin] Channel ${cleanChannelId} could not be resolved (network) — skipping this attempt; a later sweep will retry.`); + } this._rejoinAttempts.delete(cleanChannelId); return; } diff --git a/src/voice/gateway/Watchdog247.mjs b/src/voice/gateway/Watchdog247.mjs index 6a0bb10..cd660cd 100644 --- a/src/voice/gateway/Watchdog247.mjs +++ b/src/voice/gateway/Watchdog247.mjs @@ -76,7 +76,10 @@ const Watchdog247 = { * Resolve a channel by ID with a REST fallback. The channels cache is * FIFO-bounded (OOM fix), so a cache miss does NOT mean the channel was * deleted — only a REST fetch that definitively fails (404-style) proves - * deletion. Network errors keep the setting intact. + * deletion. Network errors keep the setting intact. Note the SDK's + * ChannelManager.fetch THROWS a FluxerError (code CHANNEL_NOT_FOUND) on a + * real 404 instead of returning null, so thrown errors are inspected: + * 404-style errors are definitive, everything else is treated as transient. * @this {GatewayHandler} * @param {string} channelId - The channel ID to resolve. * @returns {Promise<{channel: object|null, definitive: boolean}>} @@ -95,8 +98,11 @@ const Watchdog247 = { const fetched = await this.remix?.client?.channels?.fetch?.(clean); if (fetched) return { channel: fetched, definitive: false }; return { channel: null, definitive: true }; - } catch (_) { - return { channel: null, definitive: false }; + } catch (err) { + const gone = err?.code === "CHANNEL_NOT_FOUND" + || err?.statusCode === 404 || err?.status === 404 + || /\b404\b|not found|unknown channel/i.test(String(err?.message ?? "")); + return { channel: null, definitive: gone }; } },