fuga
Version:
A comprehensive, feature-rich, and modern Lavalink v4 client for Node.js
47 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Queue = void 0;
/**
* A feature-rich queue for managing tracks.
*/
class Queue extends Array {
/** The first track in the queue. */
get first() {
return this[0];
}
/** The total size of the queue. */
get size() {
return this.length;
}
/** The total duration of the queue in milliseconds. */
get duration() {
return this.reduce((acc, track) => acc + track.info.length, 0);
}
/**
* Adds a track to the end of the queue.
* @param track The track or tracks to add.
*/
add(track) {
if (Array.isArray(track))
this.push(...track);
else
this.push(track);
}
/** Removes the first track from the queue and returns it. */
removeFirst() {
return super.shift();
}
/** Clears the entire queue. */
clear() {
this.length = 0;
}
/** Shuffles the tracks in the queue. */
shuffle() {
for (let i = this.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[this[i], this[j]] = [this[j], this[i]];
}
}
}
exports.Queue = Queue;
//# sourceMappingURL=Queue.js.map