mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
feat: audio filters, rate limiting, stability fixes & new announcement channel
feat(filter): add %filter command with Bass Boost, Nightcore, Vaporwave,
8D, Karaoke, Tremolo and more; filter status now shown in %player UI
feat(player): add Filter button (🎛️) to player controls; display active
filter name/emoji in queue status line
feat(commands): add per-user command cooldown (1.5s) in CommandHandler;
owners are exempt so %reload/%eval are never blocked
feat(settings): debounce rapid set() calls into a single remoteSave()
80ms after the last write; prevents N parallel DB queries per command
feat(storage): add announcementChannelId field to defaults.json
fix(play): wrap statusMsg send in try/catch; fall back to fresh reply
if the initial status message fails to send
fix(stats): normalise guild.members.fetch() result (Collection, array,
or plain object) to avoid infinite pagination loop; use memberCount
as primary member count
fix(search): normalise reaction event user ID across Fluxer event shapes
(user_id / userId / user.id) so author filter works reliably
fix(forceleave): await this.players.leave() — was missing await, could
silently swallow errors
fix(MessageHandler): guard register() against double-call on hot-reload;
second call now returns early to prevent duplicate listeners
fix(MoonlinkManager): add getLiveSessionId() helper that walks active
nodes to find a valid session before falling back to cached value
fix(reload): use pathToFileURL() for cache-busting import URL so Windows
drive letters and spaces in paths are handled correctly
fix(eval): broaden sensitive-key list (mysql, nodelink, _nl, credential,
apikey, webhook); increase scan depth to 6; handle circular refs in
hasSensitive(); normalise keys to lowercase for matching
fix(worker): compile sanitize regexes once at module load instead of
on every sanitizeError() call
fix(Player): cache compiled sanitize regexes keyed by host:port:password
to avoid rebuilding identical RegExp objects on every error path
fix(index): wrap config.json read in try/catch with clear FATAL messages
for missing file or malformed JSON; validate required keys at startup
config: add rest.timeout/retries and nodelink requestTimeout to
config_example.json with explanatory comments
This commit is contained in:
1 parent
c339e32e9c
commit
57f018c815
17 files changed
+468
-232
No files matched your search
+17
-47
@@ -2,7 +2,6 @@
|
||||
* MoonlinkManager.mjs
|
||||
*
|
||||
* Wraps moonlink.js Manager with a custom connector for Fluxer.
|
||||
* FIXED: Correct payload format for packetUpdate
|
||||
*/
|
||||
|
||||
import { Manager } from "moonlink.js";
|
||||
@@ -28,7 +27,7 @@ export class MoonlinkManager extends EventEmitter {
|
||||
*/
|
||||
constructor(nodeCfg, client) {
|
||||
super();
|
||||
this.setMaxListeners(50); // reconnects temporarily stack listeners during re-init
|
||||
this.setMaxListeners(50);
|
||||
this._nodeCfg = nodeCfg;
|
||||
this._client = client;
|
||||
|
||||
@@ -59,10 +58,8 @@ export class MoonlinkManager extends EventEmitter {
|
||||
},
|
||||
});
|
||||
|
||||
// Set up voice state forwarding from Fluxer to moonlink
|
||||
this._setupVoiceForwarding(client);
|
||||
|
||||
// Forward key events
|
||||
this.manager.on("nodeReady", (node) => {
|
||||
this.sessionId = node.sessionId ?? null;
|
||||
logger.moonlink(`[Moonlink] Node ready: ${node.identifier} | session: ${this.sessionId}`);
|
||||
@@ -98,6 +95,21 @@ export class MoonlinkManager extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current live session ID from the connected node.
|
||||
* Walks active nodes to find a valid session, fallback to cached.
|
||||
* @returns {string|null}
|
||||
*/
|
||||
getLiveSessionId() {
|
||||
try {
|
||||
for (const node of this.manager.nodes?.nodes?.values?.() ?? []) {
|
||||
if (node.sessionId) return node.sessionId;
|
||||
if (node.ws?.sessionId) return node.ws.sessionId;
|
||||
}
|
||||
} catch (_) {}
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send voice payload to Fluxer's WebSocket
|
||||
* @param {string} guildId
|
||||
@@ -106,14 +118,11 @@ export class MoonlinkManager extends EventEmitter {
|
||||
*/
|
||||
_sendPayload(guildId, payload) {
|
||||
try {
|
||||
// Prefer the public ws.send(shardId, payload) API — shards is a private field
|
||||
// in @fluxerjs/ws and accessing it directly risks breaking on internal refactors.
|
||||
if (typeof this._client?.ws?.send === "function") {
|
||||
this._client.ws.send(0, payload);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: access shard directly only if the public API is unavailable
|
||||
const shard = this._client?.ws?.shards?.get?.(0);
|
||||
if (!shard) {
|
||||
logger.warn("[MoonlinkManager] No WebSocket shard available");
|
||||
@@ -138,21 +147,16 @@ export class MoonlinkManager extends EventEmitter {
|
||||
* @private
|
||||
*/
|
||||
_setupVoiceForwarding(client) {
|
||||
// @fluxerjs/core emits VoiceStateUpdate with a SINGLE argument:
|
||||
// (data: GatewayVoiceStateUpdateDispatchData) — raw gateway snake_case fields.
|
||||
client.on(Events.VoiceStateUpdate, (data) => {
|
||||
try {
|
||||
// data is the raw GatewayVoiceStateUpdateDispatchData — always snake_case
|
||||
const guildId = data.guild_id;
|
||||
if (!guildId) {
|
||||
logger.warn("[MoonlinkManager] voiceStateUpdate: No guild_id found in data", data);
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the proper payload format that moonlink expects:
|
||||
// { op: 0, t: "VOICE_STATE_UPDATE", d: { guild_id, user_id, channel_id, ... } }
|
||||
const payload = {
|
||||
op: 0, // Dispatch
|
||||
op: 0,
|
||||
t: "VOICE_STATE_UPDATE",
|
||||
d: {
|
||||
guild_id: guildId,
|
||||
@@ -176,9 +180,6 @@ export class MoonlinkManager extends EventEmitter {
|
||||
}
|
||||
});
|
||||
|
||||
// Raw WS — only for VOICE_SERVER_UPDATE (VOICE_STATE_UPDATE is handled above via Events listener)
|
||||
// Store the handler reference so we can remove the stale listener before re-attaching
|
||||
// on gateway reconnects. Without this, each reconnect stacks another handler on the socket.
|
||||
const attachRawWs = () => {
|
||||
try {
|
||||
const shard0 = client.ws?.shards?.get?.(0);
|
||||
@@ -196,7 +197,6 @@ export class MoonlinkManager extends EventEmitter {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
// Skip re-attaching if it's the same socket object (spurious Ready re-fire)
|
||||
if (wsObj === this._rawWsObj) return;
|
||||
|
||||
this._rawWsHandler = (rawData) => {
|
||||
@@ -213,7 +213,6 @@ export class MoonlinkManager extends EventEmitter {
|
||||
} catch (_) {}
|
||||
};
|
||||
|
||||
// Absorb socket-level errors so they don't escape to uncaughtException.
|
||||
this._rawWsErrorHandler = (err) => {
|
||||
logger.warn("[MoonlinkManager] Raw WS socket error (will reconnect):", err?.message ?? err);
|
||||
};
|
||||
@@ -233,26 +232,13 @@ export class MoonlinkManager extends EventEmitter {
|
||||
};
|
||||
|
||||
attachRawWs();
|
||||
// Re-attach after every gateway reconnect so the new socket gets the listener
|
||||
client.on(Events.Ready, attachRawWs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call after client.login() resolves and client.user.id is available.
|
||||
* Safe to call on every reconnect — removes stale internal listeners before re-init
|
||||
* to prevent the MaxListenersExceededWarning that moonlink.js triggers by adding
|
||||
* a new nodeReady/nodeConnected listener to the node socket on every init() call.
|
||||
* @param {string} clientId
|
||||
*/
|
||||
async init(clientId) {
|
||||
// Raise the limit on both this emitter and the internal manager so reconnects
|
||||
// don't spam MaxListenersExceededWarning while we're between socket teardown
|
||||
// and the re-init completing.
|
||||
this.setMaxListeners(50);
|
||||
try { this.manager.setMaxListeners?.(50); } catch (_) {}
|
||||
|
||||
// Strip any stale nodeReady listeners the previous init() call registered
|
||||
// so they don't stack up across gateway reconnects.
|
||||
try {
|
||||
for (const node of this.manager.nodes?.nodes?.values?.() ?? []) {
|
||||
const sock = node.socket ?? node.ws ?? null;
|
||||
@@ -268,30 +254,14 @@ export class MoonlinkManager extends EventEmitter {
|
||||
await this.manager.init(clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for tracks. Returns a moonlink SearchResult.
|
||||
* @param {string} query
|
||||
* @param {string} [source] e.g. "ytmsearch", "spsearch"
|
||||
* @param {*} [requester]
|
||||
*/
|
||||
search(query, source, requester) {
|
||||
return this.manager.search({ query, source, requester });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create a moonlink Player for a guild.
|
||||
* @param {{ guildId: string, voiceChannelId: string, textChannelId?: string, volume?: number }} opts
|
||||
* @returns {import("moonlink.js").Player}
|
||||
*/
|
||||
createPlayer(opts) {
|
||||
return this.manager.players.create(opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an existing player by guildId.
|
||||
* @param {string} guildId
|
||||
* @returns {import("moonlink.js").Player|undefined}
|
||||
*/
|
||||
getPlayer(guildId) {
|
||||
return this.manager.players.get(guildId);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user