From 09eddf27c717a958824efc1f8414eb5da3845ac8 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Wed, 24 Jun 2020 11:28:38 +0200 Subject: [PATCH] :sparkles: Fix createProgressBar method --- src/Player.js | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/Player.js b/src/Player.js index 242ecd6..c4d1d68 100644 --- a/src/Player.js +++ b/src/Player.js @@ -650,6 +650,31 @@ class Player { }) } + /** + * Creates progress bar of the current song + * @param {Discord.Snowflake} guildID + * @returns {String} + */ + createProgressBar (guildID) { + // Gets guild queue + const queue = this.queues.find((g) => g.guildID === guildID) + if (!queue) return + // Stream time of the dispatcher + const currentStreamTime = queue.voiceConnection.dispatcher.streamTime + // Total stream time + const totalTime = queue.playing.durationMS + // Stream progress + const index = Math.round((currentStreamTime / totalTime) * 15) + // conditions + if ((index >= 1) && (index <= 15)) { + const bar = '▬▬▬▬▬▬▬▬▬▬▬▬▬▬'.split('') + bar.splice(index, 0, '🔘') + return bar.join('') + } else { + return '🔘▬▬▬▬▬▬▬▬▬▬▬▬▬▬' + } + } + /** * Handle the voice state update event * @ignore @@ -674,27 +699,6 @@ class Player { queue.emit('channelEmpty') } } - - /** - * Creates progress bar of the current song - * @param {Queue} queue Queue of the current server - * @returns {String} - */ - createProgressBar(queue) { - // stream time of the dispatcher - const currentStreamTime = queue.voiceConnection.dispatcher.streamTime - // total stream length - const totalLength = queue.tracks[0].durationMS - // stream progress - let index = Math.round((currentStreamTime / totalLength) * 15) - // conditions - if ((index >= 1) && (index <= 15)) { - let bar = `▬▬▬▬▬▬▬▬▬▬▬▬▬▬`.split("") - return bar.splice(index, 0, "🔘").join("") - } else { - return `🔘▬▬▬▬▬▬▬▬▬▬▬▬▬▬` - } - } /** * Play a stream in a channel