From 841042ec4d024a00b148f16f6e7091edd20a4339 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Fri, 14 Aug 2026 02:07:19 +0300 Subject: [PATCH] testing --- commands/skip.mjs | 2 +- index.mjs | 39 +++++++++++++++++++++++++++++++++ src/CommandHandler.mjs | 11 +++++----- src/Player.mjs | 34 ++++++++++++++++++---------- src/constants/FluxerRevoice.mjs | 10 ++++++--- 5 files changed, 75 insertions(+), 21 deletions(-) diff --git a/commands/skip.mjs b/commands/skip.mjs index 7901a4f..90393e4 100644 --- a/commands/skip.mjs +++ b/commands/skip.mjs @@ -27,7 +27,7 @@ export async function run(message) { const skippedLink = current ? (current.spotifyUrl || current.url || "") : ""; const err = p.skip(); - if (err) { + if (!p.connection || !current) { const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(err); return message.reply({ embeds: [embed] }); } diff --git a/index.mjs b/index.mjs index 3795b67..b18b51b 100644 --- a/index.mjs +++ b/index.mjs @@ -89,6 +89,32 @@ export class Remix { const presenceContents = config.presenceContents ?? []; const presenceInterval = config.presenceInterval ?? 30_000; + const buildRuntimePresence = (entry) => { + const isObj = typeof entry === "object" && entry !== null; + const customStatus = {}; + if (isObj) { + if (entry.text) customStatus.text = entry.text; + if (entry.emoji_name) customStatus.emojiName = entry.emoji_name; + if (entry.emoji_id) customStatus.emojiId = entry.emoji_id; + } else { + customStatus.text = String(entry); + } + + const update = { status: "online", afk: false, customStatus }; + + if (isObj && entry.activity) { + update.activities = [{ + name: entry.activity.name ?? "music", + type: entry.activity.type ?? 0, + url: entry.activity.url ?? undefined, + }]; + } + + return update; + }; + let presenceRotationIndex = presenceContents.length > 1 ? 1 : 0; + let presenceRotationStarted = false; + const timers = config.timers ?? {}; this.T = { aloneCheckInterval: timers.aloneCheckInterval ?? 60_000, @@ -295,6 +321,19 @@ export class Remix { } this.gatewayHandler.onReady(); + + if (!presenceRotationStarted && presenceContents.length > 1) { + presenceRotationStarted = true; + setInterval(() => { + try { + const entry = presenceContents[presenceRotationIndex % presenceContents.length]; + client.user?.setPresence(buildRuntimePresence(entry)); + presenceRotationIndex = (presenceRotationIndex + 1) % presenceContents.length; + } catch (e) { + logger.warn("[Presence] Rotation update failed:", e?.message); + } + }, presenceInterval).unref?.(); + } } catch (e) { logger.error("[Ready] Fatal error in Ready handler:", e); } diff --git a/src/CommandHandler.mjs b/src/CommandHandler.mjs index efb3a3c..1c94b38 100644 --- a/src/CommandHandler.mjs +++ b/src/CommandHandler.mjs @@ -512,6 +512,12 @@ export class CommandHandler extends EventEmitter { return; } + const guildId = msg.channel?.channel?.guildId ?? msg.message?.guildId; + const prefix = this.getPrefix(guildId); + const ping = `<@${this.client.user?.id}>`; + const pingBang = `<@!${this.client.user?.id}>`; + if (!(msg.content.startsWith(prefix) || msg.content.startsWith(ping) || msg.content.startsWith(pingBang))) return; + const userId = msg.message?.author?.id ?? msg.author?.id; if (userId && !this.owners.includes(userId)) { const now = Date.now(); @@ -525,11 +531,6 @@ export class CommandHandler extends EventEmitter { } } } - const guildId = msg.channel?.channel?.guildId ?? msg.message?.guildId; - const prefix = this.getPrefix(guildId); - const ping = `<@${this.client.user?.id}>`; - const pingBang = `<@!${this.client.user?.id}>`; - if (!(msg.content.startsWith(prefix) || msg.content.startsWith(ping) || msg.content.startsWith(pingBang))) return; const len = msg.content.startsWith(prefix) ? prefix.length : (msg.content.startsWith(pingBang) ? pingBang.length : ping.length); const args = msg.content.slice(len).replace(/\u00A0/gi, " ").trim().split(" ").map(e => e.trim()); diff --git a/src/Player.mjs b/src/Player.mjs index f80cbef..efe0336 100644 --- a/src/Player.mjs +++ b/src/Player.mjs @@ -924,20 +924,23 @@ export default class Player extends EventEmitter { const streamStartedAt = Date.now(); - await new Promise((resolve) => { - const safetyTimer = setTimeout(() => { + let safetyTimer; + let onFinish, onError; + + const playbackSettled = new Promise((resolve) => { + safetyTimer = setTimeout(() => { logger.warn(`[Player] Stream safety timeout hit (${Math.round(safetyMs / 1000)}s) — advancing queue`); cleanup(); resolve(); }, safetyMs); - const onFinish = () => { + onFinish = () => { clearTimeout(safetyTimer); cleanup(); resolve(); }; - const onError = (e) => { + onError = (e) => { clearTimeout(safetyTimer); cleanup(); if (isIgnorableMediaStateError(e)) { @@ -961,6 +964,19 @@ export default class Player extends EventEmitter { this._mediaPlayer.once("finish", onFinish); this._mediaPlayer.once("error", onError); }); + + // Race the buffered-HTTP-stream error watcher against normal playback + // completion so a real network/stream failure (e.g. connection reset + // mid-download) is reported and advances the queue with an error + // message, instead of becoming an orphaned unhandled rejection while + // playback hangs waiting on events that will never fire. + try { + await Promise.race([streamError, playbackSettled]); + } finally { + clearTimeout(safetyTimer); + this._mediaPlayer?.off("finish", onFinish); + this._mediaPlayer?.off("error", onError); + } } catch (e) { if (audioStream && !audioStream.destroyed) { try { audioStream.destroy(); } catch (e2) { logger.warn("[Player] Error destroying stream:", e2?.message); } @@ -1330,12 +1346,7 @@ export default class Player extends EventEmitter { this._clearTrackEndTimer(); this._activeTrackOpt = null; - if (this._mediaPlayer) { - if (typeof this._mediaPlayer.destroy === "function") { - try { this._mediaPlayer.destroy(); } catch(e) { logger.warn("[Player] MediaPlayer destroy error on leave:", e?.message); } - } - this._mediaPlayer = null; - } + await this._stopMediaPlayer(); const channelId = this._channelId; if (this._revoice && channelId && typeof this._revoice.markIntentionalDisconnect === "function") { @@ -1405,7 +1416,6 @@ export default class Player extends EventEmitter { const connToDestroy = this.connection; this.connection = null; - this._mediaPlayer = null; if (this._revoice && this._channelId) { try { this._revoice.markIntentionalDisconnect(this._channelId); } catch(e) { logger.warn("[Player] Mark intentional disconnect on destroy:", e?.message); } } @@ -2290,7 +2300,7 @@ export default class Player extends EventEmitter { } else { try { if (this._moonlink?.manager) { - const result = await this._moonlink.search(`ytsearch:${songData.title}`); + const result = await this._moonlink.search(songData.title, "youtube"); const track = result?.tracks?.[0]; if (track?.encoded) { const nlBase = `http://${this._nl.host}:${this._nl.port}`; diff --git a/src/constants/FluxerRevoice.mjs b/src/constants/FluxerRevoice.mjs index 42edce5..4ff1f13 100644 --- a/src/constants/FluxerRevoice.mjs +++ b/src/constants/FluxerRevoice.mjs @@ -101,13 +101,17 @@ function installLiveKitLogFilter() { const origLog = console.log; const origInfo = console.info; - const filtered = function (...args) { + const filteredLog = function (...args) { if (isLiveKitLogMessage(...args)) return; return origLog.apply(console, args); }; + const filteredInfo = function (...args) { + if (isLiveKitLogMessage(...args)) return; + return origInfo.apply(console, args); + }; - console.log = filtered; - console.info = filtered; + console.log = filteredLog; + console.info = filteredInfo; } /**