diff --git a/README.md b/README.md index fc25cab..dab274f 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ now audio should start playing ### Listening for events You can listen for following lavalink events -* `PlayerUpdate` Emitted every x seconds (default 5) with the current player state +* `PlayerUpdateMessage` Emitted every x seconds (default 5) with the current player state * `PlayerPause` Emitted when the player is paused * `PlayerResume` Emitted when the player is resumed * `TrackStart` Emitted when a track starts playing @@ -148,7 +148,7 @@ lavalinkClient := disgolink.New(userID, disgolink.WithListenerFunc(onWebSocketClosed), ) -func onPlayerUpdate(player disgolink.Player, event lavalink.PlayerUpdateEvent) { +func onPlayerUpdate(player disgolink.Player, event lavalink.PlayerUpdateMessage) { // do something with the event } diff --git a/disgolink/client.go b/disgolink/client.go index 2667a22..440eb11 100644 --- a/disgolink/client.go +++ b/disgolink/client.go @@ -27,7 +27,7 @@ type Client interface { RemovePlayer(guildID snowflake.ID) ForPlayers(playerFunc func(player Player)) - EmitEvent(player Player, event lavalink.Event) + EmitEvent(player Player, event lavalink.Message) AddListeners(listeners ...EventListener) RemoveListeners(listeners ...EventListener) @@ -180,7 +180,7 @@ func (c *clientImpl) ForPlayers(playerFunc func(player Player)) { } } -func (c *clientImpl) EmitEvent(player Player, event lavalink.Event) { +func (c *clientImpl) EmitEvent(player Player, event lavalink.Message) { c.listenersMu.Lock() defer c.listenersMu.Unlock() diff --git a/disgolink/client_config.go b/disgolink/client_config.go index 67ffd34..a7e9ba0 100644 --- a/disgolink/client_config.go +++ b/disgolink/client_config.go @@ -49,7 +49,7 @@ func WithListeners(listeners ...EventListener) ConfigOpt { } } -func WithListenerFunc[E lavalink.Event](listenerFunc func(p Player, e E)) ConfigOpt { +func WithListenerFunc[E lavalink.Message](listenerFunc func(p Player, e E)) ConfigOpt { return WithListeners(NewListenerFunc(listenerFunc)) } diff --git a/disgolink/event.go b/disgolink/event.go index 92787e7..e633139 100644 --- a/disgolink/event.go +++ b/disgolink/event.go @@ -3,18 +3,18 @@ package disgolink import "github.com/disgoorg/disgolink/v3/lavalink" type EventListener interface { - OnEvent(player Player, event lavalink.Event) + OnEvent(player Player, event lavalink.Message) } -func NewListenerFunc[E lavalink.Event](f func(p Player, e E)) EventListener { +func NewListenerFunc[E lavalink.Message](f func(p Player, e E)) EventListener { return &listenerFunc[E]{f: f} } -type listenerFunc[E lavalink.Event] struct { +type listenerFunc[E lavalink.Message] struct { f func(p Player, e E) } -func (l *listenerFunc[E]) OnEvent(p Player, e lavalink.Event) { +func (l *listenerFunc[E]) OnEvent(p Player, e lavalink.Message) { if event, ok := e.(E); ok { l.f(p, event) } diff --git a/disgolink/node.go b/disgolink/node.go index f51835a..28225e9 100644 --- a/disgolink/node.go +++ b/disgolink/node.go @@ -355,6 +355,7 @@ loop: case lavalink.StatsMessage: n.stats = lavalink.Stats(message) + n.lavalink.EmitEvent(nil, m) case lavalink.PlayerUpdateMessage: player := n.lavalink.ExistingPlayer(message.GuildID) @@ -362,6 +363,7 @@ loop: continue } player.OnPlayerUpdate(message.State) + n.lavalink.EmitEvent(player, m) case lavalink.Event: player := n.lavalink.ExistingPlayer(message.GuildID()) @@ -369,6 +371,7 @@ loop: continue } player.OnEvent(message) + n.lavalink.EmitEvent(player, m) } } } diff --git a/disgolink/player.go b/disgolink/player.go index 85d4e84..5348c4c 100644 --- a/disgolink/player.go +++ b/disgolink/player.go @@ -232,7 +232,6 @@ func (p *playerImpl) OnEvent(event lavalink.Event) { p.voice = lavalink.VoiceState{} p.state.Connected = false } - p.lavalink.EmitEvent(p, event) } func (p *playerImpl) OnPlayerUpdate(state lavalink.PlayerState) { diff --git a/lavalink/messages.go b/lavalink/messages.go index ca45757..1da54a8 100644 --- a/lavalink/messages.go +++ b/lavalink/messages.go @@ -142,6 +142,7 @@ func (m UnknownMessage) MarshalJSON() ([]byte, error) { func (m UnknownMessage) Op() Op { return m.Op_ } type Event interface { + Op() Op Type() EventType GuildID() snowflake.ID }