summaryrefslogtreecommitdiff
path: root/commands/voice/shuffle.js
diff options
context:
space:
mode:
Diffstat (limited to 'commands/voice/shuffle.js')
-rw-r--r--commands/voice/shuffle.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/commands/voice/shuffle.js b/commands/voice/shuffle.js
new file mode 100644
index 0000000..158fa5c
--- /dev/null
+++ b/commands/voice/shuffle.js
@@ -0,0 +1,49 @@
+const { Command } = require('discord.js-commando');
+const { MessageEmbed } = require('discord.js');
+
+module.exports = class ShuffleVoice extends Command {
+ constructor(client) {
+ super(client, {
+ name: 'shuffle',
+ group: 'voice',
+ memberName: 'shuffle',
+ description: 'shuffle the queue',
+ guildOnly: true
+ });
+ }
+ run(msg) {
+ var voiceChannel = msg.member.voice.channel;
+ if (!voiceChannel) return msg.reply('join channel and try again k');
+
+ if (
+ typeof msg.guild.musicData.songDispatcher == 'undefined' ||
+ msg.guild.musicData.songDispatcher == null
+ ) {
+ return msg.reply('there is no song playing right now');
+ }
+
+ if (msg.guild.musicData.queue.length < 1)
+ return msg.say('There are no songs in queue');
+
+ shuffleQueue(msg.guild.musicData.queue);
+
+ const titleArray = [];
+ msg.guild.musicData.queue.map(obj => {
+ titleArray.push(obj.title);
+ });
+ var queueEmbed = new MessageEmbed()
+ .setColor(0xF97DAE)
+ .setTitle('new music q');
+ for (let i = 0; i < titleArray.length; i++) {
+ queueEmbed.addField(`${i + 1}:`, `${titleArray[i]}`);
+ }
+ return msg.say(queueEmbed);
+ }
+};
+
+function shuffleQueue(queue) {
+ for (let i = queue.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1));
+ [queue[i], queue[j]] = [queue[j], queue[i]];
+ }
+} \ No newline at end of file