mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
Add seek validation, autoplay system, progress bar & codebase cleanup
- Add seek duration validation — seeks beyond track length are rejected with clear error showing max allowed position - Add autoplay system with Last.fm similar tracks + YouTube search fallback — automatically queues similar tracks when queue ends - Add live progress bar to now playing with elapsed/total time display - Add robust ffmpeg cleanup to prevent race conditions during seek/skip/filter operations - Add proper queue advancement after seek so bot stays in voice - Add queueEnd event emission on skip/skipTo for autoplay trigger - Add _lastPlayedTrack preservation for autoplay recommendations
This commit is contained in:
1 parent
bc1fe82919
commit
0f2ee99f1e
23 files changed
+665
-170
No files matched your search
@@ -18,7 +18,6 @@ import {
|
||||
buildFluxerListUrl,
|
||||
} from "./constants/API.mjs";
|
||||
|
||||
|
||||
export class FluxerListManager {
|
||||
/**
|
||||
* @param {object} config - The `fluxerlist` section from config.json
|
||||
@@ -45,7 +44,6 @@ export class FluxerListManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a cache key from the request parameters.
|
||||
* @param {"server"|"bot"} type
|
||||
@@ -93,7 +91,6 @@ export class FluxerListManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch the list of voters for a server or bot.
|
||||
*
|
||||
@@ -218,7 +215,6 @@ export class FluxerListManager {
|
||||
return allVoters;
|
||||
}
|
||||
|
||||
|
||||
_assertEnabled() {
|
||||
if (!this.enabled) {
|
||||
throw new Error("FluxerList integration is not configured (missing apiKey in config.json).");
|
||||
|
||||
@@ -6,7 +6,6 @@ import { get247ChannelMode, remove247ChannelMode } from "./constants/Helpers247.
|
||||
import { VoiceStateCache } from "./constants/VoiceStateCache.mjs";
|
||||
import { REQUIRED_BOT_PERMISSIONS, CRITICAL_PERMISSIONS } from "./MessageHandler.mjs";
|
||||
|
||||
|
||||
/**
|
||||
* GatewayHandler — manages raw WebSocket gateway events, voice-state tracking,
|
||||
* presence rotation, and high-level Fluxer event handlers (GuildCreate,
|
||||
@@ -47,7 +46,6 @@ export class GatewayHandler {
|
||||
this._deferredDeleteCount = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a composite key for bots in the observedVoiceBots map.
|
||||
* Bots can be in multiple guilds so we namespace by guildId.
|
||||
@@ -82,7 +80,6 @@ export class GatewayHandler {
|
||||
return { key: null, value: null };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the bot has all required permissions in a newly joined guild.
|
||||
* If critical permissions are missing, log a warning and attempt to send
|
||||
@@ -151,7 +148,6 @@ export class GatewayHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Seed observedVoiceUsers / observedVoiceBots from all cached guild voice
|
||||
* states. Called once on Ready after the guild cache is populated.
|
||||
@@ -225,7 +221,6 @@ export class GatewayHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Re-read the guild's voice_states cache and update observedVoiceUsers
|
||||
* for any human users found in the specified channel.
|
||||
@@ -400,7 +395,6 @@ export class GatewayHandler {
|
||||
return humansFound;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attach a raw "message" listener to the shard-0 WebSocket so we can
|
||||
* process gateway opcodes (READY, GUILD_CREATE, VOICE_STATE_UPDATE, etc.)
|
||||
@@ -526,7 +520,6 @@ export class GatewayHandler {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
|
||||
setupPresenceRotation() {
|
||||
if (this.presenceContents.length === 0) return;
|
||||
|
||||
@@ -575,7 +568,6 @@ export class GatewayHandler {
|
||||
this.presenceTimer = setInterval(setPresence, this.presenceInterval);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register all high-level Fluxer event listeners on the Fluxer client.
|
||||
* Call once during bot startup.
|
||||
@@ -853,7 +845,6 @@ export class GatewayHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const activeGuildPlayers = [...remix.players.playerMap.entries()].filter(([, player]) =>
|
||||
String(player?._guildId ?? "").replace(/\D/g, "") === String(guildId ?? "").replace(/\D/g, "")
|
||||
);
|
||||
@@ -1101,7 +1092,6 @@ export class GatewayHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @type {Set<string>} Channel IDs currently being rejoined (dedup guard) */
|
||||
_rejoinInProgress = new Set();
|
||||
|
||||
@@ -1202,7 +1192,6 @@ export class GatewayHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invoke after the bot has connected and Moonlink has been initialised.
|
||||
* Seeds voice states, attaches raw WS listener, kicks off presence rotation,
|
||||
@@ -1511,7 +1500,6 @@ export class GatewayHandler {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform the actual cleanup for a guild that the bot was removed from.
|
||||
* Extracted from the GuildDelete handler so it can be called after the
|
||||
|
||||
+110
-11
@@ -25,7 +25,6 @@ function normalizeTrackText(value) {
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the API signature required by Last.fm for authenticated calls.
|
||||
* See: https:
|
||||
@@ -71,7 +70,6 @@ async function apiCall(params, apiSecret, post = false) {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
export class LastFmManager {
|
||||
/**
|
||||
* @param {object} config - The `lastfm` section from config.json
|
||||
@@ -103,7 +101,6 @@ export class LastFmManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the bot ID for multi-bot database isolation.
|
||||
* Ensures bot_id column exists in lastfm tables, then clears caches.
|
||||
@@ -198,7 +195,6 @@ export class LastFmManager {
|
||||
return { where: " AND bot_id = ?", params: [String(this.botId)] };
|
||||
}
|
||||
|
||||
|
||||
async _getPool() {
|
||||
if (this._pool) return this._pool;
|
||||
const mysql = await import("mysql2/promise");
|
||||
@@ -243,7 +239,6 @@ export class LastFmManager {
|
||||
`);
|
||||
}
|
||||
|
||||
|
||||
async getUser(userId) {
|
||||
const cached = this._userCache.get(userId);
|
||||
if (cached) return cached;
|
||||
@@ -308,7 +303,6 @@ export class LastFmManager {
|
||||
if (cached) cached.scrobbleEnabled = enabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Step 1: Get an auth token. The user must visit the Last.fm auth URL to approve it.
|
||||
* @returns {Promise<string>} The auth token
|
||||
@@ -342,7 +336,6 @@ export class LastFmManager {
|
||||
return data.session;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a "now playing" notification to Last.fm (does NOT count as a scrobble).
|
||||
* Called immediately when a track starts.
|
||||
@@ -404,7 +397,6 @@ export class LastFmManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the user's loved tracks.
|
||||
* @param {number} [limit=20] - Max tracks to return
|
||||
@@ -516,6 +508,54 @@ export class LastFmManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Love a track on Last.fm for the given user.
|
||||
* @param {string} userId - The Fluxer user ID
|
||||
* @param {string} artist - Track artist
|
||||
* @param {string} track - Track name
|
||||
*/
|
||||
async loveTrack(userId, artist, track) {
|
||||
if (!this.enabled) return;
|
||||
const user = await this.getUser(userId);
|
||||
if (!user) throw new Error("NOT_LINKED");
|
||||
|
||||
await apiCall(
|
||||
{
|
||||
method: "track.love",
|
||||
api_key: this.apiKey,
|
||||
sk: user.sessionKey,
|
||||
artist,
|
||||
track,
|
||||
},
|
||||
this.apiSecret,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlove a track on Last.fm for the given user.
|
||||
* @param {string} userId - The Fluxer user ID
|
||||
* @param {string} artist - Track artist
|
||||
* @param {string} track - Track name
|
||||
*/
|
||||
async unloveTrack(userId, artist, track) {
|
||||
if (!this.enabled) return;
|
||||
const user = await this.getUser(userId);
|
||||
if (!user) throw new Error("NOT_LINKED");
|
||||
|
||||
await apiCall(
|
||||
{
|
||||
method: "track.unlove",
|
||||
api_key: this.apiKey,
|
||||
sk: user.sessionKey,
|
||||
artist,
|
||||
track,
|
||||
},
|
||||
this.apiSecret,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Last.fm for a freeform track query and return the best match.
|
||||
* Useful for `%play lastfm: kendrick lamar luther` where artist/title
|
||||
@@ -644,6 +684,39 @@ export class LastFmManager {
|
||||
return scored[0]?.track ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get similar tracks from Last.fm for a given track.
|
||||
* @param {string} artist
|
||||
* @param {string} track
|
||||
* @param {number} [limit=5]
|
||||
* @returns {Promise<Array<{ artist: string, name: string, url: string, match: number }>>}
|
||||
*/
|
||||
async getSimilarTracks(artist, track, limit = 5) {
|
||||
if (!this.enabled) return [];
|
||||
|
||||
try {
|
||||
const data = await apiCall(
|
||||
{
|
||||
method: "track.getsimilar",
|
||||
api_key: this.apiKey,
|
||||
artist,
|
||||
track,
|
||||
limit,
|
||||
},
|
||||
this.apiSecret
|
||||
);
|
||||
|
||||
return (data.similartracks?.track ?? []).map(t => ({
|
||||
artist: t.artist?.name ?? "Unknown",
|
||||
name: t.name,
|
||||
url: t.url ?? "",
|
||||
match: parseFloat(t.match ?? 0),
|
||||
})).filter(t => t.match > 0.1);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a Last.fm music URL and extract artist and track info.
|
||||
* Supports:
|
||||
@@ -717,7 +790,6 @@ export class LastFmManager {
|
||||
return data.user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of the user's Last.fm playlists by scraping their profile page.
|
||||
* The Last.fm API removed user.getplaylists, so we fetch the HTML page.
|
||||
@@ -893,6 +965,35 @@ export class LastFmManager {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's top artists.
|
||||
* @param {string} userId
|
||||
* @param {string} [period="overall"] - overall | 7day | 1month | 3month | 6month | 12month
|
||||
* @param {number} [limit=15]
|
||||
* @returns {Promise<Array<{ name: string, url: string, playcount: number, image: string }>>}
|
||||
*/
|
||||
async getTopArtists(userId, period = "overall", limit = 15) {
|
||||
const user = await this.getUser(userId);
|
||||
if (!user) throw new Error("NOT_LINKED");
|
||||
|
||||
const data = await apiCall(
|
||||
{
|
||||
method: "user.gettopartists",
|
||||
api_key: this.apiKey,
|
||||
user: user.username,
|
||||
period,
|
||||
limit,
|
||||
},
|
||||
this.apiSecret
|
||||
);
|
||||
|
||||
return (data.topartists?.artist ?? []).map(a => ({
|
||||
name: a.name,
|
||||
url: a.url ?? "",
|
||||
playcount: a.playcount ?? 0,
|
||||
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch tracks from Last.fm by category and return search queries
|
||||
@@ -956,7 +1057,6 @@ export class LastFmManager {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the total lifetime scrobbles across ALL linked Last.fm users.
|
||||
* Syncs each user's scrobble count from the Last.fm API, then sums them up.
|
||||
@@ -1104,7 +1204,6 @@ export class LastFmManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_assertEnabled() {
|
||||
if (!this.enabled) throw new Error("Last.fm integration is not configured (missing apiKey/apiSecret).");
|
||||
}
|
||||
|
||||
@@ -1080,7 +1080,6 @@ export class QueuePaginator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const HELP_CMDS_PER_PAGE = 10;
|
||||
const HELP_SESSION_MS = 30 * 1000;
|
||||
|
||||
@@ -1254,7 +1253,6 @@ export class HelpCommand {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
_handle(msg, args, prefix) {
|
||||
const allCmds = this._commands.commands;
|
||||
const query = (args[0] ?? "").trim();
|
||||
|
||||
@@ -9,7 +9,6 @@ import { logger } from "./constants/Logger.mjs";
|
||||
import { EventEmitter } from "node:events";
|
||||
import { Events } from "@fluxerjs/core";
|
||||
|
||||
|
||||
export class MoonlinkManager extends EventEmitter {
|
||||
/** @type {Manager} */
|
||||
manager = null;
|
||||
|
||||
+181
-53
@@ -84,7 +84,6 @@ function isIgnorableMediaStateError(err) {
|
||||
return msg.includes("InvalidState") || msg.includes("failed to capture frame") || msg.includes("capture frame");
|
||||
}
|
||||
|
||||
|
||||
class PlayerWorkerPool {
|
||||
constructor(size, workerPath, nlConfig = {}) {
|
||||
this._size = size;
|
||||
@@ -194,7 +193,6 @@ class PlayerWorkerPool {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class Queue extends EventEmitter {
|
||||
data = [];
|
||||
current = null;
|
||||
@@ -292,7 +290,6 @@ export class Queue extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default class Player extends EventEmitter {
|
||||
/** @type {import("revoice.js").VoiceConnection|null} */
|
||||
connection = null;
|
||||
@@ -325,10 +322,15 @@ export default class Player extends EventEmitter {
|
||||
|
||||
_streamingStopped = false;
|
||||
_skipping = false;
|
||||
_seeking = false;
|
||||
_currentPassthrough = null;
|
||||
_wasRadio = false;
|
||||
_radioAnnounced = false;
|
||||
_queueEndedSent = false;
|
||||
_lastPlayedTrack = null;
|
||||
|
||||
_autoplay = false;
|
||||
_autoplayHandler = null;
|
||||
|
||||
activeFilter = null;
|
||||
activeFilterPayload = null;
|
||||
@@ -395,7 +397,6 @@ export default class Player extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if 24/7 mode is enabled for this player's channel.
|
||||
* Returns true for both "on" and "auto" modes.
|
||||
@@ -465,7 +466,6 @@ export default class Player extends EventEmitter {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
_restoreVolume() {
|
||||
if (!this._guildId) return;
|
||||
let savedVol = null;
|
||||
@@ -491,7 +491,6 @@ export default class Player extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_hasHumansInChannel() {
|
||||
if (!this._channelId || !this._guildId) return false;
|
||||
const cleanChan = String(this._channelId).replace(/\D/g, "");
|
||||
@@ -605,7 +604,6 @@ export default class Player extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async _ensureMediaPlayer() {
|
||||
if (this._destroyed) return false;
|
||||
if (!this.connection) return false;
|
||||
@@ -625,7 +623,12 @@ export default class Player extends EventEmitter {
|
||||
return true;
|
||||
}
|
||||
logger.mediaplayer("[Player] Existing MediaPlayer unhealthy, cleaning up...");
|
||||
try { await this._mediaPlayer.stop(); } catch (_) {}
|
||||
try {
|
||||
if (this._mediaPlayer.fProc) {
|
||||
try { this._mediaPlayer.fProc.removeAllListeners(); } catch (_) {}
|
||||
}
|
||||
await this._mediaPlayer.stop();
|
||||
} catch (_) {}
|
||||
this._mediaPlayer = null;
|
||||
}
|
||||
|
||||
@@ -647,7 +650,7 @@ export default class Player extends EventEmitter {
|
||||
if (mp.source && typeof mp.source.captureFrame === "function") {
|
||||
const _orig = mp.source.captureFrame.bind(mp.source);
|
||||
mp.source.captureFrame = async (frame) => {
|
||||
if (this._streamingStopped || this._skipping || this.leaving || this._destroyed) {
|
||||
if (this._streamingStopped || this._skipping || this._seeking || this.leaving || this._destroyed) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -708,19 +711,25 @@ export default class Player extends EventEmitter {
|
||||
|
||||
if (this._mediaPlayer) {
|
||||
try {
|
||||
if (this._mediaPlayer.fProc && !this._mediaPlayer.ffmpegFinished) {
|
||||
try { this._mediaPlayer.fProc.kill("SIGKILL"); } catch (_) {}
|
||||
if (this._mediaPlayer.fProc) {
|
||||
try { this._mediaPlayer.fProc.removeAllListeners(); } catch (_) {}
|
||||
}
|
||||
|
||||
await this._mediaPlayer.stop();
|
||||
} catch (e) {
|
||||
logger.error("[Player] Error stopping media player:", e.message);
|
||||
}
|
||||
|
||||
try {
|
||||
if (this._mediaPlayer?.fProc && !this._mediaPlayer.ffmpegFinished) {
|
||||
try { this._mediaPlayer.fProc.kill("SIGKILL"); } catch (_) {}
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
this._mediaPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async _request(url, options = {}, returnStream = false) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fetchUrl = (target, _redirects = 0) => {
|
||||
@@ -814,7 +823,6 @@ export default class Player extends EventEmitter {
|
||||
return elapsedMs / totalMs >= 0.85 || remainingMs <= 15_000;
|
||||
}
|
||||
|
||||
|
||||
async _streamViaRevoice(url, inputOptions = []) {
|
||||
if (this._streamingStopped) return;
|
||||
|
||||
@@ -839,7 +847,7 @@ export default class Player extends EventEmitter {
|
||||
await new Promise((resolve, reject) => {
|
||||
audioStream.on("error", (e) => {
|
||||
cleanup();
|
||||
if (this._streamingStopped || this._skipping) return resolve();
|
||||
if (this._streamingStopped || this._skipping || this._seeking) return resolve();
|
||||
const graceful = ["aborted", "ECONNRESET", "ERR_STREAM_DESTROYED", "ENOTFOUND", "ETIMEDOUT", "ECONNREFUSED"];
|
||||
if (graceful.some(g => e.code === g || e.message?.includes(g))) {
|
||||
if (this._didTrackMostlyFinish(currentTrack)) return resolve();
|
||||
@@ -869,13 +877,13 @@ export default class Player extends EventEmitter {
|
||||
return resolve();
|
||||
}
|
||||
cleanup();
|
||||
if (this._streamingStopped || this._skipping) return resolve();
|
||||
if (this._streamingStopped || this._skipping || this._seeking) return resolve();
|
||||
return reject(new Error(`FFmpeg stream ended early: ${ffMsg}`));
|
||||
}
|
||||
|
||||
logger.error("[Player] FFmpeg error:", ffMsg);
|
||||
cleanup();
|
||||
if (this._streamingStopped || this._skipping) return resolve();
|
||||
if (this._streamingStopped || this._skipping || this._seeking) return resolve();
|
||||
reject(new Error(`FFmpeg: ${ffMsg}`));
|
||||
};
|
||||
|
||||
@@ -883,7 +891,7 @@ export default class Player extends EventEmitter {
|
||||
const playResult = this._mediaPlayer.playStream(audioStream, inputOptions);
|
||||
if (playResult && typeof playResult.catch === "function") {
|
||||
playResult.catch((e) => {
|
||||
if (isIgnorableMediaStateError(e) || this._streamingStopped || this._skipping || this.leaving) {
|
||||
if (isIgnorableMediaStateError(e) || this._streamingStopped || this._skipping || this._seeking || this.leaving) {
|
||||
logger.mediaplayer("[Player] Suppressed async playStream InvalidState rejection");
|
||||
cleanup();
|
||||
resolve();
|
||||
@@ -978,7 +986,6 @@ export default class Player extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async join(channelId) {
|
||||
if (this._destroyed) return;
|
||||
|
||||
@@ -1259,6 +1266,11 @@ export default class Player extends EventEmitter {
|
||||
this._paused = false;
|
||||
this._pausedAt = null;
|
||||
this._playingNext = false;
|
||||
this._autoplay = false;
|
||||
if (this._autoplayHandler) {
|
||||
this.removeListener("queueEnd", this._autoplayHandler);
|
||||
this._autoplayHandler = null;
|
||||
}
|
||||
this.leaving = false;
|
||||
} catch (e) {
|
||||
logger.error("[Player] leave error:", e.message);
|
||||
@@ -1280,6 +1292,11 @@ export default class Player extends EventEmitter {
|
||||
this.leaving = true;
|
||||
this._streamingStopped = true;
|
||||
this._stopInactivityTimer();
|
||||
this._autoplay = false;
|
||||
if (this._autoplayHandler) {
|
||||
this.removeListener("queueEnd", this._autoplayHandler);
|
||||
this._autoplayHandler = null;
|
||||
}
|
||||
this.searches.clear();
|
||||
|
||||
if (this._workerPool) {
|
||||
@@ -1309,7 +1326,6 @@ export default class Player extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
get paused() { return this._paused; }
|
||||
|
||||
pause() {
|
||||
@@ -1346,20 +1362,24 @@ export default class Player extends EventEmitter {
|
||||
skip() {
|
||||
if (!this.connection || !this.queue.getCurrent())
|
||||
return ":negative_squared_cross_mark: There's nothing playing at the moment!";
|
||||
this._lastPlayedTrack = this.queue.getCurrent();
|
||||
this._skipping = true;
|
||||
this._radioAnnounced = false;
|
||||
this.queue.current = null;
|
||||
|
||||
if (this.queue.isEmpty() && !this._wasRadio && !this._queueEndedSent) {
|
||||
this._queueEndedSent = true;
|
||||
const prefix = (() => {
|
||||
try {
|
||||
return this.settingsMgr?.getServer?.(this._guildId)?.get?.("prefix")
|
||||
?? this.settings?.get?.("prefix")
|
||||
?? "%";
|
||||
} catch (_) { return "%"; }
|
||||
})();
|
||||
this.emit("message", { ...mkEmbed(this._t("responses._common.queueEnded", { prefix })), system: true });
|
||||
this.emit("queueEnd");
|
||||
if (!this._autoplay) {
|
||||
const prefix = (() => {
|
||||
try {
|
||||
return this.settingsMgr?.getServer?.(this._guildId)?.get?.("prefix")
|
||||
?? this.settings?.get?.("prefix")
|
||||
?? "%";
|
||||
} catch (_) { return "%"; }
|
||||
})();
|
||||
this.emit("message", { ...mkEmbed(this._t("responses._common.queueEnded", { prefix })), system: true });
|
||||
}
|
||||
}
|
||||
|
||||
this._stopMediaPlayer().then(() => {
|
||||
@@ -1385,20 +1405,24 @@ export default class Player extends EventEmitter {
|
||||
const idx = position - 1;
|
||||
if (idx < 0 || idx >= this.queue.size())
|
||||
return `:negative_squared_cross_mark: Position ${position} out of range (queue has ${this.queue.size()} tracks).`;
|
||||
this._lastPlayedTrack = this.queue.getCurrent();
|
||||
this.queue.data.splice(0, idx);
|
||||
this.queue.current = null;
|
||||
this._skipping = true;
|
||||
|
||||
if (this.queue.isEmpty() && !this._wasRadio && !this._queueEndedSent) {
|
||||
this._queueEndedSent = true;
|
||||
const prefix = (() => {
|
||||
try {
|
||||
return this.settingsMgr?.getServer?.(this._guildId)?.get?.("prefix")
|
||||
?? this.settings?.get?.("prefix")
|
||||
?? "%";
|
||||
} catch (_) { return "%"; }
|
||||
})();
|
||||
this.emit("message", { ...mkEmbed(this._t("responses._common.queueEnded", { prefix })), system: true });
|
||||
this.emit("queueEnd");
|
||||
if (!this._autoplay) {
|
||||
const prefix = (() => {
|
||||
try {
|
||||
return this.settingsMgr?.getServer?.(this._guildId)?.get?.("prefix")
|
||||
?? this.settings?.get?.("prefix")
|
||||
?? "%";
|
||||
} catch (_) { return "%"; }
|
||||
})();
|
||||
this.emit("message", { ...mkEmbed(this._t("responses._common.queueEnded", { prefix })), system: true });
|
||||
}
|
||||
}
|
||||
|
||||
this._stopMediaPlayer().then(() => {
|
||||
@@ -1418,7 +1442,6 @@ export default class Player extends EventEmitter {
|
||||
return `:track_next: Skipped to position ${position}`;
|
||||
}
|
||||
|
||||
|
||||
setVolume(v) {
|
||||
this.preferredVolume = Utils.clamp(v, 0, 2);
|
||||
this.emit("volume", this.preferredVolume);
|
||||
@@ -1428,6 +1451,75 @@ export default class Player extends EventEmitter {
|
||||
return `Volume changed to \`${Math.round(this.preferredVolume * 100)}%\`.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek to a specific position (in milliseconds) in the currently playing track.
|
||||
*
|
||||
* 1. Sends a PATCH to the NodeLink REST API so the session state is aware
|
||||
* of the new position.
|
||||
* 2. Adjusts `startedPlaying` so that elapsed-time calculations remain
|
||||
* consistent after the seek.
|
||||
* 3. Restarts the audio stream from the new position (re-uses the
|
||||
* `_replayWithFilters` path so active filters are preserved).
|
||||
*
|
||||
* @param {number} ms Position in milliseconds to seek to.
|
||||
* @returns {Promise<boolean>} true if the seek succeeded, false if the
|
||||
* node doesn't support it or no session is available.
|
||||
*/
|
||||
async seekToPosition(ms) {
|
||||
const guildId = this._guildId;
|
||||
if (!guildId) return false;
|
||||
|
||||
const current = this.queue.getCurrent();
|
||||
if (!current?.encoded) return false;
|
||||
|
||||
const liveSessionId = this._moonlink?.getLiveSessionId?.() ?? this._moonlink?.sessionId ?? this._nl.sessionId;
|
||||
if (!liveSessionId) return false;
|
||||
|
||||
const { host, port } = this._nl;
|
||||
const url = `http://${host}:${port}/v4/sessions/${liveSessionId}/players/${guildId}`;
|
||||
const body = JSON.stringify({ position: ms });
|
||||
|
||||
this._seeking = true;
|
||||
|
||||
try {
|
||||
await this._request(url, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": Buffer.byteLength(body),
|
||||
},
|
||||
body,
|
||||
});
|
||||
|
||||
if (liveSessionId !== this._nl.sessionId) {
|
||||
this._nl.sessionId = liveSessionId;
|
||||
logger.moonlink(`[Player] Synced session ID after seek: ${liveSessionId}`);
|
||||
}
|
||||
|
||||
this.startedPlaying = Date.now() - ms;
|
||||
logger.player(`[Player] Seeked to ${ms}ms — adjusted startedPlaying`);
|
||||
|
||||
if (this.connection && !this.leaving && !this._streamingStopped) {
|
||||
this._replayWithFilters(ms).catch((e) => {
|
||||
logger.warn("[Player] Seek replay failed (non-fatal):", e.message);
|
||||
});
|
||||
}
|
||||
|
||||
await Utils.sleep(500);
|
||||
this._seeking = false;
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
this._seeking = false;
|
||||
const errMsg = e?.message ?? "";
|
||||
if (errMsg.includes("HTTP 404") || errMsg.includes("HTTP 405")) {
|
||||
logger.warn("[Player] Seek not supported by audio node:", errMsg);
|
||||
return false;
|
||||
}
|
||||
logger.error("[Player] Seek request failed:", errMsg);
|
||||
throw new Error(sanitizeError(errMsg, this._nl));
|
||||
}
|
||||
}
|
||||
|
||||
async applyFilter(filterPayload, meta = null) {
|
||||
const guildId = this._guildId;
|
||||
@@ -1473,9 +1565,11 @@ export default class Player extends EventEmitter {
|
||||
const elapsed = this.startedPlaying ? (Date.now() - this.startedPlaying) : 0;
|
||||
const positionMs = Math.max(0, elapsed);
|
||||
logger.player(`[Player] Filter applied — restarting stream from ${positionMs}ms`);
|
||||
this._seeking = true;
|
||||
this._replayWithFilters(positionMs).catch((e) => {
|
||||
logger.warn("[Player] Filter replay failed (non-fatal):", e.message);
|
||||
});
|
||||
setTimeout(() => { this._seeking = false; }, 500);
|
||||
}
|
||||
|
||||
return { ok: true };
|
||||
@@ -1519,8 +1613,26 @@ export default class Player extends EventEmitter {
|
||||
} catch (e) {
|
||||
logger.warn("[Player] _replayWithFilters stream error:", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.leaving && !this._skipping && !this._seeking && !this._paused) {
|
||||
const current = this.queue.getCurrent();
|
||||
if (current?.type === "radio") {
|
||||
logger.player("[Player] Radio stream ended after replay");
|
||||
this._lastPlayedTrack = current;
|
||||
this.queue.current = null;
|
||||
this._streamingStopped = true;
|
||||
this.emit("stopplay");
|
||||
if (!this._is247Enabled()) {
|
||||
this._startInactivityTimer();
|
||||
}
|
||||
} else {
|
||||
this._lastPlayedTrack = current;
|
||||
if (!this.queue.songLoop) this.queue.current = null;
|
||||
this._streamingStopped = false;
|
||||
this.playNext().catch(e => logger.error("[Player] post-replay playNext error:", e.message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isEmpty() { return this.queue.isEmpty(); }
|
||||
|
||||
@@ -1589,10 +1701,15 @@ export default class Player extends EventEmitter {
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
_createProgressBar(length = 15) {
|
||||
const current = this.queue.getCurrent();
|
||||
if (!current?.duration || !this.startedPlaying) return Utils.progressBar(0, 1, length);
|
||||
if (!current?.duration || !this.startedPlaying) {
|
||||
const total = this._getTrackDurationMs(current);
|
||||
if (total > 0) {
|
||||
return `${Utils.progressBar(0, total, length)} \`0:00 / ${Utils.prettifyMS(total)}\``;
|
||||
}
|
||||
return Utils.progressBar(0, 1, length);
|
||||
}
|
||||
|
||||
const totalMs = this._getTrackDurationMs(current);
|
||||
let elapsed = Date.now() - this.startedPlaying;
|
||||
@@ -1693,36 +1810,43 @@ export default class Player extends EventEmitter {
|
||||
const current = this.queue.getCurrent();
|
||||
if (!current) return { msg: "There's nothing playing at the moment." };
|
||||
|
||||
const loopqueue = this.queue.loop ? "**enabled**" : "**disabled**";
|
||||
const songloop = this.queue.songLoop ? "**enabled**" : "**disabled**";
|
||||
const loopqueue = this.queue.loop ? "🔄" : "⏹️";
|
||||
const songloop = this.queue.songLoop ? "🔂" : "⏹️";
|
||||
const vol = `${Math.round((this.preferredVolume || 1) * 100)}%`;
|
||||
const autoplay = this._autoplay ? "🔁" : "⏹️";
|
||||
|
||||
const vcLine = this._channelId ? `🔊 **Now playing in:** <#${this._channelId}>\n\n` : "";
|
||||
const vcLine = this._channelId ? `🔊 <#${this._channelId}>\n` : "";
|
||||
|
||||
if (current.type === "radio") {
|
||||
try {
|
||||
const data = await meta(current.url);
|
||||
return {
|
||||
msg: `${vcLine}📻 Streaming **[${current.title}](${current.author?.url || current.url})**\n\n${current.description || ""}\n\nCurrent song: ${data?.title || "Unknown"}\n\nVolume: ${vol}\n\nQueue loop: ${loopqueue}\nSong loop: ${songloop}`,
|
||||
msg: `${vcLine}📻 **[${current.title}](${current.author?.url || current.url})**\n${current.description || ""}\n\n🎵 Now playing: ${data?.title || "Unknown"}\n\n🔉 ${vol} │ ${loopqueue} Queue │ ${songloop} Song │ ${autoplay} Autoplay`,
|
||||
image: current.thumbnail
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
msg: `${vcLine}📻 Streaming **[${current.title}](${current.author?.url || current.url})**\n\nVolume: ${vol}\n\nQueue loop: ${loopqueue}\nSong loop: ${songloop}`,
|
||||
msg: `${vcLine}📻 **[${current.title}](${current.author?.url || current.url})**\n\n🔉 ${vol} │ ${loopqueue} Queue │ ${songloop} Song │ ${autoplay} Autoplay`,
|
||||
image: current.thumbnail
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (current.type === "external") {
|
||||
const totalMs = this._getTrackDurationMs(current);
|
||||
let progressLine = "";
|
||||
if (totalMs > 0) {
|
||||
progressLine = `\n${this._createProgressBar(20)}`;
|
||||
}
|
||||
return {
|
||||
msg: `${vcLine}Playing **[${current.title}](${current.url}) by [${current.artist || "Unknown"}](${current.author?.url || ""})**\n\nVolume: ${vol}\n\nQueue loop: ${loopqueue}\nSong loop: ${songloop}`,
|
||||
msg: `${vcLine}🎵 **[${current.title}](${current.url})** by ${current.artist || "Unknown"}${progressLine}\n\n🔉 ${vol} │ ${loopqueue} Queue │ ${songloop} Song │ ${autoplay} Autoplay`,
|
||||
image: current.thumbnail
|
||||
};
|
||||
}
|
||||
|
||||
const progressBar = this._createProgressBar(20);
|
||||
return {
|
||||
msg: `${vcLine}🎵 Playing: **[${current.title}](${current.spotifyUrl || current.url})** (${this.getCurrentElapsedDuration()}/${this.getCurrentDuration()})\n\nVolume: ${vol}\n\nQueue loop: ${loopqueue}\nSong loop: ${songloop}`,
|
||||
msg: `${vcLine}🎵 **[${current.title}](${current.spotifyUrl || current.url})**\n${progressBar}\n\n🔉 ${vol} │ ${loopqueue} Queue │ ${songloop} Song │ ${autoplay} Autoplay`,
|
||||
image: current.thumbnail
|
||||
};
|
||||
}
|
||||
@@ -1778,7 +1902,6 @@ export default class Player extends EventEmitter {
|
||||
})));
|
||||
}
|
||||
|
||||
|
||||
_workerPool = null;
|
||||
|
||||
_getWorkerPool() {
|
||||
@@ -1806,7 +1929,6 @@ export default class Player extends EventEmitter {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
async fetchResults(query, id, provider = "ytm") {
|
||||
try {
|
||||
const data = await this.workerJob("searchResults", { query, provider, resultCount: this.resultLimit });
|
||||
@@ -1892,7 +2014,6 @@ export default class Player extends EventEmitter {
|
||||
return events;
|
||||
}
|
||||
|
||||
|
||||
_buildRadioTrack(radio) {
|
||||
return {
|
||||
type: "radio",
|
||||
@@ -1935,7 +2056,6 @@ export default class Player extends EventEmitter {
|
||||
if (!this.leaving) this.playNext().catch(e => logger.error("[Player] playNext error:", e.message));
|
||||
}
|
||||
|
||||
|
||||
async playNext() {
|
||||
if (this._playingNext) return;
|
||||
this._playingNext = true;
|
||||
@@ -1954,15 +2074,21 @@ export default class Player extends EventEmitter {
|
||||
|
||||
if (this._mediaPlayer) {
|
||||
try {
|
||||
if (this._mediaPlayer.fProc) {
|
||||
try { this._mediaPlayer.fProc.removeAllListeners(); } catch (_) {}
|
||||
}
|
||||
await this._mediaPlayer.stop();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
this._streamingStopped = false;
|
||||
|
||||
const currentBeforeNext = this.queue.getCurrent();
|
||||
if (currentBeforeNext) this._lastPlayedTrack = currentBeforeNext;
|
||||
const songData = this.queue.next();
|
||||
if (!songData) {
|
||||
this.emit("stopplay");
|
||||
this.emit("queueEnd");
|
||||
|
||||
if (!this._is247Enabled()) {
|
||||
this._startInactivityTimer();
|
||||
@@ -1970,7 +2096,7 @@ export default class Player extends EventEmitter {
|
||||
logger.voice247("[Player] 24/7 enabled, staying in channel");
|
||||
}
|
||||
|
||||
if (!this._wasRadio && !this._queueEndedSent) {
|
||||
if (!this._wasRadio && !this._queueEndedSent && !this._autoplay) {
|
||||
this._queueEndedSent = true;
|
||||
const prefix = (() => {
|
||||
try {
|
||||
@@ -2105,9 +2231,10 @@ export default class Player extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.leaving && !this._skipping) {
|
||||
if (!this.leaving && !this._skipping && !this._seeking) {
|
||||
if (songData.type === "radio") {
|
||||
logger.player(`[Player] Radio stream ended: ${songData.title}`);
|
||||
this._lastPlayedTrack = this.queue.getCurrent() ?? songData;
|
||||
this.queue.current = null;
|
||||
this._streamingStopped = true;
|
||||
this.emit("stopplay");
|
||||
@@ -2117,6 +2244,7 @@ export default class Player extends EventEmitter {
|
||||
return;
|
||||
} else {
|
||||
if (!this._paused) {
|
||||
this._lastPlayedTrack = this.queue.getCurrent() ?? songData;
|
||||
if (!this.queue.songLoop) this.queue.current = null;
|
||||
this._streamingStopped = false;
|
||||
return this._doPlayNext();
|
||||
@@ -2124,9 +2252,9 @@ export default class Player extends EventEmitter {
|
||||
}
|
||||
}
|
||||
this._skipping = false;
|
||||
if (this._seeking) this._seeking = false;
|
||||
}
|
||||
|
||||
|
||||
async lyrics() {
|
||||
const current = this.queue.getCurrent();
|
||||
if (!current) return null;
|
||||
|
||||
@@ -163,7 +163,6 @@ export class PlayerManager {
|
||||
this._lastfm = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a channel to the guild→player reverse index.
|
||||
* Called after a successful player join.
|
||||
@@ -275,13 +274,11 @@ export class PlayerManager {
|
||||
writable: true,
|
||||
});
|
||||
|
||||
|
||||
const emit = (type, data) => {
|
||||
if (!this.dashboard?.enabled) return;
|
||||
this.dashboard.updatePlayer({ type, data }, player);
|
||||
};
|
||||
|
||||
|
||||
const emitGlobal = (type) => {
|
||||
if (!this.dashboard?.enabled) return;
|
||||
this.dashboard.playerUpdate({ type }, player);
|
||||
@@ -315,7 +312,6 @@ export class PlayerManager {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
player.on("roomfetched", () => {
|
||||
emitGlobal("init");
|
||||
sendUserUpdates("join");
|
||||
@@ -374,7 +370,6 @@ export class PlayerManager {
|
||||
emit("stopplay", null);
|
||||
});
|
||||
|
||||
|
||||
player.queue?.on("queue", (queueEvent) => {
|
||||
const serialised = { type: queueEvent.type };
|
||||
switch (queueEvent.type) {
|
||||
@@ -440,7 +435,6 @@ export class PlayerManager {
|
||||
return this.locale.translate(guildId, key, replacements);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to detect the voice channel a user is currently in.
|
||||
* @param {Message} message
|
||||
@@ -562,7 +556,6 @@ export class PlayerManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get or create a player for the user's voice channel.
|
||||
* @param {Message} message
|
||||
@@ -659,7 +652,6 @@ export class PlayerManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prompt the user to select a voice channel.
|
||||
* @param {Message} msg
|
||||
@@ -749,7 +741,6 @@ export class PlayerManager {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make the player leave its current voice channel.
|
||||
* @param {Message} msg
|
||||
@@ -789,7 +780,6 @@ export class PlayerManager {
|
||||
await msg.reply(mkEmbed(this._t(msg, "responses._common.successfullyLeft")));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create and register a new Player for the given voice channel.
|
||||
* @param {Message} message
|
||||
@@ -972,7 +962,6 @@ export class PlayerManager {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
(async () => {
|
||||
const statusMsg = await message.reply(mkEmbed(this._t(message, "responses.join.joining")));
|
||||
try {
|
||||
@@ -1045,7 +1034,6 @@ export class PlayerManager {
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle the "startplay" event for Last.fm: send now-playing notification
|
||||
* to all linked users in the voice channel, and schedule a deferred scrobble
|
||||
|
||||
+6
-13
@@ -63,7 +63,6 @@ export class Utils {
|
||||
return this.prettifyMS(seconds * 1000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shuffles array in-place using Fisher-Yates algorithm
|
||||
* @template T
|
||||
@@ -118,7 +117,6 @@ export class Utils {
|
||||
return [...new Set(array)];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Truncate text with ellipsis
|
||||
* @param {string} str - String to truncate
|
||||
@@ -210,7 +208,6 @@ export class Utils {
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate random unique ID
|
||||
* @param {number} [length=16] - Desired length of ID (8-32 recommended)
|
||||
@@ -241,7 +238,6 @@ export class Utils {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a string represents a finite number
|
||||
* @param {string} str
|
||||
@@ -296,7 +292,6 @@ export class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sleep/delay promise
|
||||
* @param {number} ms - Milliseconds to sleep
|
||||
@@ -350,7 +345,6 @@ export class Utils {
|
||||
return Promise.race([promise, timeoutPromise]).finally(() => clearTimeout(timerId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deep clone an object (JSON method - not suitable for circular refs)
|
||||
* @template T
|
||||
@@ -398,24 +392,23 @@ export class Utils {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create progress bar string
|
||||
* @param {number} current - Current position in ms or 0-1 ratio
|
||||
* @param {number} [total] - Total duration in ms (if omitted, current is treated as 0-1 ratio)
|
||||
* @param {number} [length=15] - Bar length in characters
|
||||
* @param {string} [filledChar="▬"] - Filled character
|
||||
* @param {string} [emptyChar="▬"] - Empty character
|
||||
* @param {string} [indicator="🔘"] - Position indicator
|
||||
* @param {string} [filledChar="━"] - Filled character
|
||||
* @param {string} [emptyChar="─"] - Empty character
|
||||
* @param {string} [indicator="⬤"] - Position indicator
|
||||
* @returns {string} Progress bar string
|
||||
*/
|
||||
static progressBar(
|
||||
current,
|
||||
total,
|
||||
length = 15,
|
||||
filledChar = "▬",
|
||||
emptyChar = "▬",
|
||||
indicator = "🔘"
|
||||
filledChar = "━",
|
||||
emptyChar = "─",
|
||||
indicator = "⬤"
|
||||
) {
|
||||
let progress;
|
||||
if (total !== undefined && total > 0) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
* Edit only here; FluxerListManager.mjs and commands/vote.mjs import from this file.
|
||||
*/
|
||||
|
||||
|
||||
export const FLUXERLIST = {
|
||||
/** Base URL for all FluxerList API v1 endpoints */
|
||||
BASE_URL: "https://fluxerlist.com/api/v1",
|
||||
|
||||
@@ -70,7 +70,6 @@ import { logger } from "./Logger.mjs";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Helper: returns a human-readable label for a ConnectionState value */
|
||||
function stateLabel(cs) {
|
||||
if (cs === ConnectionState?.CONN_CONNECTED) return "CONN_CONNECTED";
|
||||
@@ -82,7 +81,6 @@ function stateLabel(cs) {
|
||||
return String(cs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A voice connection that wraps a LiveKit Room obtained via the Fluxer
|
||||
* gateway. Exposes the same interface as revoice.js's VoiceConnection:
|
||||
@@ -183,7 +181,6 @@ export class FluxerVoiceConnection extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Revoice-compatible class that uses the Fluxer gateway for voice joins.
|
||||
*
|
||||
@@ -510,7 +507,6 @@ export class FluxerRevoice extends EventEmitter {
|
||||
nativeConnection,
|
||||
});
|
||||
|
||||
|
||||
room.on(RoomEvent.Disconnected, (reason) => {
|
||||
const isIntentional = this._intentionalDisconnects.has(String(channelId));
|
||||
const reasonLabel = isIntentional ? "intentional" : (reason ?? "unexpected");
|
||||
@@ -532,7 +528,6 @@ export class FluxerRevoice extends EventEmitter {
|
||||
connection.emit("disconnect");
|
||||
});
|
||||
|
||||
|
||||
room.on(RoomEvent.ParticipantConnected, (participant) => {
|
||||
const userId = participant?.identity ?? participant?.sid;
|
||||
if (userId) {
|
||||
|
||||
@@ -46,7 +46,6 @@ export class VoiceStateCache {
|
||||
this._lruBotKeys = [];
|
||||
}
|
||||
|
||||
|
||||
/** Build composite key "guildId:userId" (both cleaned to digits only) */
|
||||
static userKey(guildId, userId) {
|
||||
return `${String(guildId ?? "").replace(/\D/g, "")}:${String(userId ?? "").replace(/\D/g, "")}`;
|
||||
@@ -57,7 +56,6 @@ export class VoiceStateCache {
|
||||
return `${String(guildId ?? "").replace(/\D/g, "")}:${String(channelId ?? "").replace(/\D/g, "")}`;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update voice state for a user.
|
||||
*
|
||||
@@ -130,7 +128,6 @@ export class VoiceStateCache {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if there are any human users in a specific channel.
|
||||
* O(1) via channelMembers index.
|
||||
@@ -224,7 +221,6 @@ export class VoiceStateCache {
|
||||
this.updateUser({ guildId, userId, channelId, isBot });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all entries for a specific guild (used on GuildDelete).
|
||||
*
|
||||
@@ -331,7 +327,6 @@ export class VoiceStateCache {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the "observedVoiceUsers" size (human count).
|
||||
* Backward-compat with `this.observedVoiceUsers.size`
|
||||
@@ -480,7 +475,6 @@ export class VoiceStateCache {
|
||||
return this.botLocations.has(compositeKey);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default iterator — iterates human users.
|
||||
* Yields [userId, {channelId, guildId}] — same shape as old observedVoiceUsers Map.
|
||||
@@ -608,7 +602,6 @@ export class VoiceStateCache {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
get stats() {
|
||||
return {
|
||||
humanUsers: this.userLocations.size,
|
||||
|
||||
@@ -12,7 +12,6 @@ import { Utils } from "./Utils.mjs";
|
||||
import { PROVIDERS } from "./constants/providers.mjs";
|
||||
import { logger } from "./constants/Logger.mjs";
|
||||
|
||||
|
||||
const nl = workerData?.data?.nodelink ?? {};
|
||||
const NL_HOST = nl.host ?? "localhost";
|
||||
const NL_PORT = nl.port ?? 3000;
|
||||
@@ -46,7 +45,6 @@ function sanitizeError(msg) {
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a GET request to NodeLink and return the parsed JSON body.
|
||||
* @param {string} path - API path (e.g. "/v4/loadtracks?identifier=…")
|
||||
@@ -97,7 +95,6 @@ async function loadTracks(identifier, nlGetFn = nlGet) {
|
||||
return nlGetFn(`/v4/loadtracks?identifier=${encodeURIComponent(identifier)}`);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a NodeLink track object to the internal video format.
|
||||
* @param {object} track
|
||||
@@ -142,10 +139,8 @@ function tokenizeMatchText(value) {
|
||||
return normalizeMatchText(value).split(" ").filter(Boolean);
|
||||
}
|
||||
|
||||
|
||||
const TYPE_MODIFIERS = ["track","playlist","album","artist","channel","user"];
|
||||
|
||||
|
||||
class YTUtils extends EventEmitter {
|
||||
constructor() { super(); }
|
||||
|
||||
@@ -451,7 +446,6 @@ class YTUtils extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const jobId = workerData?.jobId;
|
||||
const data = workerData?.data;
|
||||
|
||||
|
||||
Reference in new issue
Block a user