diff --git a/commands/bass.js b/commands/bass.js index fa28ba39..b353c7a6 100644 --- a/commands/bass.js +++ b/commands/bass.js @@ -8,14 +8,14 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); - if (!args[1] && serverQueue) return msg.channel.send(`${client.messages.currentBass}**${serverQueue.bass}**`); + const queue = client.queue.get(msg.guild.id); + if (!args[1] && queue) return msg.channel.send(`${client.messages.currentBass}**${queue.bass}**`); const bass = parseFloat(args[1]); if (client.funcs.check(client, msg, command)) { if (isNaN(bass)) return msg.channel.send(client.messages.validNumber); if (bass > 100) return msg.channel.send(client.messages.maxBass); if (bass < 0) return msg.channel.send(client.messages.positiveBass); - serverQueue.bass = bass; + queue.bass = bass; let message; message = client.messages.bassApplied.replace("%BASS%", bass); return msg.channel.send(message); diff --git a/commands/bug.js b/commands/bug.js index 71b29df0..6b63e7a0 100644 --- a/commands/bug.js +++ b/commands/bug.js @@ -6,7 +6,7 @@ module.exports = { onlyDev: false, permission: 'none', category: 'info', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, prefix, command) { const embed = new Discord.MessageEmbed() .setTitle(client.messages.bugTitle) .setDescription(client.messages.bugDesc) diff --git a/commands/cmduses.js b/commands/cmduses.js index 67701c44..99c13ef4 100644 --- a/commands/cmduses.js +++ b/commands/cmduses.js @@ -6,7 +6,7 @@ module.exports = { onlyDev: true, permission: 'dev', category: 'info', - async execute(msg, args, client, Discord) { + async execute(msg, args, client, Discord, prefix, command) { const cmduses = []; client.commands.forEach((value, key) => { cmduses.push([key, value.uses]); diff --git a/commands/eval.js b/commands/eval.js index ce0b095c..e8793a1a 100644 --- a/commands/eval.js +++ b/commands/eval.js @@ -6,12 +6,12 @@ module.exports = { onlyDev: true, permission: 'dev', category: 'util', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, prefix, command) { const ytdl = require('ytdl-core'); - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); let data; - if (serverQueue) { - data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url)); + if (queue) { + data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); } const input = msg.content.slice(prefix.length + 4); let output; diff --git a/commands/invite.js b/commands/invite.js index de8ff9ae..c38fc4f2 100644 --- a/commands/invite.js +++ b/commands/invite.js @@ -6,7 +6,7 @@ module.exports = { onlyDev: false, permission: 'none', category: 'info', - execute(msg, args, client, Discord, prefix) { + execute(msg, args, client, Discord, prefix, command) { const embed = new Discord.MessageEmbed() .setTitle(client.messages.inviteTitle) .setURL(client.config.invite) diff --git a/commands/join.js b/commands/join.js index e332cf99..a95ea256 100644 --- a/commands/join.js +++ b/commands/join.js @@ -6,13 +6,13 @@ module.exports = { onlyDev: true, permission: 'none', category: 'util', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, prefix, command) { try { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); const voiceChannel = msg.member.voice.channel; const connection = await voiceChannel.join(); - if (serverQueue) { - serverQueue.connection = connection; + if (queue) { + queue.connection = connection; } msg.channel.send(`${client.messages.joined} ${voiceChannel.name}!`); } catch (error) { diff --git a/commands/loop.js b/commands/loop.js index bda01b48..013012ed 100644 --- a/commands/loop.js +++ b/commands/loop.js @@ -7,13 +7,13 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', async execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { - if (!serverQueue.looping) { - serverQueue.looping = true; + if (!queue.looping) { + queue.looping = true; msg.channel.send(client.messages.looping); } else { - serverQueue.looping = false; + queue.looping = false; msg.channel.send(client.messages.noLooping); } } diff --git a/commands/loopsong.js b/commands/loopsong.js index 899dfbb2..75628f7e 100644 --- a/commands/loopsong.js +++ b/commands/loopsong.js @@ -7,15 +7,15 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', async execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { - if (!serverQueue.songLooping) { - serverQueue.songLooping = true; + if (!queue.songLooping) { + queue.songLooping = true; let message; - message = client.messages.loopingSong.replace("%TITLE%", serverQueue.songs[0].title); + message = client.messages.loopingSong.replace("%TITLE%", queue.songs[0].title); msg.channel.send(message); } else { - serverQueue.songLooping = false; + queue.songLooping = false; msg.channel.send(message); } } diff --git a/commands/nowplaying.js b/commands/nowplaying.js index 0ebdd327..30434f15 100644 --- a/commands/nowplaying.js +++ b/commands/nowplaying.js @@ -6,24 +6,24 @@ module.exports = { onlyDev: false, permission: 'none', category: 'music', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, prefix, command) { const getThumb = require('video-thumbnail-url'); const ytdl = require('ytdl-core'); - const serverQueue = client.queue.get(msg.guild.id); - if (!serverQueue) return msg.channel.send(client.messages.noServerQueue); - let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url)); + const queue = client.queue.get(msg.guild.id); + if (!queue) return msg.channel.send(client.messages.noServerQueue); + let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); let songtime = (data.length_seconds * 1000).toFixed(0); - serverQueue.time = serverQueue.connection.dispatcher.streamTime; - let completed = (serverQueue.time.toFixed(0)); + queue.time = queue.connection.dispatcher.streamTime; + let completed = (queue.time.toFixed(0)); let barlength = 30; let completedpercent = ((completed / songtime) * barlength).toFixed(0); let array = []; for (let i = 0; i < completedpercent - 1; i++) { array.push('⎯'); } array.push('⭗'); for (let i = 0; i < barlength - completedpercent - 1; i++) { array.push('⎯'); } - const thumbnail = getThumb(serverQueue.songs[0].url); + const thumbnail = getThumb(queue.songs[0].url); const embed = new Discord.MessageEmbed() .setTitle(client.messages.nowPlaying) - .setDescription(`${client.messages.nowPlayingDesc} ${serverQueue.songs[0].title}\n${array.join('')} | \`${client.funcs.msToTime(completed, "hh:mm:ss")} / ${client.funcs.msToTime(songtime, "hh:mm:ss")}\``) - .setFooter(`Queued by ${serverQueue.songs[0].author.tag}`) - .setURL(serverQueue.songs[0].url) + .setDescription(`${client.messages.nowPlayingDesc} ${queue.songs[0].title}\n${array.join('')} | \`${client.funcs.msToTime(completed, "hh:mm:ss")} / ${client.funcs.msToTime(songtime, "hh:mm:ss")}\``) + .setFooter(`Queued by ${queue.songs[0].author.tag}`) + .setURL(queue.songs[0].url) .setThumbnail(thumbnail._rejectionHandler0) .setColor(client.config.embedColor) return msg.channel.send(embed); diff --git a/commands/pause.js b/commands/pause.js index a5f88474..25945f24 100644 --- a/commands/pause.js +++ b/commands/pause.js @@ -7,11 +7,11 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { - if (serverQueue.paused) return msg.channel.send(client.messages.alreadyPaused); - serverQueue.paused = true; - serverQueue.connection.dispatcher.pause(true); + if (queue.paused) return msg.channel.send(client.messages.alreadyPaused); + queue.paused = true; + queue.connection.dispatcher.pause(true); return msg.channel.send(client.messages.paused); } } diff --git a/commands/play.js b/commands/play.js index d34457a8..aa01a23a 100644 --- a/commands/play.js +++ b/commands/play.js @@ -8,25 +8,21 @@ module.exports = { onlyDev: false, permission: 'none', category: 'music', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, prefix, command) { const youtube = new YouTube(client.config.api_key); const searchString = args.slice(1).join(" "); const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); const voiceChannel = msg.member.voice.channel; - if (!serverQueue) { + if (!queue) { if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel); } else { - if (voiceChannel !== serverQueue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); + if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); } if (!args[1]) return msg.channel.send(client.messages.noQuery); - const permissions = voiceChannel.permissionsFor(msg.client.user); - if (!permissions.has('CONNECT')) { - return msg.channel.send(client.messages.noPermsConnect); - } - if (!permissions.has('SPEAK')) { - return msg.channel.send(client.messages.noPermsSpeak); - } + if (voiceChannel.full) return msg.channel.send(client.messages.channelFull); + if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect); + if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak); if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) { const lmsg = await msg.channel.send(client.messages.loadingSongs); const playlist = await youtube.getPlaylist(url); diff --git a/commands/queue.js b/commands/queue.js index bf28441f..581cd194 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -6,26 +6,23 @@ module.exports = { onlyDev: false, permission: 'none', category: 'music', - async execute(msg, args, client, Discord, prefix) { - const serverQueue = client.queue.get(msg.guild.id); - if (!serverQueue) return msg.channel.send(client.messages.noServerQueue); + async execute(msg, args, client, Discord, prefix, command) { + const queue = client.queue.get(msg.guild.id); + if (!queue) return msg.channel.send(client.messages.noServerQueue); const page = 1; - let queuesongs = serverQueue.songs.slice((page - 1) * 20 + 1, page * 20 + 1); + let queuesongs = queue.songs.slice((page - 1) * 20 + 1, page * 20 + 1); let queuemessage = `${queuesongs.map(song => `**#** ${song.title}`).join('\n')}` const hashs = queuemessage.split('**#**').length; for (let i = 0; i < hashs; i++) { queuemessage = queuemessage.replace('**#**', `**${i + 1}**`); } let message; - message = client.messages.queueDesc.replace("%SONG%", serverQueue.songs[0].title); + message = client.messages.queueDesc.replace("%SONG%", queue.songs[0].title); const embed = new Discord.MessageEmbed() .setTitle(client.messages.queueTitle) .setDescription(`${message}\n${queuemessage}`) - .setFooter(`${serverQueue.songs.length} ${client.messages.queueFooter}`) + .setFooter(`${queue.songs.length} ${client.messages.queueFooter}`) .setColor(client.config.embedColor) - /*if (serverQueue.songs.size > 20) { - embed.setFooter(`${serverQueue.songs.size - 20} ${client.messages.queueFooter}`) - }*/ return msg.channel.send(embed); } }; diff --git a/commands/remove.js b/commands/remove.js index 1a606c37..9b53c5d1 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -7,7 +7,7 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { if (!args[1]) return msg.channel.send(client.messages.provideASong); const pos = parseInt(args[1]); @@ -15,11 +15,11 @@ module.exports = { if (pos < 1) return msg.channel.send(client.messages.noSongs); let message1; let message2; - message1 = client.messages.queueLength.replace("%LENGTH%", serverQueue.songs.length); - if (pos > serverQueue.songs.length) return msg.channel.send(message1); - message2 = client.messages.removed.replace("%SONG%", serverQueue.songs[pos].title); + message1 = client.messages.queueLength.replace("%LENGTH%", queue.songs.length); + if (pos > queue.songs.length) return msg.channel.send(message1); + message2 = client.messages.removed.replace("%SONG%", queue.songs[pos].title); msg.channel.send(message2); - return serverQueue.songs.splice(pos, 1); + return queue.songs.splice(pos, 1); } } }; diff --git a/commands/resume.js b/commands/resume.js index 06a4dc78..edb300b0 100644 --- a/commands/resume.js +++ b/commands/resume.js @@ -7,11 +7,11 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { - if (!serverQueue.paused) return msg.channel.send(client.messages.notPaused); - serverQueue.paused = false; - serverQueue.connection.dispatcher.resume(true); + if (!queue.paused) return msg.channel.send(client.messages.notPaused); + queue.paused = false; + queue.connection.dispatcher.resume(true); return msg.channel.send(client.messages.resumed); } } diff --git a/commands/search.js b/commands/search.js index bdf47e57..c464c16e 100644 --- a/commands/search.js +++ b/commands/search.js @@ -9,25 +9,21 @@ module.exports = { onlyDev: false, permission: 'none', category: 'music', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, prefix, command) { const youtube = new YouTube(client.config.api_key); const searchString = args.slice(1).join(" "); const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); const voiceChannel = msg.member.voice.channel; - if (!serverQueue) { + if (!queue) { if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel); } else { - if (voiceChannel !== serverQueue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); + if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); } if (!args[1]) return msg.channel.send(client.messages.noQuery); - const permissions = voiceChannel.permissionsFor(msg.client.user); - if (!permissions.has('CONNECT')) { - return msg.channel.send(client.messages.noPermsConnect); - } - if (!permissions.has('SPEAK')) { - return msg.channel.send(client.messages.noPermsSpeak); - } + if (voiceChannel.full) return msg.channel.send(client.messages.channelFull); + if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect); + if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak); if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) { const lmsg = await msg.channel.send(client.messages.loadingSongs); const playlist = await youtube.getPlaylist(url); diff --git a/commands/seek.js b/commands/seek.js index 137c9526..8dd2076a 100644 --- a/commands/seek.js +++ b/commands/seek.js @@ -8,9 +8,9 @@ module.exports = { category: 'music', async execute(msg, args, client, Discord, prefix, command) { const ytdl = require('ytdl-core'); - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { - let data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url)); + let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${prefix}seek ${command.usage}\``); let point = args[1]; const pos = parseInt(args[1]); @@ -21,9 +21,9 @@ module.exports = { if (pos > data.length_seconds) return msg.channel.send(message); point = pos; } - serverQueue.connection.dispatcher.end(); - serverQueue.endReason = "seek"; - client.funcs.play(msg.guild, serverQueue.songs[0], client, msg, point, false); + queue.connection.dispatcher.end(); + queue.endReason = "seek"; + client.funcs.play(msg.guild, queue.songs[0], client, msg, point, false); } } }; diff --git a/commands/shuffle.js b/commands/shuffle.js index 42bea505..ab734460 100644 --- a/commands/shuffle.js +++ b/commands/shuffle.js @@ -7,9 +7,9 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { - client.funcs.shuffle(serverQueue.songs); + client.funcs.shuffle(queue.songs); msg.channel.send(client.messages.shuffled); } } diff --git a/commands/skip.js b/commands/skip.js index 43c2a52e..c0752eb0 100644 --- a/commands/skip.js +++ b/commands/skip.js @@ -7,44 +7,44 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); const permissions = msg.channel.permissionsFor(msg.author); - if (!serverQueue || !serverQueue.playing) return msg.channel.send(client.messages.noServerQueue); + if (!queue || !queue.playing) return msg.channel.send(client.messages.noServerQueue); if (msg.author.id !== client.config.devId) { - if (msg.member.voice.channel !== serverQueue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); + if (msg.member.voice.channel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); if (client.global.db.guilds[msg.guild.id].permissions) { if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole) || !permissions.has(command.permission)) { - return vote(serverQueue, msg, client); + return vote(queue, msg, client); } else { - return skipSong(serverQueue, msg, client); + return skipSong(queue, msg, client); } } else { - return skipSong(serverQueue, msg, client); + return skipSong(queue, msg, client); } } else { - return skipSong(serverQueue, msg, client); + return skipSong(queue, msg, client); } } }; -function skipSong(serverQueue, msg, client) { +function skipSong(queue, msg, client) { msg.channel.send(client.messages.skipped); - serverQueue.endReason = "skip"; - serverQueue.connection.dispatcher.end(); + queue.endReason = "skip"; + queue.connection.dispatcher.end(); }; -function vote(serverQueue, msg, client) { - serverQueue.votesNeeded = Math.floor(serverQueue.voiceChannel.members.size / 2); - serverQueue.votesNeeded.toFixed(); - if (serverQueue.voiceChannel.members.size > 2) { - if (serverQueue.voters.includes(msg.member.id)) return msg.channel.send(client.messages.alreadyVoted); - serverQueue.votes++; - serverQueue.voters.push(msg.member.id); - if (serverQueue.votes >= serverQueue.votesNeeded) { - serverQueue.voters = []; - serverQueue.votes = 0; - serverQueue.votesNeeded = null; - return skipSong(serverQueue, msg); - } else return msg.channel.send(`${client.messages.notEnoughVotes} ${serverQueue.votes} / ${serverQueue.votesNeeded}!`); +function vote(queue, msg, client) { + queue.votesNeeded = Math.floor(queue.voiceChannel.members.size / 2); + queue.votesNeeded.toFixed(); + if (queue.voiceChannel.members.size > 2) { + if (queue.voters.includes(msg.member.id)) return msg.channel.send(client.messages.alreadyVoted); + queue.votes++; + queue.voters.push(msg.member.id); + if (queue.votes >= queue.votesNeeded) { + queue.voters = []; + queue.votes = 0; + queue.votesNeeded = null; + return skipSong(queue, msg); + } else return msg.channel.send(`${client.messages.notEnoughVotes} ${queue.votes} / ${queue.votesNeeded}!`); } else { - return skipSong(serverQueue, msg); + return skipSong(queue, msg); } }; diff --git a/commands/skipto.js b/commands/skipto.js index 4a416bb9..4e8b5d27 100644 --- a/commands/skipto.js +++ b/commands/skipto.js @@ -7,20 +7,20 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', async execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${command.usage}\``); const point = parseInt(args[1] - 1); if (isNaN(point)) return msg.channel.send(client.messages.validNumber); - if (point > serverQueue.songs.size) return msg.channel.send(client.messages.noSongs); + if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs); if (point < 1) return msg.channel.send(client.messages.cantSkipToCurrent); let i = 0; while (i < point) { i++; - serverQueue.songs.shift(); + queue.songs.shift(); } - serverQueue.endReason = "skipto"; - serverQueue.connection.dispatcher.end(); + queue.endReason = "skipto"; + queue.connection.dispatcher.end(); } } }; diff --git a/commands/status.js b/commands/status.js index 0efe38eb..ae215bdf 100644 --- a/commands/status.js +++ b/commands/status.js @@ -6,7 +6,7 @@ module.exports = { onlyDev: false, permission: 'none', category: 'info', - execute(msg, args, client, Discord, prefix) { + execute(msg, args, client, Discord, prefix, command) { const uptime = client.funcs.msToTime(client.uptime, "dd:hh:mm:ss"); msg.channel.send(client.messages.pinging).then(m => { const latency = m.createdTimestamp - msg.createdTimestamp; diff --git a/commands/stop.js b/commands/stop.js index f2378915..3b6fa173 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -7,12 +7,12 @@ module.exports = { permission: 'MANAGE_CHANNELS', category: 'music', execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { - serverQueue.songs = []; - serverQueue.looping = false; - serverQueue.endReason = "stop"; - serverQueue.connection.dispatcher.end(); + queue.songs = []; + queue.looping = false; + queue.endReason = "stop"; + queue.connection.dispatcher.end(); msg.channel.send(client.messages.stop) } } diff --git a/commands/volume.js b/commands/volume.js index a53c487d..bd51aaa0 100644 --- a/commands/volume.js +++ b/commands/volume.js @@ -8,15 +8,15 @@ module.exports = { permission: 'MANAGE_MESSAGES', category: 'music', execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); - if (!args[1] && serverQueue) return msg.channel.send(`${client.messages.currentVolume}**${serverQueue.volume}**`); + const queue = client.queue.get(msg.guild.id); + if (!args[1] && queue) return msg.channel.send(`${client.messages.currentVolume}**${queue.volume}**`); const volume = parseFloat(args[1]); if (client.funcs.check(client, msg, command)) { if (isNaN(volume)) return msg.channel.send(client.messages.validNumber); if (volume > 100) return msg.channel.send(client.messages.maxVolume); if (volume < 0) return msg.channel.send(client.messages.positiveVolume); - serverQueue.volume = volume; - serverQueue.connection.dispatcher.setVolume(volume / 5); + queue.volume = volume; + queue.connection.dispatcher.setVolume(volume / 5); return msg.channel.send(`${client.messages.setVolume}**${volume}**`); } } diff --git a/events/dispatcher/error.js b/events/dispatcher/error.js new file mode 100644 index 00000000..4e9e7bb3 --- /dev/null +++ b/events/dispatcher/error.js @@ -0,0 +1,13 @@ +module.exports = async function (client, error, guild) { + const queue = client.queue.get(guild.id); + console.error(error); + /*if (error = "Error: input stream: This video contains content from WMG, who has blocked it on copyright grounds.") { + queue.endReason = "skip"; + queue.connection.dispatcher.end(); + return queue.textChannel.send(client.messages.songBlockedWMG); + }*/ + client.debug_channel.send(client.messages.dispatcherError + error); + queue.voiceChannel.leave(); + client.queue.delete(guild.id); + return queue.textChannel.send(client.messages.errorDispatcher); +}; \ No newline at end of file diff --git a/events/dispatcher/finish.js b/events/dispatcher/finish.js index ef2e1bf0..db043d63 100644 --- a/events/dispatcher/finish.js +++ b/events/dispatcher/finish.js @@ -1,17 +1,17 @@ module.exports = async function (client, reason, guild) { - const serverQueue = client.queue.get(guild.id); - serverQueue.playing = false; + const queue = client.queue.get(guild.id); + queue.playing = false; if (reason === "seek") { return; } - if (!serverQueue.songLooping) { - if (serverQueue.looping) { - serverQueue.songs.push(serverQueue.songs[0]); + if (!queue.songLooping) { + if (queue.looping) { + queue.songs.push(queue.songs[0]); } - serverQueue.votes = 0; - serverQueue.voters = []; - serverQueue.songs.shift(); + queue.votes = 0; + queue.voters = []; + queue.songs.shift(); } - client.funcs.play(guild, serverQueue.songs[0], client, 0, true); + client.funcs.play(guild, queue.songs[0], client, 0, true); }; \ No newline at end of file diff --git a/events/msg.js b/events/msg.js index b8f24be1..67bf018b 100644 --- a/events/msg.js +++ b/events/msg.js @@ -22,8 +22,8 @@ module.exports = { if (commandName === "none") return; const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)) || client.commandAliases.get(commandName); if (!command && msg.content !== `${prefix}`) return; - if (command.onlyDev && msg.author.id !== client.config.devId) return msg.channel.send(client.messages.notAllowed); - //if (client.config.devMode && msg.member.id !== client.config.devId) return msg.channel.send(client.messages.devMode); + if (command.onlyDev && msg.author.id !== client.config.devId) return; + if (client.config.devMode && msg.member.id !== client.config.devId) return msg.channel.send(client.messages.devMode); client.funcs.exe(msg, args, client, Discord, prefix, command); } } \ No newline at end of file diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js index 62e6b63d..e09de8d7 100644 --- a/events/voiceStateUpdate.js +++ b/events/voiceStateUpdate.js @@ -2,30 +2,30 @@ module.exports = { name: 'voiceStateUpdate', async execute(client, oldState, newState) { let change = false; - const serverQueue = client.queue.get(newState.guild.id); - if (!serverQueue) return; + const queue = client.queue.get(newState.guild.id); + if (!queue) return; if (newState.member.id === client.user.id && oldState.member.id === client.user.id) { if (newState.member.voice.channel === null) { - serverQueue.songs = []; - serverQueue.looping = false; - serverQueue.endReason = "manual disconnect"; + queue.songs = []; + queue.looping = false; + queue.endReason = "manual disconnect"; return client.queue.delete(newState.guild.id); } - if (newState.member.voice.channel !== serverQueue.voiceChannel) { + if (newState.member.voice.channel !== queue.voiceChannel) { change = true; - serverQueue.voiceChannel = newState.member.voice.channel; - serverQueue.connection = newState.connection; + queue.voiceChannel = newState.member.voice.channel; + queue.connection = newState.connection; } } if (oldState.channel === null) return; - if (oldState.channel.members.size === 1 && oldState.channel === serverQueue.voiceChannel || change) { + if (oldState.channel.members.size === 1 && oldState.channel === queue.voiceChannel || change) { setTimeout(() => { - if (!serverQueue) return; - if (serverQueue.voiceChannel.members.size === 1) { - serverQueue.songs = []; - serverQueue.looping = false; - serverQueue.endReason = "Timeout"; - serverQueue.connection.dispatcher.end(); + if (!queue) return; + if (queue.voiceChannel.members.size === 1) { + queue.songs = []; + queue.looping = false; + queue.endReason = "Timeout"; + queue.connection.dispatcher.end(); } }, 12000); } diff --git a/struct/client.js b/struct/client.js index d2a0cd79..d93c3bc1 100644 --- a/struct/client.js +++ b/struct/client.js @@ -21,6 +21,7 @@ module.exports = class extends Client { this.config = require('./config/config.js'); this.messages = require('./config/messages.js'); this.dispatcher.finish = require('../events/dispatcher/finish.js'); + this.dispatcher.error = require('../events/dispatcher/error.js'); fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => { this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`); diff --git a/struct/config/messages.js b/struct/config/messages.js index 719c6dad..1113a105 100644 --- a/struct/config/messages.js +++ b/struct/config/messages.js @@ -16,6 +16,7 @@ module.exports = { bugTitle: "Found a bug with Musix?\nDM the core developer:", cancellingVideoSelection: "<:redx:674263474704220182> Cancelling video selection", cantSkipToCurrent: "<:redx:674263474704220182> You can't skip to the song currently playing!", + channelFull: "<:redx:674263474704220182> Your voice channel is full!", cmdUsesFooter: "These statistics are from the current uptime.", cmdUsesTitle: "Musix Command Usage During Current Uptime", correctUsage: "<:redx:674263474704220182> correct usage: ", @@ -113,6 +114,7 @@ module.exports = { shuffled: "<:shuffle:674685595980791871> Queue suffled!", skipped: "<:skip:674685614221688832> Skipped the song!", songAdded: "<:green_check_mark:674265384777416705> **%TITLE%** has been added to the queue!", + songBlockedWMG: "<:redx:674263474704220182> This song had been blocked by WMG (Warner Music Groud).\n<:skip:674685614221688832> Skipped to next song.", songSelection: "__Song Selection__", startPlaying: " Start playing: ", statusField1: ":signal_strength: Ping", diff --git a/struct/funcs/check.js b/struct/funcs/check.js index 88ce651a..09d38b28 100644 --- a/struct/funcs/check.js +++ b/struct/funcs/check.js @@ -1,12 +1,12 @@ module.exports = function (client, msg, command) { - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); const permissions = msg.channel.permissionsFor(msg.author); - if (!serverQueue || !serverQueue.playing) { + if (!queue || !queue.playing) { msg.channel.send(client.messages.noServerQueue); return false; } if (msg.author.id !== client.config.devId) { - if (msg.member.voice.channel !== serverQueue.voiceChannel) { + if (msg.member.voice.channel !== queue.voiceChannel) { msg.channel.send(client.messages.wrongVoiceChannel); return false; } diff --git a/struct/funcs/handleVideo.js b/struct/funcs/handleVideo.js index c5f8f3f8..7f8e01b3 100644 --- a/struct/funcs/handleVideo.js +++ b/struct/funcs/handleVideo.js @@ -7,10 +7,10 @@ module.exports = async function (video, msg, voiceChannel, client, playlist = fa author: msg.author } - const serverQueue = client.queue.get(msg.guild.id); + const queue = client.queue.get(msg.guild.id); - if (serverQueue) { - serverQueue.songs.push(song); + if (queue) { + queue.songs.push(song); if (playlist) return; let message; message = client.messages.songAdded.replace("%TITLE%", song.title); diff --git a/struct/funcs/play.js b/struct/funcs/play.js index 0715f691..da967ad7 100644 --- a/struct/funcs/play.js +++ b/struct/funcs/play.js @@ -3,38 +3,34 @@ module.exports = async function (guild, song, client, seek, play) { const ytdl = require('ytdl-core'); const getThumb = require('video-thumbnail-url'); - const serverQueue = client.queue.get(guild.id); + const queue = client.queue.get(guild.id); if (!song) { - serverQueue.voiceChannel.leave(); + queue.voiceChannel.leave(); client.queue.delete(guild.id); return; } - const dispatcher = serverQueue.connection - .play(await ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25, volume: false, begin: seek }), { seek: 0, bitrate: 1024, passes: 10, volume: 1, bassboost: serverQueue.bass }) + const dispatcher = queue.connection + .play(await ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25, volume: false, begin: seek }), { seek: 0, bitrate: 1024, passes: 10, volume: 1, bassboost: queue.bass }) .on("finish", () => { - client.dispatcher.finish(client, serverQueue.endReason, guild); + client.dispatcher.finish(client, queue.endReason, guild); }); dispatcher.on('start', () => { dispatcher.player.streamingData.pausedTime = 0; }); dispatcher.on('error', error => { - console.error(error); - client.debug_channel.send(client.messages.dispatcherError + error); - serverQueue.voiceChannel.leave(); - client.queue.delete(guild.id); - return serverQueue.textChannel.send(client.messages.errorDispatcher); + client.dispatcher.error(client, error, guild); }); - dispatcher.setVolume(serverQueue.volume / 10); + dispatcher.setVolume(queue.volume / 10); if (client.global.db.guilds[guild.id].startPlaying || play) { - const data = await Promise.resolve(ytdl.getInfo(serverQueue.songs[0].url)); + const data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); const songtime = (data.length_seconds * 1000).toFixed(0); - const thumbnail = getThumb(serverQueue.songs[0].url); + const thumbnail = getThumb(queue.songs[0].url); const embed = new Discord.MessageEmbed() .setTitle(`${client.messages.startPlaying}**${song.title}**`) .setDescription(`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``) .setThumbnail(thumbnail._rejectionHandler0) .setColor(client.config.embedColor) - serverQueue.textChannel.send(embed); + queue.textChannel.send(embed); } - serverQueue.playing = true; + queue.playing = true; }