From 3842f30bff69e9aeba41d649d3ded23f760cc3bc Mon Sep 17 00:00:00 2001 From: MatteZ02 <47610069+MatteZ02@users.noreply.github.com> Date: Tue, 30 Jun 2020 21:08:18 +0300 Subject: [PATCH] fixes --- src/commands/settings.js | 3 +-- src/commands/settings/reset.js | 2 +- src/events/clientEvents/guildCreate.js | 4 +-- src/events/clientEvents/ready.js | 2 +- src/events/dispatcherEvents/finish.js | 36 ++++++++++++++++++-------- src/struct/config/config.js | 7 +++-- src/struct/config/messages.js | 2 +- src/struct/funcs/checkDB.js | 6 ++--- src/struct/funcs/saveDB.js | 2 +- 9 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/commands/settings.js b/src/commands/settings.js index aad7dbd0..4c9ee169 100644 --- a/src/commands/settings.js +++ b/src/commands/settings.js @@ -53,7 +53,6 @@ module.exports = { client.messages.settingsAutoPlayDesc, true ) - .addField() .setFooter(footer) .setAuthor(client.user.username, client.user.displayAvatarURL) .setColor(client.config.embedColor); @@ -81,4 +80,4 @@ module.exports = { return msg.channel.send(embed); } }, -}; \ No newline at end of file +}; diff --git a/src/commands/settings/reset.js b/src/commands/settings/reset.js index 2dcb43af..4f27513d 100644 --- a/src/commands/settings/reset.js +++ b/src/commands/settings/reset.js @@ -11,7 +11,7 @@ module.exports = { bass: client.config.bass, blacklist: [], premium: false, - playSimilar: client.config.playSimilar, + autoPlay: client.config.autoPlay, }; msg.channel.send(client.messages.reset); } diff --git a/src/events/clientEvents/guildCreate.js b/src/events/clientEvents/guildCreate.js index f7efaaf8..6c214dea 100644 --- a/src/events/clientEvents/guildCreate.js +++ b/src/events/clientEvents/guildCreate.js @@ -11,7 +11,7 @@ module.exports = { bass: client.config.bass, blacklist: [], premium: false, - playSimilar: client.config.playSimilar, + autoPlay: client.config.autoPlay, }); client.global.db.guilds[guild.id] = { prefix: client.config.prefix, @@ -23,7 +23,7 @@ module.exports = { bass: client.config.bass, blacklist: [], premium: false, - playSimilar: client.config.playSimilar, + autoPlay: client.config.autoPlay, }; }, }; \ No newline at end of file diff --git a/src/events/clientEvents/ready.js b/src/events/clientEvents/ready.js index 205dc107..688d68fe 100644 --- a/src/events/clientEvents/ready.js +++ b/src/events/clientEvents/ready.js @@ -21,7 +21,7 @@ module.exports = { bass: client.config.bass, blacklist: [], premium: true, - playSimilar: client.config.playSimilar, + autoPlay: client.config.autoPlay, }; }); } diff --git a/src/events/dispatcherEvents/finish.js b/src/events/dispatcherEvents/finish.js index cab13a46..9c8e71ab 100644 --- a/src/events/dispatcherEvents/finish.js +++ b/src/events/dispatcherEvents/finish.js @@ -19,11 +19,20 @@ module.exports = { queue.votes = 0; queue.voters = []; if (queue.endReason !== "replay") { - if (queue.endReason === "previous") queue.songs.unshift(queue.prevSongs.pop()) - if (queue.endReason !== "previous") queue.prevSongs.push(queue.songs.shift()); - if (client.global.db.guilds[guild.id].playSimilar && !queue.songs[0] && queue.endReason !== "stop") { - const prevSongs = queue.prevSongs.filter(song => song.type == "spotify"); - if (prevSongs.length >= 0) return findSimilar(client, queue, prevSongs, guild); + if (queue.endReason === "previous") + queue.songs.unshift(queue.prevSongs.pop()); + if (queue.endReason !== "previous") + queue.prevSongs.push(queue.songs.shift()); + if ( + client.global.db.guilds[guild.id].autoPlay && + !queue.songs[0] && + queue.endReason !== "stop" + ) { + const prevSongs = queue.prevSongs.filter( + (song) => song.type == "spotify" + ); + if (prevSongs.length >= 0) + return findSimilar(client, queue, prevSongs, guild); } } } @@ -33,8 +42,8 @@ module.exports = { function findSimilar(client, queue, prevSongs, guild) { let retries = 0; - const query = prevSongs[Math.floor(Math.random() * Math.floor(prevSongs.length))]; - if (!query) return client.funcs.play(guild, queue.songs[0], client, 0, true); + const query = + prevSongs[Math.floor(Math.random() * Math.floor(prevSongs.length))]; similarSongs.find({ title: query.track.name, artist: query.track.artists[0].name, @@ -44,16 +53,21 @@ function findSimilar(client, queue, prevSongs, guild) { youtubeAPIKey: client.config.api_key, }, async function (err, songs) { - if (err) return queue.textChannel.send(err.message); + if (err) { + console.log(err.message); + return queue.textChannel.send(client.messages.error); + } if (songs[0]) { - const random = Math.floor(Math.random() * Math.floor(songs.length)) - const songInfo = await ytdl.getInfo(`https://www.youtube.com/watch?v=${songs[random].youtubeId}`); + const random = Math.floor(Math.random() * Math.floor(songs.length)); + const songInfo = await ytdl.getInfo( + `https://www.youtube.com/watch?v=${songs[random].youtubeId}` + ); queue.songs.push({ title: Discord.Util.escapeMarkdown(songInfo.videoDetails.title), url: `https://www.youtube.com/watch?v=${songs[random].youtubeId}`, author: {}, type: "ytdl", - info: songInfo.videoDetails + info: songInfo.videoDetails, }); client.funcs.play(guild, queue.songs[0], client, 0, true); } else { diff --git a/src/struct/config/config.js b/src/struct/config/config.js index 82b4d150..6bab0501 100644 --- a/src/struct/config/config.js +++ b/src/struct/config/config.js @@ -22,8 +22,7 @@ module.exports = { secondary_test_channel: "570531724002328577", devId: "360363051792203779", embedColor: "#b50002", - invite: - "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot", + invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot", supportServer: "https://discord.gg/rvHuJtB", devMode: false, api: false, @@ -41,7 +40,7 @@ module.exports = { djrole: null, startPlaying: true, bass: 1, - playSimilar: false, + autoPlay: false, }; module.exports.streamConfig = { @@ -100,4 +99,4 @@ module.exports.emojis = { stop: "<:stop:674685626108477519> ", stopWatch: ":stopwatch: ", volumeHigh: "<:volumehigh:674685637626167307> ", -}; +}; \ No newline at end of file diff --git a/src/struct/config/messages.js b/src/struct/config/messages.js index f8723b80..5d1ea9ed 100644 --- a/src/struct/config/messages.js +++ b/src/struct/config/messages.js @@ -5,7 +5,7 @@ const { module.exports = { emojis: emojis, albumAdded: emojis.green_check_mark + - "Album: **%TITLE%** has been added to the queue!", + "Album has been added to the queue!", alreadyPaused: emojis.redx + "The music is already paused!", alreadyVoted: emojis.redx + "You have already voted to skip!", announceSongs: emojis.megaPhone + "Current setting:", diff --git a/src/struct/funcs/checkDB.js b/src/struct/funcs/checkDB.js index fa806c77..b42be30d 100644 --- a/src/struct/funcs/checkDB.js +++ b/src/struct/funcs/checkDB.js @@ -11,7 +11,7 @@ module.exports = async function (client) { bass: client.config.bass, blacklist: [], premium: false, - playSimilar: client.config.playSimilar, + autoPlay: client.config.autoPlay, }); client.global.db.guilds[guild.id] = { prefix: client.config.prefix, @@ -23,7 +23,7 @@ module.exports = async function (client) { bass: client.config.bass, blacklist: [], premium: false, - playSimilar: client.config.playSimilar, + autoPlay: client.config.autoPlay, }; return; } @@ -47,6 +47,6 @@ module.exports = async function (client) { client.global.db.guilds[guild.id].blacklist = []; if (!client.global.db.guilds[guild.id].premium) client.global.db.guilds[guild.id].premium = false; - if (!client.global.db.guilds[guild.id].playSimilar) client.global.db.guilds[guild.id].playSimilar = client.config.playSimilar + if (!client.global.db.guilds[guild.id].autoPlay) client.global.db.guilds[guild.id].autoPlay = client.config.autoPlay }); }; \ No newline at end of file diff --git a/src/struct/funcs/saveDB.js b/src/struct/funcs/saveDB.js index e7c2dd83..5a68f3b3 100644 --- a/src/struct/funcs/saveDB.js +++ b/src/struct/funcs/saveDB.js @@ -12,7 +12,7 @@ module.exports = async function (client) { bass: client.global.db.guilds[guild.id].bass, blacklist: client.global.db.guilds[guild.id].blacklist, premium: client.global.db.guilds[guild.id].premium, - playSimilar: client.global.db.guilds[guild.id].playSimilar + autoPlay: client.global.db.guilds[guild.id].autoPlay }); }); }