Skip to content

Commit

Permalink
Call user callback for VOICE_STATE_UPDATE events, closes #101
Browse files Browse the repository at this point in the history
  • Loading branch information
bwmarrin committed Feb 8, 2016
1 parent af52a8c commit 1a0e4c0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions wsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,20 @@ func (s *Session) event(messageType int, message []byte) {
}
return
case "VOICE_STATE_UPDATE":
// TEMP CODE FOR TESTING VOICE
if s.Voice == nil && s.OnVoiceStateUpdate == nil {
break
}
var st *VoiceState
if err = unmarshalEvent(e, &st); err == nil {
s.onVoiceStateUpdate(st)
if s.Voice != nil {
s.onVoiceStateUpdate(st)
}
if s.OnVoiceStateUpdate != nil {
s.OnVoiceStateUpdate(s, st)
return
}

}
return
case "USER_UPDATE":
if s.OnUserUpdate != nil {
var st *User
Expand Down Expand Up @@ -749,12 +757,6 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (err error)
// for the session user.
func (s *Session) onVoiceStateUpdate(st *VoiceState) {

// If s.Voice is nil, we must not have even requested to join
// a voice channel yet, so this shouldn't be processed.
if s.Voice == nil {
return
}

// Need to have this happen at login and store it in the Session
// TODO : This should be done upon connecting to Discord, or
// be moved to a small helper function
Expand Down

0 comments on commit 1a0e4c0

Please sign in to comment.