Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

topi handholded changes #51

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions disgolink/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion disgolink/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
8 changes: 4 additions & 4 deletions disgolink/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions disgolink/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,23 @@ loop:

case lavalink.StatsMessage:
n.stats = lavalink.Stats(message)
n.lavalink.EmitEvent(nil, m)

case lavalink.PlayerUpdateMessage:
player := n.lavalink.ExistingPlayer(message.GuildID)
if player == nil {
continue
}
player.OnPlayerUpdate(message.State)
n.lavalink.EmitEvent(player, m)

case lavalink.Event:
player := n.lavalink.ExistingPlayer(message.GuildID())
if player == nil {
continue
}
player.OnEvent(message)
n.lavalink.EmitEvent(player, m)
}
}
}
1 change: 0 additions & 1 deletion disgolink/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lavalink/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down