From 28ddb171ff0fba39d4820088e8fd5ad8f9cd1189 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Wed, 22 Aug 2018 19:39:36 -0400 Subject: [PATCH] meta: add example project --- lavalink.go | 9 +++++++-- node.go | 11 ++++------- player.go | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lavalink.go b/lavalink.go index 5ec2633..5031e12 100644 --- a/lavalink.go +++ b/lavalink.go @@ -26,8 +26,13 @@ var ( ) // NewLavalink creates a new Lavalink manager -func NewLavalink() *Lavalink { - return &Lavalink{} +func NewLavalink(shards int, userID int) *Lavalink { + return &Lavalink{ + Shards: shards, + UserID: userID, + nodes: make([]Node, 1), + players: make(map[string]*Player), + } } // AddNodes adds a node to the Lavalink manager diff --git a/node.go b/node.go index 85adf7b..65e3111 100644 --- a/node.go +++ b/node.go @@ -116,11 +116,11 @@ func (node *Node) onEvent(msgType int, msg []byte) error { switch m.Type { case eventTrackEnd: - err = (*player.handler).OnTrackEnd(player, m.Track, m.Reason) + err = player.handler.OnTrackEnd(player, m.Track, m.Reason) case eventTrackException: - err = (*player.handler).OnTrackException(player, m.Track, m.Reason) + err = player.handler.OnTrackException(player, m.Track, m.Reason) case eventTrackStuck: - err = (*player.handler).OnTrackStuck(player, m.Track, m.ThresholdMs) + err = player.handler.OnTrackStuck(player, m.Track, m.ThresholdMs) } return err @@ -132,10 +132,7 @@ func (node *Node) onEvent(msgType int, msg []byte) error { } // CreatePlayer creates an audio player on this node -func (node *Node) CreatePlayer(guildID string, sessionID string, event VoiceServerUpdate, handler *EventHandler) (*Player, error) { - if handler == nil { - return nil, errNilHandler - } +func (node *Node) CreatePlayer(guildID string, sessionID string, event VoiceServerUpdate, handler EventHandler) (*Player, error) { msg := message{ Op: opVoiceUpdate, GuildID: guildID, diff --git a/player.go b/player.go index b30a0c3..ac91bb1 100644 --- a/player.go +++ b/player.go @@ -14,7 +14,7 @@ type Player struct { position int manager *Lavalink node *Node - handler *EventHandler + handler EventHandler } // Play will play the given track completely