diff --git a/commands/bass.js b/commands/bass.js new file mode 100644 index 00000000..db37961c --- /dev/null +++ b/commands/bass.js @@ -0,0 +1,22 @@ +module.exports = { + name: 'bass', + description: 'Bassboost command.', + alias: 'none', + usage: '', + cooldown: 5, + onlyDev: false, + 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(`:loud_sound: The current bass is: **${serverQueue.bass}**`); + const bass = parseFloat(args[1]); + if (client.funcs.check(client, msg, command)) { + if (isNaN(bass)) return msg.channel.send('<:redx:674263474704220182> I\'m sorry, But you need to enter a valid __number__.'); + if (bass > 100) return msg.channel.send('<:redx:674263474704220182> The max bass is `100`!'); + if (bass < 0) return msg.channel.send('<:redx:674263474704220182> The volume needs to be a positive number!'); + serverQueue.bass = bass; + return msg.channel.send(`<:volumehigh:674685637626167307> The bass level **${bass}** will be applied when the next song starts playing!`); + } + } +}; diff --git a/commands/disconnect.js b/commands/disconnect.js deleted file mode 100644 index 253dac3a..00000000 --- a/commands/disconnect.js +++ /dev/null @@ -1,33 +0,0 @@ -module.exports = { - name: 'disconnect', - alias: 'dc', - usage: '', - description: 'Disconnect the bot from a voice channel.', - onlyDev: true, - permission: 'MANAGE_CHANNELS', - category: 'util', - async execute(msg, args, client, Discord, prefix, command) { - const serverQueue = client.queue.get(msg.guild.id); - 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/commands/end.js b/commands/end.js new file mode 100644 index 00000000..114f06ef --- /dev/null +++ b/commands/end.js @@ -0,0 +1,13 @@ +module.exports = { + name: 'end', + alias: 'e', + usage: '', + description: 'end the queue', + onlyDev: true, + permission: 'dev', + category: 'util', + async execute(msg, args, client, Discord, prefix, command) { + client.queue.delete(guild.id); + msg.channel.send('Queue deleted!'); + } +}; diff --git a/commands/help.js b/commands/help.js index 6a39d073..c3c2f077 100644 --- a/commands/help.js +++ b/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 && !x.onlyDev).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/commands/reload.js b/commands/reload.js index 6023c61d..59baca52 100644 --- a/commands/reload.js +++ b/commands/reload.js @@ -22,9 +22,9 @@ module.exports = { const option = require(`./settings/${file}`); client.settingCmd.set(option.name, option); } - fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => { + /*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/remove.js b/commands/remove.js index 01574dfd..25cc14c8 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -10,7 +10,7 @@ module.exports = { const serverQueue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { if (!args[1]) return msg.channel.send('<:redx:674263474704220182> Please provide a song position in queue for me to remove!'); - const pos = parseInt(args[1] - 1); + const pos = parseInt(args[1]); if (isNaN(pos)) return msg.channel.send('<:redx:674263474704220182> You need to enter a number!'); if (pos < 1) return msg.channel.send('<:redx:674263474704220182> That songs does not exist!'); if (pos > serverQueue.songs.length) return msg.channel.send(`<:redx:674263474704220182> There is only ${serverQueue.songs.length} amount of songs in the queue!`); diff --git a/commands/restart.js b/commands/restart.js index e7ad8d25..148b9cf4 100644 --- a/commands/restart.js +++ b/commands/restart.js @@ -7,9 +7,8 @@ module.exports = { permission: 'none', category: 'util', async execute(msg, args, client, Discord, prefix, command) { - client.destroy() - const MusicClient = require('../struct/client.js'); - const newClient = new MusicClient({}); + client.destroy(); + require('../index.js'); msg.channel.send('restarted!'); } }; diff --git a/commands/seek.js b/commands/seek.js index b7af850c..6b81fc4c 100644 --- a/commands/seek.js +++ b/commands/seek.js @@ -17,6 +17,7 @@ module.exports = { if (pos < 0) return msg.channel.send('<:redx:674263474704220182> The seeking point needs to be a positive number!'); if (pos > data.length_seconds) return msg.channel.send(`<:redx:674263474704220182> The lenght of this song is ${data.length_seconds} seconds! You can't seek further than that!`); serverQueue.connection.dispatcher.end('seek'); + serverQueue.endReason = "seek"; client.funcs.play(msg.guild, serverQueue.songs[0], client, msg, pos, false); } } diff --git a/commands/settings.js b/commands/settings.js index 113dda14..5741fba1 100644 --- a/commands/settings.js +++ b/commands/settings.js @@ -14,6 +14,7 @@ module.exports = { .addField('permissions', 'Change whether to require permissions to use eg `skip, stop, pause, loop, etc...`', true) .addField('setdj', 'Set a DJ role. This will allow chosen users to freely use all Musix commands. This will automatically set the `permissions` settings to true in order for the `DJ` role to have effect!', true) .addField('announcesongs', 'Whether to announce songs that start playing or not.') + .addField('bass', 'Change the default bass level', true) .setFooter(`how to use: ${prefix}settings `) .setAuthor(client.user.username, client.user.displayAvatarURL) .setColor(client.embedColor) diff --git a/commands/settings/bass.js b/commands/settings/bass.js new file mode 100644 index 00000000..374cca2c --- /dev/null +++ b/commands/settings/bass.js @@ -0,0 +1,14 @@ +module.exports = { + name: 'bass', + async execute(msg, args, client, Discord, prefix) { + if (!args[2]) return msg.channel.send('Currect bass level: ' + client.global.db.guilds[msg.guild.id].bass); + if (args[2] === "false") { + client.global.db.guilds[msg.guild.id].bass = false; + msg.channel.send(`Bass is now false!`); + } + const level = parseInt(args[2]); + if (isNaN(level)) return msg.channel.send('You need to provide a number?'); + client.global.db.guilds[msg.guild.id].bass = level; + msg.channel.send(`Bass level is now ${level}!`); + } +}; \ No newline at end of file diff --git a/commands/skip.js b/commands/skip.js index 906636f3..f46ef98a 100644 --- a/commands/skip.js +++ b/commands/skip.js @@ -28,6 +28,7 @@ module.exports = { }; function skipSong(serverQueue, msg) { msg.channel.send('<:skip:674685614221688832> Skipped the song!'); + serverQueue.endReason = "skip"; serverQueue.connection.dispatcher.end('skipped'); }; function vote(serverQueue, msg) { diff --git a/commands/skipto.js b/commands/skipto.js index 3ff3a50a..f82ba711 100644 --- a/commands/skipto.js +++ b/commands/skipto.js @@ -10,7 +10,7 @@ module.exports = { const serverQueue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { if (!args[1]) return msg.channel.send(`<:redx:674263474704220182> correct usage: \`${command.usage}\``); - const point = parseInt(args[1]); + const point = parseInt(args[1] - 1); if (isNaN(point)) return msg.channel.send('<:redx:674263474704220182> I\'m sorry, But you need to enter a valid __number__.'); if (point > serverQueue.songs.size) return msg.channel.send('<:redx:674263474704220182> That song does not exist!'); if (point < 1) return msg.channel.send('<:redx:674263474704220182> You can\'t skip to the song currently playing!'); @@ -19,6 +19,7 @@ module.exports = { i++; serverQueue.songs.shift(); } + serverQueue.endReason = "skipto"; serverQueue.connection.dispatcher.end('skipto'); } } diff --git a/commands/status.js b/commands/status.js index 12c50461..fa54d530 100644 --- a/commands/status.js +++ b/commands/status.js @@ -8,7 +8,6 @@ module.exports = { category: 'info', execute(msg, args, client, Discord, prefix) { const uptime = client.funcs.msToTime(client.uptime, "dd:hh:mm:ss"); - const ping = Math.floor(client.ping * 10) / 10; msg.channel.send(' Pinging...').then(m => { const latency = m.createdTimestamp - msg.createdTimestamp; diff --git a/commands/stop.js b/commands/stop.js index 65986d4f..9d2ff1a1 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -11,6 +11,7 @@ module.exports = { if (client.funcs.check(client, msg, command)) { serverQueue.songs = []; serverQueue.looping = false; + serverQueue.endReason = "stop"; serverQueue.connection.dispatcher.end('Stopped'); msg.channel.send('<:stop:674685626108477519> Stopped the music!') } diff --git a/events/guildCreate.js b/events/guildCreate.js index d882ff5a..ad160211 100644 --- a/events/guildCreate.js +++ b/events/guildCreate.js @@ -8,6 +8,7 @@ module.exports = { dj: client.config.dj, djrole: client.config.djrole, startPlaying: client.config.startPlaying, + bass: client.config.bass, }); client.global.db.guilds[guild.id] = { prefix: client.config.prefix, @@ -16,6 +17,7 @@ module.exports = { dj: client.config.dj, djrole: client.config.djrole, startPlaying: client.config.startPlaying, + bass: client.config.bass, }; } } diff --git a/events/msg.js b/events/msg.js index 71f8edd1..b39a9089 100644 --- a/events/msg.js +++ b/events/msg.js @@ -21,7 +21,7 @@ module.exports = { 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('<:redx:674263474704220182> You are not allowed to do that!'); - 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 (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)!'); client.funcs.exe(msg, args, client, Discord, prefix, command); } } diff --git a/events/ready.js b/events/ready.js index 326ca683..35406f9b 100644 --- a/events/ready.js +++ b/events/ready.js @@ -3,6 +3,8 @@ const DBL = require("dblapi.js"); module.exports = { name: 'ready', async execute(client, Discord) { + const debugChannel = await client.channels.fetch(client.config.debug_channel); + client.debug_channel = debugChannel const remoteMusixGuildsData = await client.funcs.dbget('guilds', null, client); remoteMusixGuildsData.forEach(guildData => { client.global.db.guilds[guildData.id] = guildData.d; @@ -17,6 +19,7 @@ module.exports = { dj: client.config.dj, djrole: client.config.djrole, startPlaying: client.config.startPlaying, + bass: client.config.bass, }; }); } @@ -45,6 +48,7 @@ module.exports = { dj: client.global.db.guilds[guild.id].dj, djrole: client.global.db.guilds[guild.id].djrole, startPlaying: client.global.db.guilds[guild.id].startPlaying, + bass: client.global.db.guilds[guild.id].bass, }); }); } diff --git a/package.json b/package.json index daeb2c4e..0e1d24d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "musix", - "version": "1.0.0", + "version": "3.0.2", "description": "V3 for Musix the discord music bot", "main": "./index.js", "scripts": { @@ -18,7 +18,7 @@ "homepage": "https://github.com/MatteZ02/Musix-V3#readme", "dependencies": { "dblapi.js": "^2.3.1", - "discord.js": "github:discordjs/discord.js", + "discord.js": "^12.0.1", "dotenv": "^8.2.0", "ffmpeg": "0.0.4", "firebase": "^7.8.0", diff --git a/struct/client.js b/struct/client.js index 5334cdf2..ba446d00 100644 --- a/struct/client.js +++ b/struct/client.js @@ -68,6 +68,9 @@ module.exports = class extends Client { this.on('voiceStateUpdate', (newMember) => { require(`${events}voiceStateUpdate`).execute(this, newMember); }); + this.on('error', (error) => { + client.channels.fetch(client.config.debug_channel).send('Error: ' + error); + }); this.login(this.config.token).catch(err => console.log('Failed to login: ' + err)); } diff --git a/struct/config/config.js b/struct/config/config.js index 83ad36c6..de47ace3 100644 --- a/struct/config/config.js +++ b/struct/config/config.js @@ -15,8 +15,8 @@ module.exports = { embedColor: "#b50002", invite: "https://discordapp.com/api/oauth2/authorize?client_id=607266889537945605&permissions=3427328&redirect_uri=https%3A%2F%2Fdiscordapp.com%2Foauth2%2Fauthorize%3Fclient_id%3D607266889537945605%26%3Bscope%3Dbot%26%3Bpermissions%3D0&scope=bot", //Settings - devMode: false, - dblApi: true, + devMode: true, + dblApi: false, saveDB: true, //db values prefix: ">", @@ -26,4 +26,5 @@ module.exports = { dj: false, djrole: null, startPlaying: true, + bass: 1, } diff --git a/struct/config/queueConfig.js b/struct/config/queueConfig.js new file mode 100644 index 00000000..21a54e43 --- /dev/null +++ b/struct/config/queueConfig.js @@ -0,0 +1,17 @@ +module.exports = { + textChannel: null, + voiceChannel: null, + connection: null, + songs: [], + volume: null, + bass: null, + playing: false, + paused: false, + looping: false, + songLooping: false, + votes: 0, + voters: [], + votesNeeded: null, + time: 0, + endReason: null, +} \ No newline at end of file diff --git a/struct/funcs/exe.js b/struct/funcs/exe.js index 72dbabe1..5d01d27e 100644 --- a/struct/funcs/exe.js +++ b/struct/funcs/exe.js @@ -11,8 +11,7 @@ module.exports = function (msg, args, client, Discord, prefix, command) { .setTitle(`Musix ${error.toString()}`) .setDescription(error.stack.replace(/at /g, '**at **')) .setColor('#b50002'); - //client.fetchUser(client.config.devId).then(user => user.send(embed)).catch(console.error); - //client.channels.get(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 index 9a892098..e271c68d 100644 --- a/struct/funcs/ffmpeg.js +++ b/struct/funcs/ffmpeg.js @@ -3,6 +3,6 @@ module.exports = async function (client) { await client.channels.fetch(client.config.secondary_test_channel) .then(x => x.join()); } catch (error) { - client.channels.get(client.config.debug_channel).send("Error detected: " + error); + client.debug_channel.send("Error detected: " + error); } }; \ No newline at end of file diff --git a/struct/funcs/handleVideo.js b/struct/funcs/handleVideo.js index 2f7ba4b3..ce366697 100644 --- a/struct/funcs/handleVideo.js +++ b/struct/funcs/handleVideo.js @@ -6,28 +6,21 @@ module.exports = async function (video, msg, voiceChannel, client, playlist = fa url: `https://www.youtube.com/watch?v=${video.id}`, author: msg.author } + const serverQueue = client.queue.get(msg.guild.id); + if (serverQueue) { serverQueue.songs.push(song); if (playlist) return; return msg.channel.send(`<:green_check_mark:674265384777416705> **${song.title}** has been added to the queue!`); } - const construct = { - textChannel: msg.channel, - voiceChannel: voiceChannel, - connection: null, - songs: [], - volume: client.global.db.guilds[msg.guild.id].defaultVolume, - playing: false, - paused: false, - looping: false, - songLooping: false, - votes: 0, - voters: [], - votesNeeded: null, - time: 0, - }; + const construct = require("../config/queueConfig.js"); + construct.textChannel = msg.channel; + construct.voiceChannel = voiceChannel; + construct.volume = client.global.db.guilds[msg.guild.id].defaultVolume; + construct.bass = client.global.db.guilds[msg.guild.id].bass; + construct.songs.push(song); client.queue.set(msg.guild.id, construct); @@ -37,7 +30,7 @@ module.exports = async function (video, msg, voiceChannel, client, playlist = fa client.funcs.play(msg.guild, construct.songs[0], client, 0, true); } catch (error) { client.queue.delete(msg.guild.id); - //client.channels.get(client.config.debug_channel).send("Error with connecting to voice channel: " + error); + client.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/play.js b/struct/funcs/play.js index fc7fce79..954d237f 100644 --- a/struct/funcs/play.js +++ b/struct/funcs/play.js @@ -2,7 +2,6 @@ module.exports = async function (guild, song, client, seek, play) { const Discord = require('discord.js'); const ytdl = require('ytdl-core'); const getThumb = require('video-thumbnail-url'); - const prism = require('prism-media'); const serverQueue = client.queue.get(guild.id); if (!song) { @@ -13,15 +12,16 @@ module.exports = async function (guild, song, client, seek, play) { } const dispatcher = serverQueue.connection - .play(await ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25, volume: false }), { seek: seek, bitrate: 1024, passes: 10, volume: 1 }) - .on("finish", reason => { - client.dispatcher.finish(client, reason, guild); + .play(await ytdl(song.url, { filter: "audio", highWaterMark: 1 << 25, volume: false }), { seek: seek, bitrate: 1024, passes: 10, volume: 1, bassboost: serverQueue.bass }) + .on("end", () => { + client.dispatcher.finish(client, serverQueue.endReason, guild); }); dispatcher.on('start', () => { dispatcher.player.streamingData.pausedTime = 0; }); dispatcher.on('error', error => { console.error(error); + client.debug_channel.send('Error with the dispatcher: ' + error); serverQueue.voiceChannel.leave(); client.queue.delete(guild.id); return serverQueue.textChannel.send('<:redx:674263474704220182> An error has occured while playing music! The queue has been deleted.');