Skip to content

Commit 7181495

Browse files
committed
fix: Multiple issues with lavaqueue have been fixed upstream
1 parent edd34ee commit 7181495

File tree

10 files changed

+331
-156
lines changed

10 files changed

+331
-156
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ go.work.sum
2424
# env file
2525
.env
2626

27+
# Cache
28+
deploy/local/plugins/*
29+
2730
# config files
2831
config_secrets.yaml
2932
config_secrets.yml

deploy/local/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ services:
2121
- LAVALINK_SERVER_PASSWORD=supersecret
2222
volumes:
2323
- ./lavalink/application.yml:/opt/Lavalink/application.yml
24+
- ./plugins/:/opt/Lavalink/plugins/
2425
networks:
2526
- streaming
2627
expose:

deploy/local/lavalink/application.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ plugins:
1010
allowDirectPlaylistIds: true
1111
clients:
1212
- MUSIC
13+
#- TV
14+
#- TVHTML5EMBEDDED
1315
- WEB
14-
- WEBEMBEDDED
16+
- WEBEMBEDDED
17+
- MWEB
18+
- ANDROID_VR
1519

1620
lavalink:
1721
plugins:
1822
- dependency: "dev.lavalink.youtube:youtube-plugin:1.11.5"
1923
snapshot: false
20-
- dependency: "com.github.topi314.lavaqueue:lavaqueue-plugin:98c97f9"
24+
- dependency: "com.github.topi314.lavaqueue:lavaqueue-plugin:d10820e"
2125
repository: "https://maven.topi.wtf/snapshots"
2226
snapshot: false
2327
server:

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ go 1.23.6
55
require (
66
github.com/disgoorg/disgo v0.18.15
77
github.com/disgoorg/disgolink/v3 v3.0.3
8+
github.com/disgoorg/lavaqueue-plugin v0.0.0-20250311012151-1ab98828bfae
9+
github.com/disgoorg/snowflake/v2 v2.0.3
810
github.com/rs/zerolog v1.33.0
11+
gopkg.in/yaml.v3 v3.0.1
912
)
1013

1114
require (
1215
github.com/disgoorg/json v1.2.0 // indirect
13-
github.com/disgoorg/lavaqueue-plugin v0.0.0-20240708001834-dafe3f63f5a0 // indirect
14-
github.com/disgoorg/snowflake/v2 v2.0.3 // indirect
1516
github.com/gorilla/websocket v1.5.3 // indirect
1617
github.com/mattn/go-colorable v0.1.14 // indirect
1718
github.com/mattn/go-isatty v0.0.20 // indirect
1819
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect
19-
golang.org/x/crypto v0.31.0 // indirect
20-
golang.org/x/sys v0.30.0 // indirect
21-
gopkg.in/yaml.v3 v3.0.1 // indirect
20+
golang.org/x/crypto v0.36.0 // indirect
21+
golang.org/x/sys v0.31.0 // indirect
2222
)

go.sum

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ github.com/disgoorg/disgolink/v3 v3.0.3 h1:9eHV5lVAGtPzDHjp3IJJ5xdWcFEjc24VJZWsA
77
github.com/disgoorg/disgolink/v3 v3.0.3/go.mod h1:34D/dfdfrj08fSjtdKSXYz1TsMcjrX2RKoSpdxG3lHo=
88
github.com/disgoorg/json v1.2.0 h1:6e/j4BCfSHIvucG1cd7tJPAOp1RgnnMFSqkvZUtEd1Y=
99
github.com/disgoorg/json v1.2.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
10-
github.com/disgoorg/lavaqueue-plugin v0.0.0-20240708001834-dafe3f63f5a0 h1:ZvHEx0WER8DWyJewm+mKMRi3omJAbpzIbWCLAyaiZ8Y=
11-
github.com/disgoorg/lavaqueue-plugin v0.0.0-20240708001834-dafe3f63f5a0/go.mod h1:pvlIraap6FdqFCOUEeeadAIGnapApELXXM/+z1rxD6c=
10+
github.com/disgoorg/lavaqueue-plugin v0.0.0-20250311012151-1ab98828bfae h1:1hA0tigD0Ht0dDOQUMmx/X3pqihhEIfCdAoIr9Y+mAo=
11+
github.com/disgoorg/lavaqueue-plugin v0.0.0-20250311012151-1ab98828bfae/go.mod h1:75Bd+G7i7uoMBqIx7DvYqc5Qu2sv9ZXWLM5OTp+FCjc=
1212
github.com/disgoorg/snowflake/v2 v2.0.3 h1:3B+PpFjr7j4ad7oeJu4RlQ+nYOTadsKapJIzgvSI2Ro=
1313
github.com/disgoorg/snowflake/v2 v2.0.3/go.mod h1:W6r7NUA7DwfZLwr00km6G4UnZ0zcoLBRufhkFWgAc4c=
1414
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@@ -31,13 +31,14 @@ github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad h1:qIQkSlF5vAUHxE
3131
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
3232
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
3333
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
34-
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
35-
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
34+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
35+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
3636
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3737
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3838
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
39-
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
40-
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
39+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
40+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
41+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4142
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4243
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4344
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/bot/bot.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ import (
1212
"github.com/disgoorg/disgo/gateway"
1313
"github.com/disgoorg/disgo/handler"
1414
"github.com/disgoorg/disgolink/v3/disgolink"
15+
"github.com/disgoorg/lavaqueue-plugin"
16+
"github.com/disgoorg/snowflake/v2"
1517
"github.com/mroctopus/bottie-bot/internal/config"
18+
"github.com/mroctopus/bottie-bot/internal/player"
1619
)
1720

1821
type RobotoBot struct {
1922
// Config
2023
Config *config.RobotoConfig
2124
// Clients
2225
Discord bot.Client
23-
Lavalink disgolink.Client
26+
Lavalink disgolink.Client // TODO: Add message cache mapping here for lavalink handler to use
27+
// More
28+
LavalinkTrackMessages map[snowflake.ID]player.TrackMessageData
2429
}
2530

2631
func (b *RobotoBot) Start(cmds []discord.ApplicationCommandCreate, r *handler.Mux) error {
@@ -108,8 +113,12 @@ func New(cfg *config.RobotoConfig) (*RobotoBot, error) {
108113
}
109114

110115
if cfg.Lavalink != nil {
111-
lavalink := disgolink.New(discord.ApplicationID(), disgolink.WithListenerFunc(roboto.OnLavalinkEvent))
116+
lavalink := disgolink.New(discord.ApplicationID(),
117+
disgolink.WithListenerFunc(roboto.OnLavalinkEvent),
118+
disgolink.WithPlugins(lavaqueue.New()),
119+
)
112120
roboto.Lavalink = lavalink
121+
roboto.LavalinkTrackMessages = make(map[snowflake.ID]player.TrackMessageData)
113122
}
114123
roboto.Discord = discord
115124

internal/bot/handlers.go

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package bot
22

33
import (
44
"context"
5+
"encoding/json"
6+
"time"
57

68
"github.com/disgoorg/disgo/bot"
79
"github.com/disgoorg/disgo/events"
810
"github.com/disgoorg/disgolink/v3/disgolink"
911
"github.com/disgoorg/disgolink/v3/lavalink"
12+
"github.com/disgoorg/lavaqueue-plugin"
13+
"github.com/mroctopus/bottie-bot/internal/player"
14+
"github.com/rs/zerolog/log"
1015
)
1116

1217
func (b *RobotoBot) OnDiscordEvent(event bot.Event) {
@@ -24,19 +29,62 @@ func (b *RobotoBot) OnDiscordEvent(event bot.Event) {
2429
}
2530
}
2631

32+
// NOTE:
33+
// This might need a mutex -> !!!!
2734
func (b *RobotoBot) OnLavalinkEvent(p disgolink.Player, event lavalink.Event) {
28-
// player := b.Lavalink.Player(p.GuildID())
29-
/*
30-
switch e := event.(type) {
31-
case lavaqueue.QueueEndEvent:
32-
//slog.Info("queue end", slog.String("guild", p.GuildID().String()))
35+
client := b.Discord
3336

34-
case lavalink.TrackStartEvent:
37+
switch e := event.(type) {
38+
case lavaqueue.QueueEndEvent:
39+
log.Debug().Msgf("LAVALINK EVENT: %s", event.Type())
40+
41+
go func() {
42+
time.Sleep(time.Second * 10)
43+
track := p.Track()
44+
if track == nil {
45+
ctx := context.Background()
46+
47+
err := p.Destroy(ctx)
48+
if err != nil {
49+
log.Warn().Err(err).Msg("Failed to stop the music player")
50+
}
3551

36-
case lavalink.TrackExceptionEvent:
37-
//slog.Error("track exception", tint.Err(e.Exception))
52+
_ = client.UpdateVoiceState(ctx, e.GuildID(), nil, false, false)
53+
}
3854

39-
case lavalink.TrackStuckEvent:
55+
}()
4056

41-
}*/
57+
case lavalink.TrackEndEvent:
58+
track := e.Track
59+
60+
var data player.TrackUserData
61+
err := json.Unmarshal(track.UserData, &data)
62+
if err != nil {
63+
log.Error().Err(err).Msg("Failed to unmarshal track TrackUserData on Lavalink.TrackEndEvent")
64+
return
65+
}
66+
67+
msg, ok := b.LavalinkTrackMessages[data.ID]
68+
if !ok {
69+
log.Warn().Msgf("Failed to find the corresponding message for track snowflake ID '%s'", data.ID)
70+
return
71+
}
72+
73+
err = client.Rest().DeleteFollowupMessage(msg.AppID, msg.InteractionToken, msg.MessageID)
74+
if err != nil {
75+
log.Warn().Err(err).Msgf("Failed to delete the message with ID '%s' in channel ID '%s'", msg.MessageID, msg.ChannelID)
76+
}
77+
78+
delete(b.LavalinkTrackMessages, data.ID)
79+
80+
case lavalink.TrackStartEvent:
81+
// TODO
82+
83+
case lavalink.TrackExceptionEvent:
84+
// TODO
85+
86+
case lavalink.TrackStuckEvent:
87+
// TODO
88+
89+
}
4290
}

internal/command/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type CommandBootstrapper func(*bot.RobotoBot, *handler.Mux) discord.ApplicationC
1515

1616
// Add more bootstappers here
1717
var bootstrappers = [...]CommandBootstrapper{
18-
music,
18+
musicCommands,
1919
}
2020

2121
func New(bot *bot.RobotoBot) ([]discord.ApplicationCommandCreate, *handler.Mux) {

0 commit comments

Comments
 (0)