-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.go
130 lines (103 loc) · 2.81 KB
/
plugin.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package sponsorblock
import (
"encoding/json"
"log/slog"
"github.com/disgoorg/disgolink/v3/disgolink"
"github.com/disgoorg/disgolink/v3/lavalink"
)
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{
&segmentsLoadedHandler{
logger: logger,
},
&segmentSkippedHandler{
logger: logger,
},
&chaptersLoadedHandler{
logger: logger,
},
&chapterStartedHandler{
logger: logger,
},
},
}
}
type Plugin struct {
eventPlugins []disgolink.EventPlugin
}
func (p *Plugin) EventPlugins() []disgolink.EventPlugin {
return p.eventPlugins
}
func (p *Plugin) Name() string {
return "sponsorblock"
}
func (p *Plugin) Version() string {
return "1.0.0"
}
var _ disgolink.EventPlugin = (*segmentsLoadedHandler)(nil)
type segmentsLoadedHandler struct {
logger *slog.Logger
}
func (h *segmentsLoadedHandler) Event() lavalink.EventType {
return EventTypeSegmentsLoaded
}
func (h *segmentsLoadedHandler) OnEventInvocation(player disgolink.Player, data []byte) {
var e SegmentsLoadedEvent
if err := json.Unmarshal(data, &e); err != nil {
h.logger.Error("Failed to unmarshal SegmentsLoaded Event", slog.Any("err", err))
return
}
player.Lavalink().EmitEvent(player, e)
}
var _ disgolink.EventPlugin = (*segmentSkippedHandler)(nil)
type segmentSkippedHandler struct {
logger *slog.Logger
}
func (h *segmentSkippedHandler) Event() lavalink.EventType {
return EventTypeSegmentSkipped
}
func (h *segmentSkippedHandler) OnEventInvocation(player disgolink.Player, data []byte) {
var e SegmentSkippedEvent
if err := json.Unmarshal(data, &e); err != nil {
h.logger.Error("Failed to unmarshal SegmentSkipped Event", err)
return
}
player.Lavalink().EmitEvent(player, e)
}
type chaptersLoadedHandler struct {
logger *slog.Logger
}
func (h *chaptersLoadedHandler) Event() lavalink.EventType {
return EventTypeChaptersLoaded
}
func (h *chaptersLoadedHandler) OnEventInvocation(player disgolink.Player, data []byte) {
var e ChaptersLoadedEvent
if err := json.Unmarshal(data, &e); err != nil {
h.logger.Error("Failed to unmarshal ChaptersLoaded Event", err)
return
}
player.Lavalink().EmitEvent(player, e)
}
var _ disgolink.EventPlugin = (*chapterStartedHandler)(nil)
type chapterStartedHandler struct {
logger *slog.Logger
}
func (h *chapterStartedHandler) Event() lavalink.EventType {
return EventTypeChapterStarted
}
func (h *chapterStartedHandler) OnEventInvocation(player disgolink.Player, data []byte) {
var e ChapterStartedEvent
if err := json.Unmarshal(data, &e); err != nil {
h.logger.Error("Failed to unmarshal ChapterStarted Event", err)
return
}
player.Lavalink().EmitEvent(player, e)
}