feature: expose player Guild ID, current track

This commit is contained in:
Christopher F 2018-08-25 22:58:41 -04:00
parent 2fd6d25b7b
commit e1f823649f
2 changed files with 14 additions and 0 deletions

View File

@ -120,6 +120,7 @@ func (node *Node) onEvent(msgType int, msg []byte) error {
switch m.Type { switch m.Type {
case eventTrackEnd: case eventTrackEnd:
player.track = ""
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)

View File

@ -14,11 +14,17 @@ type Player struct {
position int position int
paused bool paused bool
vol int vol int
track string
manager *Lavalink manager *Lavalink
node *Node node *Node
handler EventHandler handler EventHandler
} }
// GuildID returns this player's Guild ID
func (player *Player) GuildID() string {
return player.guildID
}
// Play will play the given track completely // Play will play the given track completely
func (player *Player) Play(track string) error { func (player *Player) Play(track string) error {
return player.PlayAt(track, 0, 0) return player.PlayAt(track, 0, 0)
@ -29,6 +35,7 @@ func (player *Player) Play(track string) error {
// Setting a time to 0 will omit it. // Setting a time to 0 will omit it.
func (player *Player) PlayAt(track string, startTime int, endTime int) error { func (player *Player) PlayAt(track string, startTime int, endTime int) error {
player.paused = false player.paused = false
player.track = track
start := strconv.Itoa(startTime) start := strconv.Itoa(startTime)
end := strconv.Itoa(endTime) end := strconv.Itoa(endTime)
@ -48,8 +55,14 @@ func (player *Player) PlayAt(track string, startTime int, endTime int) error {
return err return err
} }
// Track returns the player's current track
func (player *Player) Track() string {
return player.track
}
// Stop will stop the currently playing track // Stop will stop the currently playing track
func (player *Player) Stop() error { func (player *Player) Stop() error {
player.track = ""
msg := message{ msg := message{
Op: opStop, Op: opStop,
GuildID: player.guildID, GuildID: player.guildID,