aboutsummaryrefslogtreecommitdiff
path: root/src/commands/queue.ts
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2022-01-26 12:58:33 -0500
committerMax Isom <[email protected]>2022-01-26 12:58:33 -0500
commitaacb107f43db6b8c53d160b5913701959f81cf09 (patch)
treea63d0717d03c84987b69d5af1c1f5b45ef019a4a /src/commands/queue.ts
parent09665af53ee1b1903fc9ea719722aa5dfdc26325 (diff)
parentaf05210be4a8857ea707866192efa79b3945b314 (diff)
downloadmuse-aacb107f43db6b8c53d160b5913701959f81cf09.tar.xz
muse-aacb107f43db6b8c53d160b5913701959f81cf09.zip
Merge branch 'master' into feature/slash-commands
Diffstat (limited to 'src/commands/queue.ts')
-rw-r--r--src/commands/queue.ts68
1 files changed, 10 insertions, 58 deletions
diff --git a/src/commands/queue.ts b/src/commands/queue.ts
index 9768f58..4d75d42 100644
--- a/src/commands/queue.ts
+++ b/src/commands/queue.ts
@@ -1,80 +1,32 @@
-import {ButtonInteraction, CommandInteraction} from 'discord.js';
+import {CommandInteraction} from 'discord.js';
import {SlashCommandBuilder} from '@discordjs/builders';
import {inject, injectable} from 'inversify';
import {TYPES} from '../types.js';
import PlayerManager from '../managers/player.js';
-import UpdatingQueueEmbedManager from '../managers/updating-queue-embed.js';
-import {BUTTON_IDS} from '../services/updating-queue-embed.js';
import Command from '.';
+import {buildQueueEmbed} from '../utils/build-embed.js';
@injectable()
export default class implements Command {
public readonly slashCommand = new SlashCommandBuilder()
.setName('queue')
- .setDescription('show the current queue');
-
- public readonly handledButtonIds = Object.values(BUTTON_IDS);
+ .setDescription('show the current queue')
+ .addIntegerOption(option => option
+ .setName('page')
+ .setDescription('page of queue to show [default: 1]')
+ .setRequired(false));
private readonly playerManager: PlayerManager;
- private readonly updatingQueueEmbedManager: UpdatingQueueEmbedManager;
- constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager, @inject(TYPES.Managers.UpdatingQueueEmbed) updatingQueueEmbedManager: UpdatingQueueEmbedManager) {
+ constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
this.playerManager = playerManager;
- this.updatingQueueEmbedManager = updatingQueueEmbedManager;
}
public async execute(interaction: CommandInteraction) {
- const embed = this.updatingQueueEmbedManager.get(interaction.guild!.id);
-
- await embed.createFromInteraction(interaction);
- }
-
- public async handleButtonInteraction(interaction: ButtonInteraction) {
const player = this.playerManager.get(interaction.guild!.id);
- const embed = this.updatingQueueEmbedManager.get(interaction.guild!.id);
-
- const buttonId = interaction.customId as keyof typeof this.handledButtonIds;
-
- // Not entirely sure why this is necessary.
- // We don't wait for the Promise to resolve here to avoid blocking the
- // main logic. However, we need to wait for the Promise to be resolved before
- // throwing as otherwise a race condition pops up when bot.ts tries updating
- // the interaction.
- const deferedUpdatePromise = interaction.deferUpdate();
-
- try {
- switch (buttonId) {
- case BUTTON_IDS.TRACK_BACK:
- await player.back();
- break;
-
- case BUTTON_IDS.TRACK_FORWARD:
- await player.forward(1);
- break;
-
- case BUTTON_IDS.PAUSE:
- player.pause();
- break;
-
- case BUTTON_IDS.PLAY:
- await player.play();
- break;
-
- case BUTTON_IDS.PAGE_BACK:
- await embed.pageBack();
- break;
-
- case BUTTON_IDS.PAGE_FORWARD:
- await embed.pageForward();
- break;
- default:
- throw new Error('unknown customId');
- }
- } catch (error: unknown) {
- await deferedUpdatePromise;
+ const embed = buildQueueEmbed(player, interaction.options.getInteger('page') ?? 1);
- throw error;
- }
+ await interaction.reply({embeds: [embed]});
}
}