mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
fix(player, voice): resolve queue loop recycling, 24/7 backoff cooldown, and command routing (#10, #11)
This commit is contained in:
1 parent
cf278ed68c
commit
fa5bc68f16
3 files changed
+32
-57
No files matched your search
@@ -44,7 +44,6 @@ const PlaybackMixin = {
|
|||||||
|
|
||||||
if (!this._paused) {
|
if (!this._paused) {
|
||||||
this._lastPlayedTrack = this.queue.getCurrent() ?? songData;
|
this._lastPlayedTrack = this.queue.getCurrent() ?? songData;
|
||||||
if (!this.queue.songLoop) this.queue.current = null;
|
|
||||||
this._playingNext = false;
|
this._playingNext = false;
|
||||||
this.playNext().catch(e => logger.error("[Player] auto-advance playNext error:", e.message));
|
this.playNext().catch(e => logger.error("[Player] auto-advance playNext error:", e.message));
|
||||||
}
|
}
|
||||||
@@ -99,13 +98,14 @@ const PlaybackMixin = {
|
|||||||
* generation counter ensures an older run's cleanup never clears the
|
* generation counter ensures an older run's cleanup never clears the
|
||||||
* in-flight flag of a newer run (which previously allowed double-advances).
|
* in-flight flag of a newer run (which previously allowed double-advances).
|
||||||
* @this {import('./Player.mjs').Player}
|
* @this {import('./Player.mjs').Player}
|
||||||
|
* @param {object} [opts] - Advancement options forwarded to Queue.next.
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async playNext() {
|
async playNext(opts = {}) {
|
||||||
if (this._playingNext) return;
|
if (this._playingNext) return;
|
||||||
this._playingNext = true;
|
this._playingNext = true;
|
||||||
const generation = (this._playNextGeneration = (this._playNextGeneration ?? 0) + 1);
|
const generation = (this._playNextGeneration = (this._playNextGeneration ?? 0) + 1);
|
||||||
try { await this._doPlayNext(); }
|
try { await this._doPlayNext(opts); }
|
||||||
finally { if (generation === this._playNextGeneration) this._playingNext = false; }
|
finally { if (generation === this._playNextGeneration) this._playingNext = false; }
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -114,13 +114,14 @@ const PlaybackMixin = {
|
|||||||
* track options, announces, starts playback via the bridge, arms the
|
* track options, announces, starts playback via the bridge, arms the
|
||||||
* track-end timer, and handles the queue-end path.
|
* track-end timer, and handles the queue-end path.
|
||||||
* @this {import('./Player.mjs').Player}
|
* @this {import('./Player.mjs').Player}
|
||||||
|
* @param {object} [opts] - Advancement options forwarded to Queue.next.
|
||||||
*/
|
*/
|
||||||
async _doPlayNext() {
|
async _doPlayNext(opts = {}) {
|
||||||
this._bridgeStop();
|
this._bridgeStop();
|
||||||
|
|
||||||
const currentBeforeNext = this.queue.getCurrent();
|
const currentBeforeNext = this.queue.getCurrent();
|
||||||
if (currentBeforeNext) this._lastPlayedTrack = currentBeforeNext;
|
if (currentBeforeNext) this._lastPlayedTrack = currentBeforeNext;
|
||||||
const songData = this.queue.next();
|
const songData = this.queue.next(opts);
|
||||||
if (!songData) {
|
if (!songData) {
|
||||||
this.emit("stopplay");
|
this.emit("stopplay");
|
||||||
this.emit("queueEnd");
|
this.emit("queueEnd");
|
||||||
@@ -352,24 +353,13 @@ const PlaybackMixin = {
|
|||||||
this._playingNext = false;
|
this._playingNext = false;
|
||||||
this._lastPlayedTrack = this.queue.getCurrent() ?? this._lastPlayedTrack;
|
this._lastPlayedTrack = this.queue.getCurrent() ?? this._lastPlayedTrack;
|
||||||
this.emit("trackSkip", this._lastPlayedTrack);
|
this.emit("trackSkip", this._lastPlayedTrack);
|
||||||
if (!this.queue.isEmpty() && !this.leaving) {
|
if (!this.leaving) {
|
||||||
this.playNext().catch(e => logger.error("[Player] TrackEnd playNext error:", e.message));
|
this.playNext()
|
||||||
|
.catch(e => logger.error("[Player] TrackEnd playNext error:", e.message))
|
||||||
|
.finally(() => { this._skipping = false; });
|
||||||
} else {
|
} else {
|
||||||
this.queue.current = null;
|
|
||||||
if (!this._wasRadio && !this._queueEndedSent) {
|
|
||||||
this._queueEndedSent = true;
|
|
||||||
this.emit("queueEnd");
|
|
||||||
if (!this._autoplay) {
|
|
||||||
const prefix = this._getPrefix?.(this._guildId) ?? "%";
|
|
||||||
this.emit("message", { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(this._t("responses._common.queueEnded", { prefix }))], system: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.emit("stopplay");
|
|
||||||
if (!this._is247Enabled()) {
|
|
||||||
this._startInactivityTimer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this._skipping = false;
|
this._skipping = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+17
-34
@@ -799,32 +799,20 @@ class Player extends EventEmitter {
|
|||||||
this._radioAnnounced = false;
|
this._radioAnnounced = false;
|
||||||
this._activeTrackOpt = null;
|
this._activeTrackOpt = null;
|
||||||
this._clearTrackEndTimer();
|
this._clearTrackEndTimer();
|
||||||
this.queue.current = null;
|
|
||||||
|
|
||||||
this._bridgeStop();
|
this._bridgeStop();
|
||||||
|
|
||||||
this.emit("trackSkip", this._lastPlayedTrack);
|
this.emit("trackSkip", this._lastPlayedTrack);
|
||||||
|
|
||||||
if (this.queue.isEmpty() && !this._wasRadio && !this._queueEndedSent) {
|
|
||||||
this._queueEndedSent = true;
|
|
||||||
this.emit("queueEnd");
|
|
||||||
if (!this._autoplay) {
|
|
||||||
const prefix = this._getPrefix?.(this._guildId) ?? "%";
|
|
||||||
this.emit("message", { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(this._t("responses._common.queueEnded", { prefix }))], system: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._playingNext = false;
|
this._playingNext = false;
|
||||||
if (!this.queue.isEmpty() && !this.leaving) {
|
if (!this.leaving) {
|
||||||
this.playNext().catch(e => logger.error("[Player] playNext error:", e.message));
|
this.playNext({ ignoreSongLoop: true })
|
||||||
|
.catch(e => logger.error("[Player] playNext error:", e.message))
|
||||||
|
.finally(() => { this._skipping = false; });
|
||||||
} else {
|
} else {
|
||||||
this.emit("stopplay");
|
this._skipping = false;
|
||||||
if (!this._is247Enabled()) {
|
|
||||||
this._startInactivityTimer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._skipping = false;
|
|
||||||
return ":track_next: Skipped";
|
return ":track_next: Skipped";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -840,34 +828,29 @@ class Player extends EventEmitter {
|
|||||||
if (idx < 0 || idx >= this.queue.size())
|
if (idx < 0 || idx >= this.queue.size())
|
||||||
return `:negative_squared_cross_mark: Position ${position} out of range (queue has ${this.queue.size()} tracks).`;
|
return `:negative_squared_cross_mark: Position ${position} out of range (queue has ${this.queue.size()} tracks).`;
|
||||||
this._lastPlayedTrack = this.queue.getCurrent();
|
this._lastPlayedTrack = this.queue.getCurrent();
|
||||||
this.queue.data.splice(0, idx);
|
const skipped = [this._lastPlayedTrack, ...this.queue.data.splice(0, idx)];
|
||||||
|
if (this.queue.loop) {
|
||||||
|
this.queue.data.push(...skipped);
|
||||||
|
}
|
||||||
this.queue.current = null;
|
this.queue.current = null;
|
||||||
this._skipping = true;
|
this._skipping = true;
|
||||||
|
this._radioAnnounced = false;
|
||||||
|
this._activeTrackOpt = null;
|
||||||
|
this._clearTrackEndTimer();
|
||||||
|
|
||||||
this._bridgeStop();
|
this._bridgeStop();
|
||||||
|
|
||||||
this.emit("trackSkip", this._lastPlayedTrack);
|
this.emit("trackSkip", this._lastPlayedTrack);
|
||||||
|
|
||||||
if (this.queue.isEmpty() && !this._wasRadio && !this._queueEndedSent) {
|
|
||||||
this._queueEndedSent = true;
|
|
||||||
this.emit("queueEnd");
|
|
||||||
if (!this._autoplay) {
|
|
||||||
const prefix = this._getPrefix?.(this._guildId) ?? "%";
|
|
||||||
this.emit("message", { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(this._t("responses._common.queueEnded", { prefix }))], system: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._playingNext = false;
|
this._playingNext = false;
|
||||||
if (!this.queue.isEmpty() && !this.leaving) {
|
if (!this.leaving) {
|
||||||
this.playNext().catch(e => logger.error("[Player] playNext error:", e.message));
|
this.playNext({ ignoreSongLoop: true })
|
||||||
|
.catch(e => logger.error("[Player] playNext error:", e.message))
|
||||||
|
.finally(() => { this._skipping = false; });
|
||||||
} else {
|
} else {
|
||||||
this.emit("stopplay");
|
this._skipping = false;
|
||||||
if (!this._is247Enabled()) {
|
|
||||||
this._startInactivityTimer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._skipping = false;
|
|
||||||
return `:track_next: Skipped to position ${position}`;
|
return `:track_next: Skipped to position ${position}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,12 +40,14 @@ export class Queue extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Advance to the next track in the queue. If songLoop is active, returns
|
* Advance to the next track in the queue. If songLoop is active, returns
|
||||||
* the current track. If queue loop is active, re-appends the current track.
|
* the current track. If queue loop is active, re-appends the current track.
|
||||||
|
* @param {object} [options]
|
||||||
|
* @param {boolean} [options.ignoreSongLoop=false] - Bypass songLoop (used when explicitly skipping).
|
||||||
* @returns {object|null} The next track, or null if the queue is empty.
|
* @returns {object|null} The next track, or null if the queue is empty.
|
||||||
*/
|
*/
|
||||||
next() {
|
next({ ignoreSongLoop = false } = {}) {
|
||||||
const previous = this.current;
|
const previous = this.current;
|
||||||
|
|
||||||
if (this.songLoop && this.current) return this.current;
|
if (!ignoreSongLoop && this.songLoop && this.current) return this.current;
|
||||||
if (this.loop && this.current) this.data.push(this.current);
|
if (this.loop && this.current) this.data.push(this.current);
|
||||||
|
|
||||||
if (this.isEmpty()) {
|
if (this.isEmpty()) {
|
||||||
|
|||||||
Reference in new issue
Block a user