improved seek command

This commit is contained in:
Hazem Krimi
2020-05-13 20:12:52 +01:00
parent b20b8607c7
commit 4e4be24fe5
2 changed files with 8 additions and 4 deletions
+2 -2
View File
@@ -25,7 +25,7 @@ module.exports = class JoinCommand extends Command {
key: 'query', key: 'query',
prompt: 'to what time do you want to seek? (HH:MM:SS)', prompt: 'to what time do you want to seek? (HH:MM:SS)',
type: 'string', 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: { throttling: {
@@ -54,7 +54,7 @@ module.exports = class JoinCommand extends Command {
} }
message.guild.music.seek = seekSeconds; message.guild.music.seek = seekSeconds;
await message.guild.play(message.guild.music.queue, message); 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 }); return await message.say({ embed });
} }
} catch(err) { } catch(err) {
+6 -2
View File
@@ -104,11 +104,15 @@ Structures.extend('Guild', Guild => {
} }
formatDurationSeconds = durationString => { 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)); 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];
}
} }
} }