Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Replay.ts #595

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/commands/music/Replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ export default class Replay extends Command {
const player = client.queue.get(ctx.guild.id);
const embed = this.client.embed();

if (!player.current) {

if (!player.current?.info.isSeekable) {
return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription("There is no track currently playing")],
embeds: [embed.setColor(this.client.color.red).setDescription("Cannot replay this track as it is not seekable")],
});
}

player.seek(0);

return await ctx.sendMessage({
Expand Down
29 changes: 21 additions & 8 deletions src/commands/music/Seek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default class Seek extends Command {
slashCommand: true,
options: [
{
name: "time",
description: "The time to seek to",
name: "duration",
description: "The duration to seek to",
type: 3,
required: true,
},
Expand All @@ -38,19 +38,32 @@ export default class Seek extends Command {

public async run(client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
const player = client.queue.get(ctx.guild.id);
const current = player.current.info;
const embed = this.client.embed();

const time = client.utils.parseTime(args[0]);
if (!time) {
const duration = client.utils.parseTime(args.join(" "));

if (!duration) {
return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription("Invalid time format.")],
embeds: [embed.setColor(this.client.color.red).setDescription("Invalid time format. Example: seek 1m, seek 1h 30m")],
});
}

player.seek(time);
if (!current.isSeekable) {
return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription("This track is not seekable")],
});
}

if (duration > current.length) {
return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription(`Cannot seek beyond the song duration of ${client.utils.formatTime(current.length)}`)],
});
}

player.seek(duration);

return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.main).setDescription(`Seeked to ${args[0]}`)],
embeds: [embed.setColor(this.client.color.main).setDescription(`Seeked to ${client.utils.formatTime(duration)}`)],
});
}
}
Expand Down