This commit is contained in:
NoLogicAlan committed 2026-05-21 18:44:31 +03:00
1 parent 5ba24bf1df
commit 2ee4a0a86d
2 files changed
+42 -29

No files matched your search

+4 -29
View File
@@ -1,6 +1,7 @@
import { CommandBuilder } from "../src/CommandHandler.mjs"; import { CommandBuilder } from "../src/CommandHandler.mjs";
import { EmbedBuilder } from "@fluxerjs/core"; import { EmbedBuilder } from "@fluxerjs/core";
import { getGlobalColor } from "../src/MessageHandler.mjs"; import { getGlobalColor } from "../src/MessageHandler.mjs";
import { logger } from "../src/constants/Logger.mjs";
const DEFAULT_ALIAS = "default"; const DEFAULT_ALIAS = "default";
@@ -208,35 +209,9 @@ export async function run(msg, data) {
} }
try { try {
if (result.startMs > 0) { const applied = p.applyTrackOption(result);
await p.seekToPosition(result.startMs); if (!applied) {
} return msg.reply({ embeds: [new EmbedBuilder().setColor("#ff0000").setDescription("❌ Failed to apply alias.")] });
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 aliasLabel = safeAlias === DEFAULT_ALIAS ? "default" : safeAlias; const aliasLabel = safeAlias === DEFAULT_ALIAS ? "default" : safeAlias;
+38
View File
@@ -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() { async lyrics() {
const current = this.queue.getCurrent(); const current = this.queue.getCurrent();
if (!current) return null; if (!current) return null;