diff options
| author | Max Isom <[email protected]> | 2022-03-13 18:30:36 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-03-13 17:30:36 -0500 |
| commit | 6c00727a4a22e28c45711b301c7bf4dbaff90117 (patch) | |
| tree | c23696f95ce0ef9a4f31586af96021329dedf292 /src/commands | |
| parent | 03d5cfffd1a9cd8a9977de0d24cce1be0cc73210 (diff) | |
| download | muse-6c00727a4a22e28c45711b301c7bf4dbaff90117.tar.xz muse-6c00727a4a22e28c45711b301c7bf4dbaff90117.zip | |
Parse duration strings for /fseek and /seek (#565)
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/fseek.ts | 15 | ||||
| -rw-r--r-- | src/commands/seek.ts | 5 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/commands/fseek.ts b/src/commands/fseek.ts index 985a7c4..3e34438 100644 --- a/src/commands/fseek.ts +++ b/src/commands/fseek.ts @@ -5,15 +5,16 @@ import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; import Command from '.'; import {prettyTime} from '../utils/time.js'; +import durationStringToSeconds from '../utils/duration-string-to-seconds.js'; @injectable() export default class implements Command { public readonly slashCommand = new SlashCommandBuilder() .setName('fseek') .setDescription('seek forward in the current song') - .addNumberOption(option => option - .setName('seconds') - .setDescription('the number of seconds to skip forward') + .addStringOption(option => option + .setName('time') + .setDescription('an interval expression or number of seconds (1m, 30s, 100)') .setRequired(true)); public requiresVC = true; @@ -37,12 +38,14 @@ export default class implements Command { throw new Error('can\'t seek in a livestream'); } - const seekTime = interaction.options.getNumber('seconds'); + const seekValue = interaction.options.getString('value'); - if (!seekTime) { - throw new Error('missing number of seconds to seek'); + if (!seekValue) { + throw new Error('missing seek value'); } + const seekTime = durationStringToSeconds(seekValue); + if (seekTime + player.getPosition() > currentSong.length) { throw new Error('can\'t seek past the end of the song'); } diff --git a/src/commands/seek.ts b/src/commands/seek.ts index 07f6590..00e9c2e 100644 --- a/src/commands/seek.ts +++ b/src/commands/seek.ts @@ -5,6 +5,7 @@ import PlayerManager from '../managers/player.js'; import Command from '.'; import {parseTime, prettyTime} from '../utils/time.js'; import {SlashCommandBuilder} from '@discordjs/builders'; +import durationStringToSeconds from '../utils/duration-string-to-seconds.js'; @injectable() export default class implements Command { @@ -13,7 +14,7 @@ export default class implements Command { .setDescription('seek to a position from beginning of song') .addStringOption(option => option.setName('time') - .setDescription('time to seek') + .setDescription('an interval expression or number of seconds (1m, 30s, 100)') .setRequired(true), ); @@ -45,7 +46,7 @@ export default class implements Command { if (time.includes(':')) { seekTime = parseTime(time); } else { - seekTime = parseInt(time, 10); + seekTime = durationStringToSeconds(time); } if (seekTime > currentSong.length) { |
