mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
...
This commit is contained in:
1 parent
00df253588
commit
ea05777390
7 files changed
+62
-14
No files matched your search
@@ -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"));
|
||||
|
||||
+3
-3
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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<Player|null>} 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<Player|null>} 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(
|
||||
|
||||
@@ -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<object|null>} 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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user