diff --git a/commands/movesong.js b/commands/movesong.js new file mode 100644 index 0000000..fe61c21 --- /dev/null +++ b/commands/movesong.js @@ -0,0 +1,53 @@ +// Copyright 2020 Emily J. / mudkipscience and contributors. Subject to the AGPLv3 license. + +exports.conf = { + enabled: true, + guildOnly: true, + aliases: [], + permLevel: 'User', + requiredPerms: [], + cooldown: 2000 +} + +exports.help = { + name: 'movesong', + category: 'Music', + description: 'Moves a song to a new position in the queue.', + usage: 'movesong [current position] [new position]', + parameters: '[current position] - The current position of the song you want to move' +} + +const { getGuild } = require('../utils/music') +module.exports.run = (client, message, args, level) => { + const queue = getGuild(message.guild.id).queue + const oldPosition = +args[0] + const newPosition = +args[1] + const songName = queue[oldPosition].video.title + + if (queue.length < 3) { + return message.channel.send('<:error:466995152976871434> Not enough songs are in the queue for this command to work!') + } + + if (!args[0]) { + return message.channel.send(`<:error:466995152976871434> You didn't tell me what song to move! Usage: \`${client.commands.get('removesong').help.usage}\``) + } + + if (!args[1]) { + return message.channel.send(`<:error:466995152976871434> You didn't tell me what position in the queue you want to move this song to! Usage: \`${client.commands.get('removesong').help.usage}\``) + } + + if (isNaN(oldPosition) === true || isNaN(newPosition) === true) { + return message.channel.send('That isn\'t a number! You need to tell me the songs position in the queue (1, 2, etc.)') + } + + if (newPosition >= queue.length) { + var k = newPosition - queue.length + 1 + while (k--) { + queue.push(undefined) + } + } + + queue.splice(newPosition, 0, queue.splice(oldPosition, 1)[0]) + + message.channel.send(`Moved **${songName}** from position \`${oldPosition}\` to \`${newPosition}\``) +} diff --git a/commands/shuffle.js b/commands/shuffle.js index 368586d..a574933 100644 --- a/commands/shuffle.js +++ b/commands/shuffle.js @@ -10,11 +10,32 @@ exports.conf = { } exports.help = { - name: 'removesong', + name: 'shuffle', category: 'Music', - description: 'Removes a song from the queue.', - usage: 'removesong [position]', - parameters: '[position] - The position of the song you want to remove' + description: 'Mixes up the songs in the queue', + usage: 'shuffle', + parameters: '' } -const { getGuild } = require('../utils/music') \ No newline at end of file +const { getGuild } = require('../utils/music') +module.exports.run = (client, message, args, level) => { + var queue = getGuild(message.guild.id).queue + + if (queue.length < 3) { + return message.channel.send('Not enough songs are in the queue for this command to work!') + } + + let j, x, i + + for (i = queue.length - 1; i > 0; i--) { + if (i > 1) { + console.log(i) + j = Math.floor(Math.random() * (i + 1)) + x = queue[i] + queue[i] = queue[j] + queue[j] = x + } + } + + message.channel.send('Queue shuffled!') +} diff --git a/utils/music.js b/utils/music.js index 9b1244b..c36c5d0 100644 --- a/utils/music.js +++ b/utils/music.js @@ -162,7 +162,7 @@ exports.play = async function (client, message, query, ignoreQueue) { guild.queue.push({ video: video, requestedBy: message.author }) } - // Figure out if the bot should add it to queue or play it right now + // Figure out if the bot should add it to queue or play it right now if (guild.playing) { message.reply('added **' + video.title + '** to the queue') } else {