From dbe1c46dc50c72ee4c103f68a2f366351aae15f6 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Wed, 17 Jun 2026 03:26:46 +0300 Subject: [PATCH] hotfix /testing --- index.mjs | 2 +- src/LastFmManager.mjs | 8 +----- src/MessageHandler.mjs | 9 +++++-- src/Player.mjs | 7 ++++-- src/constants/FluxerRevoice.mjs | 43 ++++++++++++++++++++++++++++++--- 5 files changed, 53 insertions(+), 16 deletions(-) diff --git a/index.mjs b/index.mjs index 3888a9e..b561f54 100644 --- a/index.mjs +++ b/index.mjs @@ -188,7 +188,7 @@ export class Remix { commands.owners = config.owners ?? []; this.moonlink = null; - const moonlinkInitialised = false; + let moonlinkInitialised = false; this.voiceCache = new VoiceStateCache({ maxUsers: 50_000, maxBots: 10_000 }); diff --git a/src/LastFmManager.mjs b/src/LastFmManager.mjs index e4052d9..281416b 100644 --- a/src/LastFmManager.mjs +++ b/src/LastFmManager.mjs @@ -231,12 +231,6 @@ export class LastFmManager { ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; `); - try { - await pool.execute("ALTER TABLE \`lastfm_users\` ADD COLUMN \`scrobble_count\` BIGINT NOT NULL DEFAULT 0 AFTER \`scrobble\`"); - } catch (e) { - logger.warn("[LastFm] Migration warning:", e?.message); - } - await pool.execute(` CREATE TABLE IF NOT EXISTS \`lastfm_stats\` ( \`id\` TINYINT(1) NOT NULL PRIMARY KEY DEFAULT 1, @@ -298,7 +292,7 @@ export class LastFmManager { [...f.params, String(userId), ...f.params] ); } catch (e) { - logger.warn("[LastFm] Migration warning:", e?.message); + logger.warn("[LastFm] Stats update warning:", e?.message); } return data; diff --git a/src/MessageHandler.mjs b/src/MessageHandler.mjs index e817667..8691cc0 100644 --- a/src/MessageHandler.mjs +++ b/src/MessageHandler.mjs @@ -572,14 +572,19 @@ export class MessageHandler { } /** + * Join a voice channel using the documented VoiceManager.join() API. + * Reference: https://fluxer.js.org/v/latest/guides/voice + * * @param {string} channelId * @returns {Promise} */ async joinChannel(channelId) { - const { joinVoiceChannel } = await import("@fluxerjs/voice"); + const { getVoiceManager } = await import("@fluxerjs/voice"); const channel = await this.client.channels.fetch(channelId); if (!channel || !("guildId" in channel)) throw new Error("Cannot join a non-guild voice channel."); - return joinVoiceChannel(this.client, channel); + const vm = getVoiceManager(this.client); + if (!vm) throw new Error("VoiceManager not available."); + return vm.join(channel); } } diff --git a/src/Player.mjs b/src/Player.mjs index 46df061..f306dce 100644 --- a/src/Player.mjs +++ b/src/Player.mjs @@ -17,11 +17,14 @@ * that occurs when a Fluxer bot token is sent to an incompatible API. */ -import { MediaPlayer } from "revoice.js"; +import { createRequire } from "node:module"; + +const require = createRequire(import.meta.url); +const { MediaPlayer } = require("revoice.js"); import { ConnectionState, LKRoomEvent } from "./constants/FluxerRevoice.mjs"; import { getVoiceManager } from "@fluxerjs/voice"; -import { Utils } from "./Utils.mjs"; +import { Utils, cleanId } from "./Utils.mjs"; import { EventEmitter } from "node:events"; import meta from "./probe.mjs"; import { Worker } from "node:worker_threads"; diff --git a/src/constants/FluxerRevoice.mjs b/src/constants/FluxerRevoice.mjs index 28f868c..0bd8c36 100644 --- a/src/constants/FluxerRevoice.mjs +++ b/src/constants/FluxerRevoice.mjs @@ -20,10 +20,12 @@ * 3. Gateway sends VOICE_SERVER_UPDATE with { endpoint, token } * 4. The endpoint/token are LiveKit credentials * - * This adapter wraps @fluxerjs/voice's `joinVoiceChannel()` and returns + * This adapter wraps @fluxerjs/voice's VoiceManager.join() and returns * a `FluxerVoiceConnection` that is API-compatible with revoice.js's * `VoiceConnection`, so Player.mjs and MediaPlayer work unchanged. * + * Reference: https://fluxer.js.org/v/latest/guides/voice + * * IMPORTANT: @livekit/rtc-node (Node.js SDK) does NOT have `room.state`. * ✅ room.isConnected — boolean getter (true when connected) * ✅ room.connectionState — ConnectionState enum getter @@ -32,7 +34,7 @@ */ import { EventEmitter } from "node:events"; -import { joinVoiceChannel, getVoiceManager } from "@fluxerjs/voice"; +import { getVoiceManager } from "@fluxerjs/voice"; export const ConnectionState = Object.freeze({ CONN_DISCONNECTED: 0, @@ -288,7 +290,7 @@ export class FluxerRevoice extends EventEmitter { * Send a channel-specific leave signal to the Fluxer gateway so it * knows the bot is no longer in the given channel. Without this, the * gateway may think the bot is still connected and won't send a fresh - * VOICE_SERVER_UPDATE on the next joinVoiceChannel() call, causing the + * VOICE_SERVER_UPDATE on the next VoiceManager.join() call, causing the * rejoin to hang or fail. * * IMPORTANT: Only uses channel-specific leave (vm.leaveChannel). @@ -445,9 +447,14 @@ export class FluxerRevoice extends EventEmitter { const channelGuildId = guildId ?? channel?.guildId ?? channel?.guild?.id ?? null; + const vm = getVoiceManager(this.client); + if (!vm) { + throw new Error(`Fluxer voice join failed for ${channelId}: VoiceManager not available — call getVoiceManager(client) before login`); + } + let nativeConnection; try { - nativeConnection = await joinVoiceChannel(this.client, channel); + nativeConnection = await vm.join(channel); } catch (e) { throw new Error(`Fluxer voice join failed for ${channelId}: ${e.message}`); } @@ -551,6 +558,7 @@ export class FluxerRevoice extends EventEmitter { }); room.on(LKRoomEvent.Disconnected, (reason) => { + if (conn._destroyed) return; const isIntentional = this._intentionalDisconnects.has(String(channelId)); const reasonLabel = isIntentional ? "intentional" : (reason ?? "unexpected"); logger.player(`[FluxerRevoice] Room disconnected: ${reasonLabel}`); @@ -594,6 +602,33 @@ export class FluxerRevoice extends EventEmitter { } }); + /** + * Handle the VoiceManager's serverLeave event, which fires when + * the Fluxer/LiveKit server terminates the session server-side. + * Without this handler the bot never learns the session is dead, + * leading to "validate request timed out" on the next join attempt. + * + * Reference: https://fluxer.js.org/v/latest/guides/voice + * "If using LiveKit, the server may emit serverLeave. + * Listen and reconnect if needed." + */ + if (nativeConnection && typeof nativeConnection.on === "function") { + nativeConnection.on("serverLeave", () => { + if (conn._destroyed) return; + logger.player(`[FluxerRevoice] serverLeave received for channel ${channelId} — cleaning up`); + conn._connected = false; + conn._destroyed = true; + this.connections.delete(channelId); + this._leaveGateway(channelId, channelGuildId); + if (room) { + try { room.disconnect().catch(() => {}); } catch (_) { /** already gone */ } + } + if (conn.listenerCount("disconnect") > 0) { + conn.emit("disconnect"); + } + }); + } + this.connections.set(channelId, conn); if (_leaveIfEmpty) {