meta: add example project

This commit is contained in:
Christopher F 2018-08-22 19:39:36 -04:00
parent b1983105f3
commit 28ddb171ff
3 changed files with 12 additions and 10 deletions

View File

@ -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

11
node.go
View File

@ -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,

View File

@ -14,7 +14,7 @@ type Player struct {
position int
manager *Lavalink
node *Node
handler *EventHandler
handler EventHandler
}
// Play will play the given track completely