Skip to content

Commit 2cf68e1

Browse files
committed
feat: skip multiple tracks at once
1 parent 6811d44 commit 2cf68e1

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

commands/music.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ var music = discord.SlashCommandCreate{
240240
discord.ApplicationCommandOptionSubCommand{
241241
Name: "skip",
242242
Description: "Skips the current track",
243+
Options: []discord.ApplicationCommandOption{
244+
discord.ApplicationCommandOptionInt{
245+
Name: "count",
246+
Description: "The number of tracks to skip",
247+
Required: false,
248+
},
249+
},
243250
},
244251
discord.ApplicationCommandOptionSubCommand{
245252
Name: "pause",

commands/skip.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,38 @@ package commands
22

33
import (
44
"context"
5+
"fmt"
56
"time"
67

78
"github.com/disgoorg/disgo/discord"
89
"github.com/disgoorg/disgo/handler"
910
"github.com/disgoorg/disgolink/v3/lavalink"
1011
)
1112

12-
func (c *Commands) Skip(_ discord.SlashCommandInteractionData, e *handler.CommandEvent) error {
13+
func (c *Commands) Skip(data discord.SlashCommandInteractionData, e *handler.CommandEvent) error {
1314
ctx, cancel := context.WithTimeout(e.Ctx, 10*time.Second)
1415
defer cancel()
16+
17+
var trackCount = data.Int("count")
18+
if trackCount == 0 {
19+
trackCount = 1
20+
}
21+
1522
player := c.Lavalink.ExistingPlayer(*e.GuildID())
16-
track, ok := c.MusicQueue.Next(*e.GuildID())
23+
track, ok := c.MusicQueue.NextCount(*e.GuildID(), trackCount)
1724
if !ok {
1825
return e.CreateMessage(discord.MessageCreate{
19-
Content: "No more tracks in queue",
26+
Content: "Not enough tracks to skip",
2027
Flags: discord.MessageFlagEphemeral,
2128
})
2229
}
2330
if err := player.Update(ctx, lavalink.WithTrack(track)); err != nil {
2431
return e.CreateMessage(discord.MessageCreate{
25-
Content: "Failed to play skip track",
32+
Content: "Failed to skip track(s)",
2633
})
2734
}
2835

2936
return e.CreateMessage(discord.MessageCreate{
30-
Content: "⏭ Skipped track",
37+
Content: fmt.Sprintf("⏭ Skipped %d track(s)", trackCount),
3138
})
3239
}

lavalinkbot/queue.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,27 @@ func (q *PlayerManager) SetRepeatMode(guildID snowflake.ID, mode RepeatMode) {
132132
}
133133

134134
func (q *PlayerManager) Next(guildID snowflake.ID) (lavalink.Track, bool) {
135+
return q.NextCount(guildID, 1)
136+
}
137+
138+
func (q *PlayerManager) NextCount(guildID snowflake.ID, count int) (lavalink.Track, bool) {
135139
q.mu.Lock()
136140
defer q.mu.Unlock()
137141

138142
qq, ok := q.queues[guildID]
139143
if !ok {
140144
return lavalink.Track{}, false
141145
}
142-
if len(qq.tracks) == 0 {
146+
if len(qq.tracks) < count {
143147
return lavalink.Track{}, false
144148
}
145-
track := qq.tracks[0]
149+
150+
track := qq.tracks[count-1]
146151
if qq.mode != RepeatModeTrack {
147152
if qq.mode == RepeatModeQueue {
148153
qq.tracks = append(qq.tracks, track)
149154
}
150-
qq.tracks = qq.tracks[1:]
155+
qq.tracks = qq.tracks[count:]
151156
}
152157
return track, true
153158
}

0 commit comments

Comments
 (0)