From 59cbc8b474425225f7f188ce54bc19d5f1193ecb Mon Sep 17 00:00:00 2001 From: Thongrapee Panyapatiphan Date: Sat, 22 Jan 2022 01:50:57 +0700 Subject: Announce current song (#470) Co-authored-by: Max Isom --- src/commands/queue.ts | 60 ++++----------------------------------------------- 1 file changed, 4 insertions(+), 56 deletions(-) (limited to 'src/commands/queue.ts') diff --git a/src/commands/queue.ts b/src/commands/queue.ts index 58d6377..79285b1 100644 --- a/src/commands/queue.ts +++ b/src/commands/queue.ts @@ -1,15 +1,9 @@ -import {Message, MessageEmbed} from 'discord.js'; -import getYouTubeID from 'get-youtube-id'; +import {Message} from 'discord.js'; import {inject, injectable} from 'inversify'; import {TYPES} from '../types.js'; import PlayerManager from '../managers/player.js'; -import {STATUS} from '../services/player.js'; import Command from '.'; -import getProgressBar from '../utils/get-progress-bar.js'; -import errorMsg from '../utils/error-msg.js'; -import {prettyTime} from '../utils/time.js'; - -const PAGE_SIZE = 10; +import {buildQueueEmbed} from '../utils/build-embed.js'; @injectable() export default class implements Command { @@ -29,54 +23,8 @@ export default class implements Command { public async execute(msg: Message, args: string []): Promise { const player = this.playerManager.get(msg.guild!.id); - const currentlyPlaying = player.getCurrent(); - - if (currentlyPlaying) { - const queueSize = player.queueSize(); - const queuePage = args[0] ? parseInt(args[0], 10) : 1; - - const maxQueuePage = Math.ceil((queueSize + 1) / PAGE_SIZE); - - if (queuePage > maxQueuePage) { - await msg.channel.send(errorMsg('the queue isn\'t that big')); - return; - } - - const embed = new MessageEmbed(); - - embed.setTitle(currentlyPlaying.title); - embed.setURL(`https://www.youtube.com/watch?v=${currentlyPlaying.url.length === 11 ? currentlyPlaying.url : getYouTubeID(currentlyPlaying.url) ?? ''}`); - - let description = player.status === STATUS.PLAYING ? '⏹️' : '▶️'; - description += ' '; - description += getProgressBar(20, player.getPosition() / currentlyPlaying.length); - description += ' '; - description += `\`[${prettyTime(player.getPosition())}/${currentlyPlaying.isLive ? 'live' : prettyTime(currentlyPlaying.length)}]\``; - description += ' 🔉'; - description += player.isQueueEmpty() ? '' : '\n\n**Next up:**'; - - embed.setDescription(description); - - let footer = `Source: ${currentlyPlaying.artist}`; - - if (currentlyPlaying.playlist) { - footer += ` (${currentlyPlaying.playlist.title})`; - } - - embed.setFooter({text: footer}); - - const queuePageBegin = (queuePage - 1) * PAGE_SIZE; - const queuePageEnd = queuePageBegin + PAGE_SIZE; - - player.getQueue().slice(queuePageBegin, queuePageEnd).forEach((song, i) => { - embed.addField(`${(i + 1 + queuePageBegin).toString()}/${queueSize.toString()}`, song.title, false); - }); - - embed.addField('Page', `${queuePage} out of ${maxQueuePage}`, false); + const embed = buildQueueEmbed(player, args[0] ? parseInt(args[0], 10) : 1); - await msg.channel.send({embeds: [embed]}); - } else { - await msg.channel.send('queue empty'); - } + await msg.channel.send({embeds: [embed]}); } } -- cgit v1.2.3