Merge pull request #65 from mariusbegby/seek-command

Seek command
This commit is contained in:
Marius Begby authored and GitHub committed 2023-07-16 18:23:53 +02:00
commit d92a33a762
13 files changed
+215 -46

No files matched your search

+1 -1
View File
@@ -39,7 +39,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
+11 -10
View File
@@ -13,16 +13,17 @@ module.exports = {
new EmbedBuilder()
.setDescription(
`${embedIcons.rule} **List of commands**\n` +
'- `/play` `query` - Add a track or playlist to the queue by url or search.\n' +
'- `/pause` - Pause or resume the current track.\n' +
'- `/queue` `[page]` - Show the list of tracks added to the queue.\n' +
`- \`/nowplaying\` - ${embedIcons.new} Show information about the track currently playing.\n` +
`- \`/loop\` \`mode\` - ${embedIcons.beta} Toggle looping a track, the whole queue or autoplay.\n` +
`- \`/filters\` - ${embedIcons.beta} Toggle various audio filters during playback.\n` +
'- `/volume` `[percentage]` - Show or set the playback volume for tracks.\n' +
'- `/skip` `[trackNumber]` - Skip to next or specified track.\n' +
'- `/remove` `trackNumber` - Remove specified track from the queue.\n' +
'- `/leave` - Clear the queue and remove the bot from voice channel.\n\n' +
'- **`/play` `query`** - Add a track or playlist to the queue by url or search.\n' +
'- **`/pause`** - Pause or resume the current track.\n' +
'- **`/queue` `[page]`** - Show the list of tracks added to the queue.\n' +
'- **`/nowplaying`** - Show information about the track currently playing.\n' +
`- **\`/seek\` \`duration\`** - ${embedIcons.new} Seek to a specified duration in the current track.\n` +
`- **\`/loop\` \`mode\`** - ${embedIcons.beta} Toggle looping a track, the whole queue or autoplay.\n` +
'- **`/filters`** - Toggle various audio filters during playback.\n' +
'- **`/volume` `[percentage]`** - Show or set the playback volume for tracks.\n' +
'- **`/skip` `[tracknumber]`** - Skip to next or specified track.\n' +
'- **`/remove` `tracknumber`** - Remove specified track from the queue.\n' +
'- **`/leave`** - Clear the queue and remove the bot from voice channel.\n\n' +
`${embedIcons.support} **Support server**\nJoin the support server for help or suggestions: \n**${botInfo.supportServerInviteUrl}**\n\n` +
`${embedIcons.bot} **Enjoying ${botInfo.name}?**\nAdd me to another server: \n**[Click me!](${botInfo.botInviteUrl})**`
)
+1 -1
View File
@@ -52,7 +52,7 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the \`/play\` command!`
`**${embedIcons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!`
)
.setColor(embedColors.colorSuccess)
]
+1 -1
View File
@@ -40,7 +40,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
+9 -9
View File
@@ -32,7 +32,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
@@ -44,7 +44,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
@@ -83,16 +83,16 @@ module.exports = {
'Unavailable';
const queueLength = queue.tracks.data.length;
const timestamp = queue.node.getTimestamp();
let bar = `\`${
let bar = `**\`${
timestamp.current.label
}\` ${queue.node.createProgressBar({
}\`** ${queue.node.createProgressBar({
queue: false,
length: progressBarOptions.length ?? 12,
timecodes: progressBarOptions.timecodes ?? false,
indicator: progressBarOptions.indicator ?? '🔘',
leftChar: progressBarOptions.leftChar ?? '▬',
rightChar: progressBarOptions.rightChar ?? '▬'
})} \`${timestamp.total.label}\``;
})} **\`${timestamp.total.label}\`**`;
if (
currentTrack.raw.duration === 0 ||
@@ -141,7 +141,7 @@ module.exports = {
queue.repeatMode === 3
? embedIcons.autoplay
: embedIcons.loop
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with \`/loop\`.`
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.`
}`
)
.addFields(
@@ -190,7 +190,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
],
@@ -233,7 +233,7 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**` +
`**${embedIcons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` +
`${
queue.repeatMode === 0
? ''
@@ -241,7 +241,7 @@ module.exports = {
queue.repeatMode === 3
? embedIcons.autoplaying
: embedIcons.looping
} Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with \`/loop\`.`
} Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with **\`/loop\`**.`
}`
)
.setThumbnail(skippedTrack.thumbnail)
+2 -2
View File
@@ -28,7 +28,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
@@ -40,7 +40,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
+4 -4
View File
@@ -179,11 +179,11 @@ module.exports = {
.setDescription(
`**${
embedIcons.success
} Added playlist to queue**\n${durationFormat} **[${
} Added playlist to queue**\n**${durationFormat} [${
track.title
}](${track.url})**\n\nAnd **${
searchResult.tracks.length - 1
}** more tracks... \`/queue\` to view all.`
}** more tracks... **\`/queue\`** to view all.`
)
.setThumbnail(track.thumbnail)
.setColor(embedColors.colorSuccess)
@@ -203,7 +203,7 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.audioStartedPlaying} Started playing**\n${durationFormat} **[${track.title}](${track.url})**`
`**${embedIcons.audioStartedPlaying} Started playing**\n**${durationFormat} [${track.title}](${track.url})**`
)
.setThumbnail(track.thumbnail)
.setColor(embedColors.colorSuccess)
@@ -221,7 +221,7 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`${embedIcons.success} **Added to queue**\n${durationFormat} **[${track.title}](${track.url})**`
`${embedIcons.success} **Added to queue**\n**${durationFormat} [${track.title}](${track.url})**`
)
.setThumbnail(track.thumbnail)
.setColor(embedColors.colorSuccess)
+6 -6
View File
@@ -43,7 +43,7 @@ module.exports = {
.setDescription(
`**${embedIcons.warning} Oops!**\nPage \`${
pageIndex + 1
}\` is not a valid page number.\n\nThe queue is currently empty, first add some tracks with \`/play\`!`
}\` is not a valid page number.\n\nThe queue is currently empty, first add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
@@ -98,7 +98,7 @@ module.exports = {
return `**${
pageIndex * 10 + index + 1
}.** ${durationFormat} **[${track.title}](${track.url})**`;
}.** **${durationFormat} [${track.title}](${track.url})**`;
})
.join('\n');
}
@@ -121,7 +121,7 @@ module.exports = {
queue.repeatMode === 3
? embedIcons.autoplay
: embedIcons.loop
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with \`/loop\`.\n\n`
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.\n\n`
}`;
if (!currentTrack) {
@@ -146,16 +146,16 @@ module.exports = {
});
} else {
const timestamp = queue.node.getTimestamp();
let bar = `\`${
let bar = `**\`${
timestamp.current.label
}\` ${queue.node.createProgressBar({
}\`** ${queue.node.createProgressBar({
queue: false,
length: progressBarOptions.length ?? 12,
timecodes: progressBarOptions.timecodes ?? false,
indicator: progressBarOptions.indicator ?? '🔘',
leftChar: progressBarOptions.leftChar ?? '▬',
rightChar: progressBarOptions.rightChar ?? '▬'
})} \`${timestamp.total.label}\``;
})} **\`${timestamp.total.label}\`**`;
if (
currentTrack.raw.duration === 0 ||
+3 -3
View File
@@ -35,7 +35,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
@@ -49,7 +49,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nTrack \`${removeTrackNumber}\` is not a valid track number. There are a total of\`${queue.tracks.data.length}\` tracks in the queue.\n\nView tracks added to the queue with \`/queue\`.`
`**${embedIcons.warning} Oops!**\nTrack \`${removeTrackNumber}\` is not a valid track number. There are a total of\`${queue.tracks.data.length}\` tracks in the queue.\n\nView tracks added to the queue with **\`/queue\`**.`
)
.setColor(embedColors.colorWarning)
]
@@ -73,7 +73,7 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.success} Removed track**\n${durationFormat} **[${removedTrack.title}](${removedTrack.url})**`
`**${embedIcons.success} Removed track**\n**${durationFormat} [${removedTrack.title}](${removedTrack.url})**`
)
.setThumbnail(removedTrack.thumbnail)
.setColor(embedColors.colorSuccess)
+168
View File
@@ -0,0 +1,168 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors, embedIcons } = require('../config.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('seek')
.setDescription('Seek to a specified duration in the current track.')
.setDMPermission(false)
.addStringOption((option) =>
option
.setName('duration')
.setDescription(
'Duration in format 00:00:00 (HH:mm:ss) to seek to.'
)
.setRequired(true)
),
run: async ({ interaction }) => {
if (!interaction.member.voice.channel) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.`
)
.setColor(embedColors.colorWarning)
]
});
}
const queue = useQueue(interaction.guild.id);
if (!queue) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
});
}
if (!queue.currentTrack) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
});
}
const durationInput = interaction.options.getString('duration');
let durationArray = durationInput.split(':');
switch (durationArray.length) {
case 1:
durationArray.unshift('00', '00');
break;
case 2:
durationArray.unshift('00');
break;
default:
break;
}
if (durationArray.length === 0 || durationArray.length > 3) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` +
'- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- `/seek` **`42`** - Seek to 42 seconds.'
)
.setColor(embedColors.colorWarning)
]
});
}
durationArray = durationArray.map((value) => {
return value.padStart(2, '0');
});
const durationString = durationArray.join(':');
let validElements = durationArray.every((value) => {
return value.length === 2;
});
if (!validElements) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` +
'- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- `/seek` **`42`** - Seek to 42 seconds.'
)
.setColor(embedColors.colorWarning)
]
});
}
// Now array should only be 3 elements long, all with 2 characters, e.g. ['00', '00', '00'].
// Regex can now validate if this is a valid duration format. E.g. check if the first element is 0-23, second element is 0-59 and third element is 0-59.
const regex = new RegExp('([0-1][0-9]|2[0-3]):?[0-5][0-9]:?[0-5][0-9]');
const isValidDuration = regex.test(durationString);
if (!isValidDuration) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` +
'- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- `/seek` **`42`** - Seek to 42 seconds.'
)
.setColor(embedColors.colorWarning)
]
});
}
const currentTrackMaxDurationInMs = queue.currentTrack.durationMS;
const durationInMilliseconds =
durationArray[0] * 3600000 +
durationArray[1] * 60000 +
durationArray[2] * 1000;
if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nYou entered **\`${durationString}\`**, which is a duration that is longer than the duration for the current track.\n\nPlease try a duration that is less than the duration of the track (**\`${queue.currentTrack.duration}\`**).`
)
.setColor(embedColors.colorWarning)
]
});
}
queue.node.seek(durationInMilliseconds);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name:
interaction.member.nickname ||
interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.success} Seeking to duration**\nSeeking to **\`${durationString}\`** in current track.`
)
.setThumbnail(queue.currentTrack.thumbnail)
.setColor(embedColors.colorSuccess)
]
});
}
};
+6 -6
View File
@@ -34,7 +34,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
@@ -49,7 +49,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are only \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track \`${skipToTrack}\`.\n\nView tracks added to the queue with \`/queue\`.`
`**${embedIcons.warning} Oops!**\nThere are only \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track \`${skipToTrack}\`.\n\nView tracks added to the queue with **\`/queue\`**.`
)
.setColor(embedColors.colorWarning)
]
@@ -73,7 +73,7 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**`
`**${embedIcons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**`
)
.setThumbnail(skippedTrack.thumbnail)
.setColor(embedColors.colorSuccess)
@@ -86,7 +86,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
@@ -120,7 +120,7 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedIcons.skipped} Skipped track**\n${durationFormat} **[${skippedTrack.title}](${skippedTrack.url})**` +
`**${embedIcons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` +
`${
queue.repeatMode === 0
? ''
@@ -128,7 +128,7 @@ module.exports = {
queue.repeatMode === 3
? embedIcons.autoplaying
: embedIcons.looping
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with \`/loop\`.`
} Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.`
}`
)
.setThumbnail(skippedTrack.thumbnail)
+1 -1
View File
@@ -35,7 +35,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with \`/play\`!`
`**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!`
)
.setColor(embedColors.colorWarning)
]
+2 -2
View File
@@ -41,8 +41,8 @@ module.exports = {
let embedDescription = `**${embedIcons.bot} ${
client.guilds.cache.size < 50
? 'Guilds'
: `Top ${client.guilds.cache.size} guilds`
? `Top ${client.guilds.cache.size} guilds`
: 'Top 50 guilds'
} by member count (${client.guilds.cache.size} total)**\n${guildsList}`;
if (embedDescription.length >= 4000) {