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 // NewLavalink creates a new Lavalink manager
func NewLavalink() *Lavalink { func NewLavalink(shards int, userID int) *Lavalink {
return &Lavalink{} return &Lavalink{
Shards: shards,
UserID: userID,
nodes: make([]Node, 1),
players: make(map[string]*Player),
}
} }
// AddNodes adds a node to the Lavalink manager // 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 { switch m.Type {
case eventTrackEnd: case eventTrackEnd:
err = (*player.handler).OnTrackEnd(player, m.Track, m.Reason) err = player.handler.OnTrackEnd(player, m.Track, m.Reason)
case eventTrackException: case eventTrackException:
err = (*player.handler).OnTrackException(player, m.Track, m.Reason) err = player.handler.OnTrackException(player, m.Track, m.Reason)
case eventTrackStuck: case eventTrackStuck:
err = (*player.handler).OnTrackStuck(player, m.Track, m.ThresholdMs) err = player.handler.OnTrackStuck(player, m.Track, m.ThresholdMs)
} }
return err return err
@ -132,10 +132,7 @@ func (node *Node) onEvent(msgType int, msg []byte) error {
} }
// CreatePlayer creates an audio player on this node // CreatePlayer creates an audio player on this node
func (node *Node) CreatePlayer(guildID string, sessionID string, event VoiceServerUpdate, handler *EventHandler) (*Player, error) { func (node *Node) CreatePlayer(guildID string, sessionID string, event VoiceServerUpdate, handler EventHandler) (*Player, error) {
if handler == nil {
return nil, errNilHandler
}
msg := message{ msg := message{
Op: opVoiceUpdate, Op: opVoiceUpdate,
GuildID: guildID, GuildID: guildID,

View File

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