From 6d5d4765288dbcd20cbef89f0b428fb37b5091e8 Mon Sep 17 00:00:00 2001 From: mudkipscience Date: Wed, 22 Apr 2020 14:50:00 +1000 Subject: [PATCH] music stuff, added reload --- commands/movesong.js | 34 ++++++++++++++++++++++++---------- commands/reload.js | 32 ++++++++++++++++++++++++++++++++ commands/shuffle.js | 15 +++++++-------- utils/music.js | 1 - 4 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 commands/reload.js diff --git a/commands/movesong.js b/commands/movesong.js index fe61c21..363e900 100644 --- a/commands/movesong.js +++ b/commands/movesong.js @@ -20,31 +20,45 @@ exports.help = { 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}\``) + return client.userError(message, exports, 'Missing argument, the `current position` argument is required!') } 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}\``) + return client.userError(message, exports, 'Missing argument, the `new position` argument is required!') } - if (isNaN(oldPosition) === true || isNaN(newPosition) === true) { + const oldPosition = +args[0] + const newPosition = +args[1] + const songName = queue[oldPosition].video.title + + if (isNaN(oldPosition) === 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 (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 (oldPosition < 1) { + return message.channel.send('This number is too low!') + } + + if (newPosition < 1) { + return message.channel.send('This number is too low!') + } + + if (oldPosition >= queue.length) { + return message.channel.send('This number is too high!') + } + if (newPosition >= queue.length) { - var k = newPosition - queue.length + 1 - while (k--) { - queue.push(undefined) - } + return message.channel.send('This number is too high!') } queue.splice(newPosition, 0, queue.splice(oldPosition, 1)[0]) diff --git a/commands/reload.js b/commands/reload.js new file mode 100644 index 0000000..3de7af1 --- /dev/null +++ b/commands/reload.js @@ -0,0 +1,32 @@ +exports.conf = { + enabled: true, + guildOnly: false, + aliases: [], + permLevel: 'Developer', + requiredPerms: [], + cooldown: 2000 +} + +exports.help = { + name: 'reload', + category: 'Developer', + description: 'Reloads a command without having to restart the whole bot.', + usage: 'reload [command]', + parameters: '[command] - command you want to reload' +} + +exports.run = async (client, message, args) => { // eslint-disable-line no-unused-vars + if (!args || args.length < 1) { + return message.channel.send( + `<:error:466995152976871434> You must provide a command to reload! Usage: \`${client.commands.get('reload').help.usage}\`` + ) + } + + let response = await client.unloadCommand(args[0]) + if (response) return message.channel.send(`<:error:466995152976871434> Error unloading: ${response}`) + + response = client.loadCommand(args[0]) + if (response) return message.channel.send(`<:error:466995152976871434> Error loading: ${response}`) + + message.channel.send(`<:success:466995111885144095> \`${args[0]}\` has been reloaded!`) +} diff --git a/commands/shuffle.js b/commands/shuffle.js index a574933..18edaca 100644 --- a/commands/shuffle.js +++ b/commands/shuffle.js @@ -27,14 +27,13 @@ module.exports.run = (client, message, args, level) => { 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 - } + // Make it so it shuffles all elements EXCEPT [0] + + for (i = queue.length - 1; i > 1; 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 c36c5d0..d5747d4 100644 --- a/utils/music.js +++ b/utils/music.js @@ -169,7 +169,6 @@ exports.play = async function (client, message, query, ignoreQueue) { guild.playing = true guild.voiceChannel = vc - console.log(vc) const connection = await vc.join()