From 4e4be24fe56852573800898fe557e4889adb5c9e Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Wed, 13 May 2020 20:12:52 +0100 Subject: [PATCH] improved seek command --- commands/music/seek.js | 4 ++-- index.js | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/commands/music/seek.js b/commands/music/seek.js index 7e57754..fa2888e 100644 --- a/commands/music/seek.js +++ b/commands/music/seek.js @@ -25,7 +25,7 @@ module.exports = class JoinCommand extends Command { key: 'query', prompt: 'to what time do you want to seek? (HH:MM:SS)', type: 'string', - validate: query => query.length > 0 && query.match(/\d+:\d{2}:\d{2}/) + validate: query => query.length > 0 && query.match(/(\d+:)?(\d{2}:)?\d{2}/) } ], throttling: { @@ -54,7 +54,7 @@ module.exports = class JoinCommand extends Command { } message.guild.music.seek = seekSeconds; await message.guild.play(message.guild.music.queue, message); - const embed = new MessageEmbed().setColor('#000099').setTitle(`:musical_note: Sought to ${query}`); + const embed = new MessageEmbed().setColor('#000099').setTitle(`:musical_note: Sought to ${message.guild.formatDurationString(Math.floor(seekSeconds / 3600), Math.floor(seekSeconds / 60), seekSeconds % 60)}`); return await message.say({ embed }); } } catch(err) { diff --git a/index.js b/index.js index d133017..4d5252d 100644 --- a/index.js +++ b/index.js @@ -104,11 +104,15 @@ Structures.extend('Guild', Guild => { } formatDurationSeconds = durationString => { - if (!durationString.match(/\d+:\d{2}:\d{2}/)) return; + if (!durationString.match(/(\d+:)?(\d{2}:)?\d{2}/)) return; const time = durationString.split(':').map(time => parseInt(time)); - return time[0] * 3600 + time[1] * 60 + time[2]; + switch (time.length) { + case 3: return time[0] * 3600 + time[1] * 60 + time[2]; + case 2: return time[0] * 60 + time[1]; + case 1: return time[0]; + } } }