From c1bbdf9532af714f26826ba84429238daaadbeec Mon Sep 17 00:00:00 2001 From: MatteZ02 <47610069+MatteZ02@users.noreply.github.com> Date: Mon, 10 Feb 2020 21:04:42 +0200 Subject: [PATCH] update --- .gitignore | 1 - src/commands/disconnect.js | 23 ++++++++++++++++++++--- src/commands/help.js | 2 +- src/commands/join.js | 2 +- src/commands/shuffle.js | 12 ------------ src/events/msg.js | 2 +- src/index.js | 3 +-- src/struct/config/config.js | 10 ++++++++-- src/struct/funcs/ffmpeg.js | 2 +- src/struct/funcs/msToTime.js | 20 ++++++++++++-------- 10 files changed, 45 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index c5198c09..bc57a589 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ dev/ .env .vscode/ package-lock.json -src/struct/config/.env src/struct/config/serviceAccount.json \ No newline at end of file diff --git a/src/commands/disconnect.js b/src/commands/disconnect.js index e00b3142..76edfcca 100644 --- a/src/commands/disconnect.js +++ b/src/commands/disconnect.js @@ -3,14 +3,31 @@ module.exports = { alias: 'dc', usage: 'disconnect', description: 'Disconnect the bot from a voice channel.', - onlyDev: false, + onlyDev: true, permission: 'MANAGE_CHANNELS', category: 'util', async execute(msg, args, client, Discord, prefix, command) { const serverQueue = client.queue.get(msg.guild.id); - if (client.funcs.check(client, msg, command)) { - serverQueue.voiceChannel.leave(); + if (msg.author.id !== client.config.devId) { + if (msg.member.voice.channel !== serverQueue.voiceChannel) return msg.channel.send(`<:redx:674263474704220182> I'm sorry but you need to be in the same voice channel as Musix to use this command!`); + if (client.global.db.guilds[msg.guild.id].permissions === true) { + if (client.global.db.guilds[msg.guild.id].dj) { + if (!msg.member.roles.has(client.global.db.guilds[msg.guild.id].djrole)) { + msg.channel.send('<:redx:674263474704220182> You need the `DJ` role to use this command!'); + }; + } else if (!permissions.has(command.permission)) { + msg.channel.send(`<:redx:674263474704220182> You need the \`${command.permission}\` permission to use this command!`); + } + }; + } + if (serverQueue && serverQueue.playing) { + return msg.channel.send('<:redx:674263474704220182> There is something playing! Use the `stop` command instead!'); + } + if (msg.guild.voiceConnection) { + msg.guild.voiceConnection.channel.leave(); msg.channel.send('<:green_check_mark:674265384777416705> Left the voice channel!'); + } else { + msg.channel.send('<:redx:674263474704220182> i\'m not connected to a voice channel!') } } }; \ No newline at end of file diff --git a/src/commands/help.js b/src/commands/help.js index 7bef8f64..3e48a6c5 100644 --- a/src/commands/help.js +++ b/src/commands/help.js @@ -23,7 +23,7 @@ module.exports = { } let commands = ''; for (let i = 0; i < categories.length; i++) { - commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp).map(x => `\`${x.name}\``).join(', ')}\n`; + commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp && !x.onlyDev).map(x => `\`${x.name}\``).join(', ')}\n`; } const embed = new Discord.MessageEmbed() .setTitle(`${client.user.username} help:`) diff --git a/src/commands/join.js b/src/commands/join.js index c500ae61..1b098d47 100644 --- a/src/commands/join.js +++ b/src/commands/join.js @@ -3,7 +3,7 @@ module.exports = { alias: 'j', usage: 'join', description: 'Make Musix join the channel your channel', - onlyDev: false, + onlyDev: true, permission: 'none', category: 'util', async execute(msg, args, client, Discord, prefix) { diff --git a/src/commands/shuffle.js b/src/commands/shuffle.js index 8960afec..0b241f92 100644 --- a/src/commands/shuffle.js +++ b/src/commands/shuffle.js @@ -11,18 +11,6 @@ module.exports = { if (client.funcs.check(client, msg, command)) { client.funcs.shuffle(serverQueue.songs); msg.channel.send('<:shuffle:674685595980791871> Queue suffled!'); - /*let currentIndex = serverQueue.songs.length, - temporaryValue, - randomIndex; - - while (0 !== currentIndex) { - randomIndex = Math.floor(Math.random() * currentIndex); - currentIndex -= 1; - - temporaryValue = serverQueue.songs[currentIndex]; - serverQueue.songs[currentIndex] = serverQueue.songs[randomIndex]; - serverQueue.songs[randomIndex] = temporaryValue;* - }*/ } } }; \ No newline at end of file diff --git a/src/events/msg.js b/src/events/msg.js index 02f9292f..4881522b 100644 --- a/src/events/msg.js +++ b/src/events/msg.js @@ -15,9 +15,9 @@ module.exports = { } } } - if (client.config.devMode && msg.member.id !== client.config.devId) return msg.channel.send('<:redx:674263474704220182> Dev mode has been turned on! Commands are only available to developer(s)!'); if (!msg.content.startsWith(prefix)) return; if (!args[0]) return; + if (client.config.devMode && msg.member.id !== client.config.devId) return msg.channel.send('<:redx:674263474704220182> Dev mode has been turned on! Commands are only available to developer(s)!'); const commandName = args[0].toLowerCase(); 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; diff --git a/src/index.js b/src/index.js index 24116fc0..2708e48b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,3 @@ const Discord = require('discord.js'); const MusicClient = require('./struct/client.js'); -const client = new MusicClient({}); -require('dotenv/config'); \ No newline at end of file +const client = new MusicClient({}); \ No newline at end of file diff --git a/src/struct/config/config.js b/src/struct/config/config.js index 66707151..095bc424 100644 --- a/src/struct/config/config.js +++ b/src/struct/config/config.js @@ -1,9 +1,15 @@ +require('dotenv/config'); + module.exports = { //credentials token: process.env.TOKEN, - api_key: process.env.API_KEY, + devToken: process.env.DEVTOKEN, + dblKey: process.env.DBLKEY, + api_key: process.env.GOOGLE_API_KEY, //channels debug_channel: "634718645188034560", + primary_test_channel: "617633098296721409", + secondary_test_channel: "570531724002328577", devId: "360363051792203779", //misc embedColor: "#B127CD", @@ -13,7 +19,7 @@ module.exports = { dblApi: false, saveDB: false, //db values - prefix: "-", + prefix: "*", defaultVolume: 5, permissions: false, dj: false, diff --git a/src/struct/funcs/ffmpeg.js b/src/struct/funcs/ffmpeg.js index d1a01e25..594f0f3d 100644 --- a/src/struct/funcs/ffmpeg.js +++ b/src/struct/funcs/ffmpeg.js @@ -1,6 +1,6 @@ module.exports = async function (client) { try { - await client.channels.get('570531724002328577').join() + await client.channels.get(client.configs.secondary_test_channel).join() } catch (error) { client.channels.get(client.config.debug_channel).send("Error detected: " + error); } diff --git a/src/struct/funcs/msToTime.js b/src/struct/funcs/msToTime.js index 87a16ab3..cfb3192f 100644 --- a/src/struct/funcs/msToTime.js +++ b/src/struct/funcs/msToTime.js @@ -1,11 +1,15 @@ -module.exports = function msToTime(duration) { - var seconds = Math.floor((duration / 1000) % 60), - minutes = Math.floor((duration / (1000 * 60)) % 60), - hours = Math.floor((duration / (1000 * 60 * 60)) % 24); +module.exports = function msToTime(duration, format) { + if (format = "hh:mm:ss") { + var seconds = Math.floor((duration / 1000) % 60), + minutes = Math.floor((duration / (1000 * 60)) % 60), + hours = Math.floor((duration / (1000 * 60 * 60)) % 24); - hours = (hours < 10) ? "0" + hours : hours; - minutes = (minutes < 10) ? "0" + minutes : minutes; - seconds = (seconds < 10) ? "0" + seconds : seconds; + hours = (hours < 10) ? "0" + hours : hours; + minutes = (minutes < 10) ? "0" + minutes : minutes; + seconds = (seconds < 10) ? "0" + seconds : seconds; - return `${hours}:${minutes}:${seconds}`; + return `${hours}:${minutes}:${seconds}`; + } else if (format = "dd:hh:mm") { + + } } \ No newline at end of file