-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlavaqueue.go
64 lines (50 loc) · 1.19 KB
/
lavaqueue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package lavaqueue
import (
"log/slog"
"github.com/disgoorg/disgolink/v3/disgolink"
"github.com/disgoorg/disgolink/v3/lavalink"
"github.com/disgoorg/json"
)
var (
_ disgolink.EventPlugins = (*Plugin)(nil)
_ disgolink.Plugin = (*Plugin)(nil)
)
func New() *Plugin {
return NewWithLogger(slog.Default())
}
func NewWithLogger(logger *slog.Logger) *Plugin {
return &Plugin{
eventPlugins: []disgolink.EventPlugin{
&queueEndHandler{
logger: logger,
},
},
}
}
type Plugin struct {
eventPlugins []disgolink.EventPlugin
}
func (p *Plugin) EventPlugins() []disgolink.EventPlugin {
return p.eventPlugins
}
func (p *Plugin) Name() string {
return "lavaqueue"
}
func (p *Plugin) Version() string {
return "1.0.0"
}
var _ disgolink.EventPlugin = (*queueEndHandler)(nil)
type queueEndHandler struct {
logger *slog.Logger
}
func (h *queueEndHandler) Event() lavalink.EventType {
return EventTypeQueueEnd
}
func (h *queueEndHandler) OnEventInvocation(player disgolink.Player, data []byte) {
var e QueueEndEvent
if err := json.Unmarshal(data, &e); err != nil {
h.logger.Error("Failed to unmarshal QueueEndEvent", slog.Any("err", err))
return
}
player.Lavalink().EmitEvent(player, e)
}