aboutsummaryrefslogtreecommitdiff
path: root/src/commands/loop-queue.ts
diff options
context:
space:
mode:
authorReynard G <[email protected]>2024-01-16 19:44:44 -0600
committerGitHub <[email protected]>2024-01-16 19:44:44 -0600
commit769f9da8a21ca467964142f57c79a0f482232900 (patch)
treee5bc1bf82630db97d6d871597294eeb1afc4da96 /src/commands/loop-queue.ts
parent45bdbd1494a59f590ec7a29a65df022ae6af05ab (diff)
downloadmuse-769f9da8a21ca467964142f57c79a0f482232900.tar.xz
muse-769f9da8a21ca467964142f57c79a0f482232900.zip
Add /loop-queue command (#989)
Diffstat (limited to 'src/commands/loop-queue.ts')
-rw-r--r--src/commands/loop-queue.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/commands/loop-queue.ts b/src/commands/loop-queue.ts
new file mode 100644
index 0000000..47b9adf
--- /dev/null
+++ b/src/commands/loop-queue.ts
@@ -0,0 +1,42 @@
+import {ChatInputCommandInteraction} from 'discord.js';
+import {TYPES} from '../types.js';
+import {inject, injectable} from 'inversify';
+import PlayerManager from '../managers/player.js';
+import Command from '.';
+import {SlashCommandBuilder} from '@discordjs/builders';
+import {STATUS} from '../services/player.js';
+
+@injectable()
+export default class implements Command {
+ public readonly slashCommand = new SlashCommandBuilder()
+ .setName('loop-queue')
+ .setDescription('toggle looping the entire queue');
+
+ public requiresVC = true;
+
+ private readonly playerManager: PlayerManager;
+
+ constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
+ this.playerManager = playerManager;
+ }
+
+ public async execute(interaction: ChatInputCommandInteraction): Promise<void> {
+ const player = this.playerManager.get(interaction.guild!.id);
+
+ if (player.status === STATUS.IDLE) {
+ throw new Error('no songs to loop!');
+ }
+
+ if (player.queueSize() < 2) {
+ throw new Error('not enough songs to loop a queue!');
+ }
+
+ if (player.loopCurrentSong) {
+ player.loopCurrentSong = false;
+ }
+
+ player.loopCurrentQueue = !player.loopCurrentQueue;
+
+ await interaction.reply((player.loopCurrentQueue ? 'looped queue :)' : 'stopped looping queue :('));
+ }
+}