From 67db7e73a856db408e75aa7bc70e344081cd80c5 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Sat, 9 May 2026 16:12:15 +0300 Subject: [PATCH] reworking --- commands/settings.mjs | 16 ++++++++++++++++ src/GatewayHandler.mjs | 11 ++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/commands/settings.mjs b/commands/settings.mjs index 4e5c7f8..9c1f3bc 100644 --- a/commands/settings.mjs +++ b/commands/settings.mjs @@ -524,15 +524,31 @@ async function handle247(ctx, message, value) { save247Channels(set, channels); + // Check if the bot already has a player in this guild. + // Fluxer only supports one voice connection per guild — spawning a new player + // would disconnect the existing one. If the bot is already in a different + // channel in this guild, just save the 24/7 setting without spawning. const playerExists = ctx.players.playerMap.has(id) || [...ctx.players.playerMap.values()].some(p => cleanId(p?._channelId ?? "") === id && cleanId(p?._guildId ?? "") === cleanId(guildId) ); + const guildHasPlayer = [...ctx.players.playerMap.values()].some(p => + cleanId(p?._guildId ?? "") === cleanId(guildId) && !p._destroyed + ); + if (playerExists) { return message.reply(build247EnabledPanel(set, id, resolved, false, ctx, guildId)); } + // If the bot is already in a different channel in this guild, save the + // channel for 24/7 but don't try to spawn a new player (which would + // disconnect the existing one). The bot will auto-rejoin when it + // eventually disconnects from the current channel. + if (guildHasPlayer) { + return message.reply(build247EnabledPanel(set, id, resolved, false, ctx, guildId)); + } + try { await ctx._spawnPlayer(guildId, id); return message.reply(build247EnabledPanel(set, id, resolved, true, ctx, guildId)); diff --git a/src/GatewayHandler.mjs b/src/GatewayHandler.mjs index 6c07c3f..fae1fb5 100644 --- a/src/GatewayHandler.mjs +++ b/src/GatewayHandler.mjs @@ -796,19 +796,20 @@ export class GatewayHandler { ? new Set(raw.map(id => String(id).replace(/\D/g, "")).filter(id => id.length >= 15)) : new Set(); if (channels.has(cleanOld) && cleanOld !== cleanId && cleanId.length >= 15) { - channels.delete(cleanOld); + // Keep the old channel saved AND add the new one. + // The bot moved from one 24/7 channel to another — both should + // remain in the saved list so the bot can auto-rejoin either one. channels.add(cleanId); set.set("stay_247", [...channels]); - // Also migrate the per-channel mode from old → new channel + // Copy the per-channel mode from old → new channel (keep old too) const modes = set.get("stay_247_modes"); if (modes && typeof modes === "object" && !Array.isArray(modes) && modes[cleanOld]) { - modes[cleanId] = modes[cleanOld]; - delete modes[cleanOld]; + if (!modes[cleanId]) modes[cleanId] = modes[cleanOld]; set.set("stay_247_modes", modes); } - logger.voice247(`[247] Updated stay_247: ${cleanOld} → ${cleanId}`); + logger.voice247(`[247] Added to stay_247: ${cleanId} (kept ${cleanOld})`); } } } catch (e) {