diff --git a/package.json b/package.json index 8a10c49..40e60a9 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dependencies": { "discord-ytdl-core": "^4.0.2", "merge-options": "^2.0.0", + "moment": "^2.27.0", "node-fetch": "^2.6.0", "spotify-url-info": "^1.3.1", "ytpl": "^0.2.4", diff --git a/src/Player.js b/src/Player.js index 82caede..2f5756d 100644 --- a/src/Player.js +++ b/src/Player.js @@ -3,6 +3,7 @@ const Discord = require('discord.js') const ytsr = require('ytsr') const ytpl = require('ytpl') const spotify = require('spotify-url-info') +const moment = require('moment') const Queue = require('./Queue') const Track = require('./Track') const Util = require('./Util') @@ -434,25 +435,36 @@ class Player extends EventEmitter { }) } - createProgressBar (message) { + createProgressBar (message, options) { // Gets guild queue const queue = this.queues.get(message.guild.id) if (!queue) return + const timecodes = options && typeof options === 'object' ? options.timecodes : false // Stream time of the dispatcher const currentStreamTime = queue.voiceConnection.dispatcher ? queue.voiceConnection.dispatcher.streamTime + queue.additionalStreamTime : 0 // Total stream time - const totalTime = queue.tracks[0].durationMS + 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('') + if (timecodes) { + const currentTimecode = (currentStreamTime >= 3600000 ? moment(currentStreamTime).format('H:mm:ss') : moment(currentStreamTime).format('m:ss')) + return `${currentTimecode} ┃ ${bar.join('')} ┃ ${queue.playing.duration}` + } else { + return `${bar.join('')}` + } } else { - return '🔘▬▬▬▬▬▬▬▬▬▬▬▬▬▬' + if (timecodes) { + const currentTimecode = (currentStreamTime >= 3600000 ? moment(currentStreamTime).format('H:mm:ss') : moment(currentStreamTime).format('m:ss')) + return `${currentTimecode} ┃ 🔘▬▬▬▬▬▬▬▬▬▬▬▬▬▬ ┃ ${queue.playing.duration}` + } else { + return '🔘▬▬▬▬▬▬▬▬▬▬▬▬▬▬' + } } }