diff options
| author | 8cy <[email protected]> | 2020-04-10 10:16:53 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-10 10:16:53 -0700 |
| commit | 4b308538961facb87d73fafeab7fab5927562eff (patch) | |
| tree | 8eaf88c074c379d76e7932e6fc3f32c05adb70ca /commands/voice/shuffle.js | |
| parent | rework reboot, work on itemshop, v1.5.2 (diff) | |
| download | s5nical-4b308538961facb87d73fafeab7fab5927562eff.tar.xz s5nical-4b308538961facb87d73fafeab7fab5927562eff.zip | |
port to commando/ v12, 2.0.0
ported everything over to v12 and then commando in the span of 2 days no sleep lol. also now using typescript standard for cool 8)
Diffstat (limited to 'commands/voice/shuffle.js')
| -rw-r--r-- | commands/voice/shuffle.js | 49 |
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 |