Allow seeking with hours

This commit is contained in:
Max Isom 2020-03-18 12:55:03 -05:00
parent b1895627db
commit e57d86d7cc
2 changed files with 12 additions and 4 deletions

View file

@ -65,7 +65,7 @@ export default class implements Command {
await this.playerManager.get(msg.guild!.id).connect(targetVoiceChannel); await this.playerManager.get(msg.guild!.id).connect(targetVoiceChannel);
await this.playerManager.get(msg.guild!.id).play(); await this.playerManager.get(msg.guild!.id).play();
await res.stop('play resuming'); await res.stop('the stop-and-go light is now green');
return; return;
} }

View file

@ -11,8 +11,9 @@ import Command from '.';
export default class implements Command { export default class implements Command {
public name = 'seek'; public name = 'seek';
public examples = [ public examples = [
['seek 10', 'seeks to 10 seconds from begining of song'], ['seek 10', 'seeks to 10 seconds from beginning of song'],
['seek 1:30', 'seeks to 1 minute and 30 seconds from begining of song'] ['seek 1:30', 'seeks to 1 minute and 30 seconds from beginning of song'],
['seek 1:00:00', 'seeks to 1 hour from beginning of song']
]; ];
private readonly playerManager: PlayerManager; private readonly playerManager: PlayerManager;
@ -43,7 +44,14 @@ export default class implements Command {
let seekTime = 0; let seekTime = 0;
if (time.includes(':')) { if (time.includes(':')) {
seekTime = (parseInt(time.split(':')[0], 10) * 60) + parseInt(time.split(':')[1], 10); const timeGroups = time.split(':').map(t => parseInt(t, 10));
let currentTimePeriod = 1;
for (let i = timeGroups.length - 1; i >= 0; i--) {
seekTime += currentTimePeriod * timeGroups[i];
currentTimePeriod *= 60;
}
} else { } else {
seekTime = parseInt(time, 10); seekTime = parseInt(time, 10);
} }