From 2ee4a0a86daaed7dd790469513e8608a0bbd44c4 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Thu, 21 May 2026 18:44:31 +0300 Subject: [PATCH] fixing --- commands/trackopt.mjs | 33 ++++----------------------------- src/Player.mjs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/commands/trackopt.mjs b/commands/trackopt.mjs index 3ffca88..d172533 100644 --- a/commands/trackopt.mjs +++ b/commands/trackopt.mjs @@ -1,6 +1,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; +import { logger } from "../src/constants/Logger.mjs"; const DEFAULT_ALIAS = "default"; @@ -208,35 +209,9 @@ export async function run(msg, data) { } try { - if (result.startMs > 0) { - await p.seekToPosition(result.startMs); - } - - p._clearTrackEndTimer(); - p._activeTrackOpt = null; - - if (result.endMs > 0) { - const elapsedMs = Date.now() - p.startedPlaying; - const remainingMs = result.endMs - elapsedMs; - if (remainingMs > 0) { - const match = result; - p._activeTrackOpt = match; - p._trackEndTimer = setTimeout(() => { - if (p._destroyed || p.leaving || !p._activeTrackOpt) return; - logger.player(`[Player] TrackOptions: end time reached (${match.endMs}ms), skipping track`); - p._activeTrackOpt = null; - p._trackEndTimer = null; - p._trackEndRemainingMs = null; - p._skipping = true; - p._stopMediaPlayer().then(() => { - p._doPlayNext(); - }).catch(() => { - p._doPlayNext(); - }); - }, remainingMs); - } - } else { - p._activeTrackOpt = result; + const applied = p.applyTrackOption(result); + if (!applied) { + return msg.reply({ embeds: [new EmbedBuilder().setColor("#ff0000").setDescription("❌ Failed to apply alias.")] }); } const aliasLabel = safeAlias === DEFAULT_ALIAS ? "default" : safeAlias; diff --git a/src/Player.mjs b/src/Player.mjs index 2eaa8e4..146b31d 100644 --- a/src/Player.mjs +++ b/src/Player.mjs @@ -2468,6 +2468,44 @@ export default class Player extends EventEmitter { } } + applyTrackOption(match) { + if (!match || !this.connection || this._paused) return false; + + if (match.startMs > 0) { + this.seekToPosition(match.startMs).catch((e) => { + logger.warn("[Player] TrackOptions apply-seek error:", e.message); + }); + } + + this._clearTrackEndTimer(); + this._activeTrackOpt = null; + + if (match.endMs > 0) { + const elapsedMs = Date.now() - this.startedPlaying; + const remainingMs = match.endMs - elapsedMs; + if (remainingMs > 0) { + this._activeTrackOpt = match; + this._trackEndTimer = setTimeout(() => { + if (this._destroyed || this.leaving || !this._activeTrackOpt) return; + logger.player(`[Player] TrackOptions: end time reached (${match.endMs}ms), skipping track`); + this._activeTrackOpt = null; + this._trackEndTimer = null; + this._trackEndRemainingMs = null; + this._skipping = true; + this._stopMediaPlayer().then(() => { + this._doPlayNext(); + }).catch(() => { + this._doPlayNext(); + }); + }, remainingMs); + } + } else { + this._activeTrackOpt = match; + } + + return true; + } + async lyrics() { const current = this.queue.getCurrent(); if (!current) return null;