diff options
| author | Max Isom <[email protected]> | 2021-04-23 12:30:31 -0400 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2021-04-23 12:30:31 -0400 |
| commit | 5d92d4ed541df091526e8c918737cd245ea24db3 (patch) | |
| tree | 91890fa5233b78b0afd1c8135f02621f3e3da7db /src | |
| parent | 531da56dd071cdedf9177fea68597a49cb5bfba4 (diff) | |
| download | muse-5d92d4ed541df091526e8c918737cd245ea24db3.tar.xz muse-5d92d4ed541df091526e8c918737cd245ea24db3.zip | |
Allow skipping multiple tracks
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands/skip.ts | 15 | ||||
| -rw-r--r-- | src/services/natural-language-commands.ts | 2 | ||||
| -rw-r--r-- | src/services/player.ts | 12 |
3 files changed, 19 insertions, 10 deletions
diff --git a/src/commands/skip.ts b/src/commands/skip.ts index 677ad03..b12729b 100644 --- a/src/commands/skip.ts +++ b/src/commands/skip.ts @@ -11,7 +11,8 @@ export default class implements Command { public name = 'skip'; public aliases = ['s']; public examples = [ - ['skip', 'skips the current song'] + ['skip', 'skips the current song'], + ['skip 2', 'skips the next 2 songs'] ]; public requiresVC = true; @@ -22,14 +23,22 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(msg: Message, _: string []): Promise<void> { + public async execute(msg: Message, args: string []): Promise<void> { + let numToSkip = 1; + + if (args.length === 1) { + if (!Number.isNaN(parseInt(args[0], 10))) { + numToSkip = parseInt(args[0], 10); + } + } + const player = this.playerManager.get(msg.guild!.id); const loader = new LoadingMessage(msg.channel as TextChannel); try { await loader.start(); - await player.forward(); + await player.forward(numToSkip); await loader.stop('keep \'er movin\''); } catch (_: unknown) { diff --git a/src/services/natural-language-commands.ts b/src/services/natural-language-commands.ts index 45605e1..829e2d1 100644 --- a/src/services/natural-language-commands.ts +++ b/src/services/natural-language-commands.ts @@ -63,7 +63,7 @@ export default class { if (isPlaying) { oldPosition = player.getPosition(); - player.manualForward(); + player.manualForward(1); } await player.seek(position); diff --git a/src/services/player.ts b/src/services/player.ts index d149826..63f6445 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -161,8 +161,8 @@ export default class { this.stopTrackingPosition(); } - async forward(): Promise<void> { - this.manualForward(); + async forward(skip: number): Promise<void> { + this.manualForward(skip); try { if (this.getCurrent() && this.status !== STATUS.PAUSED) { @@ -177,9 +177,9 @@ export default class { } } - manualForward(): void { - if (this.queuePosition < this.queue.length) { - this.queuePosition++; + manualForward(skip: number): void { + if ((this.queuePosition + skip - 1) < this.queue.length) { + this.queuePosition += skip; this.positionInSeconds = 0; this.stopTrackingPosition(); } else { @@ -440,7 +440,7 @@ export default class { private async onVoiceConnectionSpeaking(isSpeaking: boolean): Promise<void> { // Automatically advance queued song at end if (!isSpeaking && this.status === STATUS.PLAYING) { - await this.forward(); + await this.forward(1); } } } |
