aboutsummaryrefslogtreecommitdiff
path: root/src/commands/queue.ts
diff options
context:
space:
mode:
authorThongrapee Panyapatiphan <[email protected]>2022-01-22 01:50:57 +0700
committerGitHub <[email protected]>2022-01-21 12:50:57 -0600
commit59cbc8b474425225f7f188ce54bc19d5f1193ecb (patch)
treee218db77455d935fed39e112dcd1807d53ea8352 /src/commands/queue.ts
parentda72cd708bcfbba6e0a91da4878aaef10d2532e2 (diff)
downloadmuse-59cbc8b474425225f7f188ce54bc19d5f1193ecb.tar.xz
muse-59cbc8b474425225f7f188ce54bc19d5f1193ecb.zip
Announce current song (#470)
Co-authored-by: Max Isom <[email protected]>
Diffstat (limited to 'src/commands/queue.ts')
-rw-r--r--src/commands/queue.ts60
1 files changed, 4 insertions, 56 deletions
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<void> {
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]});
}
}