Full support for changing nodes

This commit is contained in:
Tyler 2019-10-13 00:04:01 -04:00
parent ba383db391
commit ef903095c9
2 changed files with 6 additions and 0 deletions

View File

@ -184,6 +184,7 @@ func (node *Node) CreatePlayer(guildID string, sessionID string, event VoiceServ
player := &Player{ player := &Player{
guildID: guildID, guildID: guildID,
sessionID: sessionID,
manager: node.manager, manager: node.manager,
node: node, node: node,
handler: handler, handler: handler,

View File

@ -7,6 +7,7 @@ import (
// Player is a Lavalink player // Player is a Lavalink player
type Player struct { type Player struct {
guildID string guildID string
sessionID string
time int time int
position int position int
paused bool paused bool
@ -167,6 +168,8 @@ func (player *Player) UserLeave(userId string) error {
// To move a player to a new Node, first player.Destroy() it, and then // To move a player to a new Node, first player.Destroy() it, and then
// create a new player on the new node. // create a new player on the new node.
func (player *Player) Forward(sessionID string, event VoiceServerUpdate) error { func (player *Player) Forward(sessionID string, event VoiceServerUpdate) error {
player.sessionID = sessionID
msg := voiceUpdateMessage{ msg := voiceUpdateMessage{
Op: opVoiceUpdate, Op: opVoiceUpdate,
GuildID: player.guildID, GuildID: player.guildID,
@ -182,6 +185,8 @@ func (player *Player) Forward(sessionID string, event VoiceServerUpdate) error {
func (player *Player) ChangeNode(node *Node) error { func (player *Player) ChangeNode(node *Node) error {
player.node = node player.node = node
player.Forward(player.sessionID, player.lastVoiceServerUpdate)
return player.PlayAt(player.track, player.position, 0) return player.PlayAt(player.track, player.position, 0)
} }