/skip: Add queue skipping feature

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
Macintxsh 2023-12-19 15:36:52 +03:00
parent 4eba6f3b96
commit 6c88ad59e5
Signed by: mctaylors
GPG key ID: 7181BEBE676903C1

View file

@ -167,10 +167,12 @@ public sealed class ControlsCommandGroup(
}
[Command("skip")]
[Description("Skips the current track")]
[Description("Skips the current track or track from queue")]
[DiscordDefaultDMPermission(false)]
[UsedImplicitly]
public async Task<Result> SkipCommandAsync()
public async Task<Result> SkipCommandAsync(
[Description("Track number in queue to skip")] [MinValue(1)]
int? index = null)
{
var player = await LavalinkPlayer.GetPlayerAsync(
commandContext, audioService, feedbackService);
@ -179,18 +181,41 @@ public sealed class ControlsCommandGroup(
return Result.FromSuccess();
}
if (player.CurrentTrack is null)
if (index is not null)
{
var queue = player.Queue;
if (index > queue.Count)
{
return await feedbackService.SendContextualMessageResult(
"There's no track with that index.",
feedbackService.Theme.FaultOrDanger);
}
var queueItem = queue[(int)index - 1];
var track = queueItem.Track;
await player.Queue.RemoveAsync(queueItem);
if (track is null)
{
return Result.FromSuccess(); // how
}
return await feedbackService.SendContextualMessageResult(
$"Removed {track.Display()} from queue", feedbackService.Theme.Success);
}
var currentTrack = player.CurrentTrack;
if (currentTrack is null)
{
return await feedbackService.SendContextualMessageResult(
"There's nothing playing right now.",
feedbackService.Theme.FaultOrDanger);
}
var track = player.CurrentTrack;
await player.SkipAsync();
return await feedbackService.SendContextualMessageResult(
$"Skipped {track.Display()}", feedbackService.Theme.Success);
$"Skipped {currentTrack.Display()}", feedbackService.Theme.Success);
}
}