From 59084b07cb553788d045473db0f1bfa2bcf2b7a5 Mon Sep 17 00:00:00 2001 From: mudkipscience Date: Thu, 30 Apr 2020 14:44:23 +1000 Subject: [PATCH] Add new music commands --- src/commands/fixmusic.js | 30 +++++++++++++++++++++ src/commands/movehere.js | 33 +++++++++++++++++++++++ src/commands/movesong.js | 56 +++++++++++++++++++++++++++++++++++++++ src/commands/playnext.js | 23 ++++++++++++++++ src/commands/shuffle.js | 34 ++++++++++++++++++++++++ src/commands/songinfo.js | 42 +++++++++++++++++++++++++++++ src/commands/volume.js | 57 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 275 insertions(+) create mode 100644 src/commands/fixmusic.js create mode 100644 src/commands/movehere.js create mode 100644 src/commands/movesong.js create mode 100644 src/commands/playnext.js create mode 100644 src/commands/shuffle.js create mode 100644 src/commands/songinfo.js create mode 100644 src/commands/volume.js diff --git a/src/commands/fixmusic.js b/src/commands/fixmusic.js new file mode 100644 index 0000000..387aa9f --- /dev/null +++ b/src/commands/fixmusic.js @@ -0,0 +1,30 @@ +const { getGuild } = require('../modules/music') +module.exports.run = async (client, message, args, level) =>{ + guild = getGuild(message.guild.id) + + guild.queue = [] + guild.playing = false + guild.paused = false + guild.skippers = [] + + if (guild.dispatcher) { + guild.dispatcher.end('silent') + } + + message.channel.send('<:success:466995111885144095> Music has been fixed (hopefully)') +} + +exports.conf = { + enabled: true, + guildOnly: true, + aliases: [], + permLevel: "Moderator", + requiredPerms: [] +}; + +exports.help = { + name: "fixmusic", + category: "Music", + description: 'Fixes music if it breaks.', + usage: 'fixmusic', +}; diff --git a/src/commands/movehere.js b/src/commands/movehere.js new file mode 100644 index 0000000..61ea0ee --- /dev/null +++ b/src/commands/movehere.js @@ -0,0 +1,33 @@ +const { getGuild } = require('../modules/music') +const Discord = require("discord.js") + +module.exports.run = async (client, message, args, level) =>{ + const guild = getGuild(message.guild.id) + + if (!guild.playing) { + return message.channel.send('<:error:466995152976871434> Nothing is playing.') + } + + if (guild.channel.id === message.channel.id) { + return message.channel.send('<:error:466995152976871434> Music messages are already being sent to this channel.') + } + + guild.channel = message.channel + + message.channel.send('<:success:466995111885144095> Music messages will now be sent to this channel.') +} + +exports.conf = { + enabled: true, + guildOnly: true, + aliases: [], + permLevel: "Moderator", + requiredPerms: [] +}; + +exports.help = { + name: 'movehere', + category: 'Music', + description: 'Moves music related messages to the channel the this command is ran in.', + usage: 'movehere', +}; diff --git a/src/commands/movesong.js b/src/commands/movesong.js new file mode 100644 index 0000000..83c6a7c --- /dev/null +++ b/src/commands/movesong.js @@ -0,0 +1,56 @@ +const { getGuild } = require('../modules/music') +exports.run = async (client, message, args) => { + const queue = getGuild(message.guild.id).queue + + 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 client.userError(message, exports, 'Missing argument, the `current position` argument is required!') + } + + if (!args[1]) { + return client.userError(message, exports, 'Missing argument, the `new position` argument is required!') + } + + const oldPosition = +args[0] + const newPosition = +args[1] + + if (isNaN(oldPosition) === true) { + return message.channel.send('<:error:466995152976871434> 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('<:error:466995152976871434> That isn\'t a number! You need to tell me the songs position in the queue (1, 2, etc.)') + } + + if (oldPosition < 1 || oldPosition >= queue.length) { + return message.channel.send('<:error:466995152976871434> Old position is not a valid song ID.') + } + + if (newPosition < 1 || newPosition >= queue.length) { + return message.channel.send('<:error:466995152976871434> New position is not a valid song ID.') + } + + const songName = queue[oldPosition].video.title + + queue.splice(newPosition, 0, queue.splice(oldPosition, 1)[0]) + + message.channel.send(`<:success:466995111885144095> Moved **${songName}** from position \`${oldPosition}\` to \`${newPosition}\``) +} + +exports.conf = { + enabled: true, + guildOnly: true, + aliases: [], + permLevel: "Moderator", + requiredPerms: [] +} + +exports.help = { + name: 'movesong', + category: 'Music', + description: 'Moves a song to a new position in the queue.', + usage: 'movesong [current position] [new position]' +} \ No newline at end of file diff --git a/src/commands/playnext.js b/src/commands/playnext.js new file mode 100644 index 0000000..6314283 --- /dev/null +++ b/src/commands/playnext.js @@ -0,0 +1,23 @@ +const { play } = require('../modules/music') +exports.run = async (client, message, args) => { + if (!args[0]) { + return message.channel.send(`<:error:466995152976871434> You didn't give me a song name or YouTube URL! Usage: \`${client.commands.get('play').help.usage}\``) + } + + await play(client, message, args.join(' '), true) +} + +exports.conf = { + enabled: true, + guildOnly: true, + aliases: [], + permLevel: "Moderator", + requiredPerms: [] +} + +exports.help = { + name: 'playnext', + category: 'Music', + description: 'Similar to play, but adds it to the start of the queue instead of the end.', + usage: 'playnext [song]' +} \ No newline at end of file diff --git a/src/commands/shuffle.js b/src/commands/shuffle.js new file mode 100644 index 0000000..23270e5 --- /dev/null +++ b/src/commands/shuffle.js @@ -0,0 +1,34 @@ +const { getGuild } = require('../modules/music') +exports.run = async (client, message) => { + var queue = getGuild(message.guild.id).queue + + if (queue.length < 4) { + return message.channel.send('<:error:466995152976871434> There aren\'t enough songs are in the queue for this command to work!') + } + + const max = queue.length - 1 + const min = 1 + for (let i = max; i >= min; i--) { + const randomIndex = Math.floor(Math.random() * (max - min + 1)) + min + const itemAtIndex = queue[randomIndex] + queue[randomIndex] = queue[i] + queue[i] = itemAtIndex + } + + message.channel.send('<:success:466995111885144095> Queue shuffled!') +} + +exports.conf = { + enabled: true, + guildOnly: true, + aliases: [], + permLevel: "Moderator", + requiredPerms: [] +} + +exports.help = { + name: 'shuffle', + category: 'Music', + description: 'Mixes up the songs in the queue', + usage: 'shuffle' +} \ No newline at end of file diff --git a/src/commands/songinfo.js b/src/commands/songinfo.js new file mode 100644 index 0000000..cd7bb0b --- /dev/null +++ b/src/commands/songinfo.js @@ -0,0 +1,42 @@ +const { getGuild, createTimestamp } = require('../modules/music') +const { MessageEmbed } = require('discord.js') +exports.run = async (client, message, args) => { + const guild = getGuild(message.guild.id) + + if (guild.queue.length < 1) { + return message.channel.send(client.config.emojis.error + ' Nothing is in the queue!') + } + + const songID = +args[0] + + if (isNaN(songID) === true) { + return message.channel.send('<:error:466995152976871434> That isn\'t a number! You need to tell me the songs position in the queue (1, 2, etc.)') + } + + const s = guild.queue[songID] + + const embed = new MessageEmbed() + embed.setThumbnail(s.video.videoThumbnails[1].url) + embed.setColor(client.embedColour(message)) + embed.setDescription(`**[${s.video.title}](https://www.youtube.com/watch?v=${s.video.videoId})**`) + embed.addField('Channel:', s.video.author, true) + embed.addField('Length:', '`[' + createTimestamp(s.video.lengthSeconds) + ']`', true) + embed.setFooter('Requested by ' + s.requestedBy.tag, s.requestedBy.avatarURL({ format: 'png', dynamic: true, size: 2048 })) + + message.channel.send(embed) +} + +exports.conf = { + enabled: true, + guildOnly: true, + aliases: [], + permLevel: "User", + requiredPerms: [] +} + +exports.help = { + name: "songinfo", + category: "Music", + description: "Sends you information about a song in the queue. Song ID is the song's position in the queue.", + usage: "songinfo [songID]" +} \ No newline at end of file diff --git a/src/commands/volume.js b/src/commands/volume.js new file mode 100644 index 0000000..6711947 --- /dev/null +++ b/src/commands/volume.js @@ -0,0 +1,57 @@ +const { getGuild, setVolume } = require('../modules/music') +exports.run = async (client, message, args) => { + if (!args[0]) { + return message.channel.send(`<:error:466995152976871434> No input! Usage: \`${client.commands.get('volume').help.usage}\``) + } + + const guild = getGuild(message.guild.id) + + if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) { + return message.channel.send( + '<:error:466995152976871434> Nothing is playing.' + ) + } + + let userVolume = args[0] + + if (userVolume.includes('%')) { + userVolume = userVolume.replace('%', '') + } + + userVolume = +userVolume + + if (isNaN(userVolume) === true) { + return message.channel.send('<:error:466995152976871434> Input must be a number!') + } + + if (userVolume > 100 || userVolume < 1) { + return message.channel.send('<:error:466995152976871434> Invalid input, input must be between 1-100') + } + + if (userVolume) { + userVolume = Number(userVolume) + + userVolume = userVolume / 100 + + if (userVolume <= 1) { + setVolume(message.guild, userVolume) + + message.channel.send('<:success:466995111885144095> Set volume to ' + userVolume * 100 + '%') + } + } +} + +exports.conf = { + enabled: true, + guildOnly: true, + aliases: [], + permLevel: "Moderator", + requiredPerms: [] +} + +exports.help = { + name: 'volume', + category: 'Music', + description: 'Sets volume of currently playing music. (100% = 25% of the actual volume)', + usage: 'volume [volume]' +} \ No newline at end of file