feat: add shuffle method

This commit is contained in:
Androz2091 2020-04-24 17:14:34 +02:00
parent 61d62d4d5e
commit fd5821e977
2 changed files with 24 additions and 1 deletions

View file

@ -312,6 +312,24 @@ class Player {
}); });
} }
/**
* Shuffles the guild queue.
* @param {string} guildID
* @returns {Promise<Void>}
*/
shuffle(guildID){
return new Promise(async(resolve, reject) => {
// Gets guild queue
let queue = this.queues.find((g) => g.guildID === guildID);
if(!queue) return reject('Not playing');
// Shuffle the queue (except the first song)
let currentSong = queue.songs.shift();
queue.songs = queue.songs.sort(() => Math.random() - 0.5);
queue.songs.unshift(currentSong);
// Resolve
resolve();
});
}
/** /**
* Start playing songs in a guild. * Start playing songs in a guild.
* @ignore * @ignore

View file

@ -6,7 +6,7 @@ class Song {
* @param {Video} video The Youtube video * @param {Video} video The Youtube video
* @param {Queue} queue The queue in which the song is * @param {Queue} queue The queue in which the song is
*/ */
constructor(video, queue) { constructor(video, queue, requestedBy) {
/** /**
* Song name. * Song name.
* @type {string} * @type {string}
@ -47,6 +47,11 @@ class Song {
* @type {Queue} * @type {Queue}
*/ */
this.queue = queue; this.queue = queue;
/**
* The user who requested that song.
* @type {User}
*/
this.requestedBy = requestedBy;
} }
}; };