From ba5aaf12e582038fc0d2c5d0b669fee43cef6376 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Tue, 26 Oct 2021 14:05:07 +0300 Subject: [PATCH] show duration in queue and now playing --- src/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 5d6e12b..83970a7 100644 --- a/src/index.js +++ b/src/index.js @@ -23,7 +23,6 @@ bot.once('ready', () => { const prefix = ';'; const embedColor = 0xa0ffa5; const foggyImg = 'https://cdn.discordapp.com/attachments/789023763396165633/898908687299657728/552bb191-93e3-4eaa-b935-d5031f3845e7.gif'; -const ffprobeRegex = /Audio: ([^,\n]+), (\d+) ?Hz, ?([^,\n]+), ?([^,\n]+)(, ?([^,\n]+))?/; async function checkVoiceChannel(msg) { if (!msg.guild) return; @@ -157,6 +156,10 @@ function rawYTDLQueue(info) { return song; } +function formatTime(t) { + return `${Math.floor(t / 60).toString().padStart(2, '0')}:${Math.floor(t % 60).toString().padStart(2, '0')}` +} + async function queueUp(url, id) { if (!queue[id]) queue[id] = []; @@ -246,7 +249,7 @@ bot.on('messageCreate', async (msg) => { if (q.length === 0) { msg.channel.send('no songs queued!'); } else { - msg.channel.send('```' + q.map((m, i) => `${i === 0 ? 'now playing:' : i + '.'} ${m.title}`).join('\n') + '```'); + msg.channel.send('```' + q.map((m, i) => `${i === 0 ? 'now playing:' : i + '.'} ${m.title} ${(m.duration !== 0) ? formatTime(m.duration) : ''}`).join('\n') + '```'); } } else if (cmd === 'np' || cmd === 'nowplaying') { const song = (queue[msg.guild.id] || [])[0]; @@ -261,6 +264,7 @@ bot.on('messageCreate', async (msg) => { progressStr = '🔘 `buffering,,`'; } else { progressStr = `${'▬'.repeat(Math.floor(Math.abs(progress) * progressLength))}🔘${'▬'.repeat(Math.floor((1 - Math.abs(progress)) * progressLength))}`; + progressStr += `\n\`${formatTime((Date.now() - (playerStartTime[msg.guild.id] || 0)) / 1000)}\`/\`${formatTime(song.duration)}\`` } let embed = new Discord.MessageEmbed()