diff --git a/commands/cmduses.js b/commands/cmduses.js deleted file mode 100644 index 7e350f3..0000000 --- a/commands/cmduses.js +++ /dev/null @@ -1,31 +0,0 @@ -module.exports = { - name: 'cmduses', - alias: 'none', - usage: '', - description: 'list all commands and how many times they\'ve been used', - onlyDev: true, - permission: 'dev', - category: 'info', - async execute(msg, args, client, Discord) { - const cmduses = []; - client.commands.forEach((value, key) => { - cmduses.push([key, value.uses]); - }); - cmduses.sort((a, b) => { - return b[1] - a[1]; - }); - const cmdnamelength = Math.max(...cmduses.map(x => x[0].length)) + 4; - const numberlength = Math.max(...cmduses.map(x => x[1].toString().length), 4); - const markdownrows = ['Command' + ' '.repeat(cmdnamelength - 'command'.length) + ' '.repeat(numberlength - 'uses'.length) + 'Uses']; - cmduses.forEach(x => { - if (x[1] > 0) markdownrows.push(x[0] + '.'.repeat(cmdnamelength - x[0].length) + ' '.repeat(numberlength - x[1].toString().length) + x[1].toString()); - }); - const embed = new Discord.MessageEmbed(); - embed - .setTitle('Musix Command Usage During Current Uptime') - .setDescription('```ml\n' + markdownrows.join('\n') + '\n```') - .setFooter('These statistics are from the current uptime.') - .setColor(client.config.embedColor); - msg.channel.send(embed); - }, -}; \ No newline at end of file diff --git a/commands/eval.js b/commands/eval.js deleted file mode 100644 index 53d41b6..0000000 --- a/commands/eval.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = { - name: 'eval', - alias: 'e', - usage: '', - description: 'Evaluation command. DEV ONLY!', - onlyDev: true, - permission: 'dev', - category: 'util', - async execute(msg, args, client, Discord, prefix) { - const radio = client.radio.get(msg.guild.id); - const input = msg.content.slice(prefix.length + 4); - let output; - try { - output = await eval(input); - } catch (error) { - output = error.toString(); - } - const embed = new Discord.MessageEmbed() - .setTitle('Evaluation Command') - .setColor(client.config.embedColor) - .setDescription(`Input: \`\`\`js\n${input.replace(/; /g, ';').replace(/;/g, ';\n')}\n\`\`\`\nOutput: \`\`\`\n${output}\n\`\`\``); - return msg.channel.send(embed); - }, -}; diff --git a/commands/join.js b/commands/join.js deleted file mode 100644 index daa6944..0000000 --- a/commands/join.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = { - name: 'join', - alias: 'j', - usage: '', - description: 'Make Musix join the channel your channel', - onlyDev: true, - permission: 'none', - category: 'util', - async execute(msg, args, client, Discord, prefix) { - try { - const radio = client.radio.get(msg.guild.id); - const voiceChannel = msg.member.voice.channel; - const connection = await voiceChannel.join(); - if (radio) { - radio.connection = connection; - } - msg.channel.send(`<:green_check_mark:674265384777416705> Joined ${voiceChannel.name}!`); - } catch (error) { - client.radio.delete(msg.guild.id); - client.channels.fetch(client.config.debug_channel).send("Error with connecting to voice channel: " + error); - return msg.channel.send(`<:redx:674263474704220182> An error occured: ${error}`); - } - } -}; \ No newline at end of file diff --git a/commands/play.js b/commands/play.js index 953a335..057f39d 100644 --- a/commands/play.js +++ b/commands/play.js @@ -7,7 +7,6 @@ module.exports = { permission: 'none', category: 'music', async execute(msg, args, client, Discord, prefix) { - const searchString = args.slice(1).join(" "); const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; const radio = client.radio.get(msg.guild.id); const voiceChannel = msg.member.voice.channel; @@ -24,6 +23,30 @@ module.exports = { if (!permissions.has('SPEAK')) { return msg.channel.send('<:redx:674263474704220182> I cannot speak in your voice channel, make sure I have the proper permissions!'); } - return client.funcs.handleRadio(msg, voiceChannel, client, url); + + if (radio) { + radio.connection.dispatcher.end(); + } + + const construct = { + textChannel: msg.channel, + voiceChannel: voiceChannel, + connection: null, + playing: false, + url: url, + name: null, + volume: client.config.volume, + }; + client.radio.set(msg.guild.id, construct); + + try { + const connection = await voiceChannel.join(); + construct.connection = connection; + client.funcs.play(msg.guild, client, url); + } catch (error) { + client.radio.delete(msg.guild.id); + client.debug_channel.send("Error with connecting to voice channel: " + error); + return msg.channel.send(`<:redx:674263474704220182> An error occured: ${error}`); + } } }; diff --git a/commands/reload.js b/commands/reload.js deleted file mode 100644 index 59baca5..0000000 --- a/commands/reload.js +++ /dev/null @@ -1,30 +0,0 @@ -const fs = require('fs'); -const path = require('path') - -module.exports = { - name: 'reload', - alias: 'none', - usage: '', - description: 'Reload all files', - onlyDev: true, - permission: 'none', - category: 'util', - async execute(msg, args, client, Discord, prefix, command) { - const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.js')); - for (const file of commandFiles) { - const command = require(`./${file}`); - command.uses = 0; - client.commands.set(command.name, command); - client.commandAliases.set(command.alias, command); - } - const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.js')); - for (const file of settingFiles) { - const option = require(`./settings/${file}`); - client.settingCmd.set(option.name, option); - } - /*fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => { - this.funcs[filename.slice(0, -3)] = require(`../struct/funcs/${filename}`); - });*/ - msg.channel.send('All files reloaded!'); - } -}; diff --git a/commands/restart.js b/commands/restart.js deleted file mode 100644 index 148b9cf..0000000 --- a/commands/restart.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - name: 'restart', - alias: 'none', - usage: '', - description: 'Restart the bot', - onlyDev: true, - permission: 'none', - category: 'util', - async execute(msg, args, client, Discord, prefix, command) { - client.destroy(); - require('../index.js'); - msg.channel.send('restarted!'); - } -}; diff --git a/commands/stop.js b/commands/stop.js index fd422be..c664683 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -9,7 +9,7 @@ module.exports = { execute(msg, args, client, Discord, prefix, command) { const radio = client.radio.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { - radio.connection.dispatcher.end('Stopped'); + radio.connection.dispatcher.end(); msg.channel.send('<:stop:674685626108477519> Stopped the music!') } } diff --git a/commands/volume.js b/commands/volume.js index 7fa73e1..32255eb 100644 --- a/commands/volume.js +++ b/commands/volume.js @@ -3,7 +3,6 @@ module.exports = { description: 'Volume command.', alias: 'none', usage: '', - cooldown: 5, onlyDev: false, permission: 'MANAGE_MESSAGES', category: 'music', diff --git a/events/ready.js b/events/ready.js index bfe058c..e6d7a29 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,14 +1,11 @@ module.exports = { name: 'ready', async execute(client, Discord) { + const debugChannel = await client.channels.fetch(client.config.debug_channel); + client.debug_channel = debugChannel if (client.config.devMode) { console.log('dev mode'); } - client.user.setActivity(`@${client.user.username} help | 🎶`, { type: 'LISTENING' }); - client.user.setStatus('online'); console.log('- Activated -'); - setInterval(() => { - client.funcs.ffmpeg(client, Discord); - }, 7200000); } } diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js index 57a5fa5..32b5d47 100644 --- a/events/voiceStateUpdate.js +++ b/events/voiceStateUpdate.js @@ -1,13 +1,32 @@ module.exports = { name: 'voiceStateUpdate', - async execute(client, newMember) { - const serverQueue = client.radio.get(newMember.guild.id); - if (!serverQueue) return; - if (newMember === client.user) { - if (newMember.voice.channel !== serverQueue.voiceChannel) { - serverQueue.voiceChannel = newMember.voice.channel; - console.log(`Changed serverQueue voiceChannel since Musix was moved to a different channel!`); + async execute(client, oldState, newState) { + let change = false; + const radio = client.radio.get(newState.guild.id); + if (!radio) return; + if (newState.member.id === client.user.id && oldState.member.id === client.user.id) { + if (newState.member.voice.channel === null) { + radio.songs = []; + radio.looping = false; + radio.endReason = "manual disconnect"; + return client.queue.delete(newState.guild.id); } + if (newState.member.voice.channel !== radio.voiceChannel) { + change = true; + radio.voiceChannel = newState.member.voice.channel; + radio.connection = newState.connection; + } + } + if (oldState.channel === null) return; + if (oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel || change) { + setTimeout(() => { + if (!radio) return; + if (radio.voiceChannel.members.size === 1) { + radio.songs = []; + radio.looping = false; + radio.connection.dispatcher.end(); + } + }, 12000); } } } diff --git a/struct/client.js b/struct/client.js index 37069e2..cd8eb45 100644 --- a/struct/client.js +++ b/struct/client.js @@ -39,8 +39,8 @@ module.exports = class extends Client { this.on('message', (msg) => { require(`${events}msg`).execute(this, msg, Discord); }); - this.on('voiceStateUpdate', (newMember) => { - require(`${events}voiceStateUpdate`).execute(this, newMember); + this.on('voiceStateUpdate', (oldState, newState) => { + require(`${events}voiceStateUpdate`).execute(this, oldState, newState); }); this.on('error', (error) => { client.channels.fetch(client.config.debug_channel).send('Error: ' + error); diff --git a/struct/funcs/exe.js b/struct/funcs/exe.js index 820e43c..51a688a 100644 --- a/struct/funcs/exe.js +++ b/struct/funcs/exe.js @@ -1,7 +1,6 @@ module.exports = function (msg, args, client, Discord, prefix, command) { const permissions = msg.channel.permissionsFor(msg.client.user); if (!permissions.has('EMBED_LINKS')) return msg.channel.send('<:redx:674263474704220182> I cannot send embeds (Embed links), make sure I have the proper permissions!'); - //if (!permissions.has('EXTERNAL_EMOJIS')) return msg.channel.send('<:redx:674263474704220182> I cannot use external emojis, make sure I have the proper permissions!'); DEPRACATED! try { command.uses++; command.execute(msg, args, client, Discord, prefix, command); @@ -11,7 +10,7 @@ module.exports = function (msg, args, client, Discord, prefix, command) { .setTitle(`Musix ${error.toString()}`) .setDescription(error.stack.replace(/at /g, '**at **')) .setColor('#b50002'); - //client.channels.fetch(client.config.debug_channel).send(embed); + client.debug_channel.send(embed); console.error(error); } }; diff --git a/struct/funcs/ffmpeg.js b/struct/funcs/ffmpeg.js deleted file mode 100644 index 4577f3c..0000000 --- a/struct/funcs/ffmpeg.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = async function (client) { - try { - await client.channels.fetch(client.config.secondary_test_channel) - .then(x => x.join()); - } catch (error) { - client.channels.fetch(client.config.debug_channel).send("Error detected: " + error); - } -}; \ No newline at end of file diff --git a/struct/funcs/handleRadio.js b/struct/funcs/handleRadio.js deleted file mode 100644 index ec419c5..0000000 --- a/struct/funcs/handleRadio.js +++ /dev/null @@ -1,29 +0,0 @@ -module.exports = async function (msg, voiceChannel, client, url) { - const radio = client.radio.get(msg.guild.id); - - if (radio) { - radio.connection.dispatcher.end('Stopped'); - } - - const construct = { - textChannel: msg.channel, - voiceChannel: voiceChannel, - connection: null, - playing: false, - url: url, - name: null, - volume: client.config.volume, - }; - client.radio.set(msg.guild.id, construct); - - try { - const connection = await voiceChannel.join(); - construct.connection = connection; - client.funcs.play(msg.guild, client, url); - } catch (error) { - client.radio.delete(msg.guild.id); - //client.channels.fetch(client.config.debug_channel).send("Error with connecting to voice channel: " + error); - return msg.channel.send(`<:redx:674263474704220182> An error occured: ${error}`); - } - return; -} diff --git a/struct/funcs/msToTime.js b/struct/funcs/msToTime.js deleted file mode 100644 index 3247cb7..0000000 --- a/struct/funcs/msToTime.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = function msToTime(duration, format) { - var seconds = Math.floor((duration / 1000) % 60), - minutes = Math.floor((duration / (1000 * 60)) % 60), - hours = Math.floor((duration / (1000 * 60 * 60)) % 24); - days = Math.floor((duration / (1000 * 60 * 60 * 24)) % 24); - - days = (days < 10) ? "0" + days : days; - hours = (hours < 10) ? "0" + hours : hours; - minutes = (minutes < 10) ? "0" + minutes : minutes; - seconds = (seconds < 10) ? "0" + seconds : seconds; - - if (format === "hh:mm:ss") { - return `${hours}:${minutes}:${seconds}`; - } else if (format === "dd:hh:mm:ss") { - return `${days}:${hours}:${minutes}:${seconds}`; - } -}