Call user callback for VOICE_STATE_UPDATE events, closes #101
This commit is contained in:
parent
af52a8c822
commit
1a0e4c05fa
1 changed files with 11 additions and 9 deletions
16
wsapi.go
16
wsapi.go
|
@ -323,12 +323,20 @@ func (s *Session) event(messageType int, message []byte) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case "VOICE_STATE_UPDATE":
|
case "VOICE_STATE_UPDATE":
|
||||||
// TEMP CODE FOR TESTING VOICE
|
if s.Voice == nil && s.OnVoiceStateUpdate == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
var st *VoiceState
|
var st *VoiceState
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
|
if s.Voice != nil {
|
||||||
s.onVoiceStateUpdate(st)
|
s.onVoiceStateUpdate(st)
|
||||||
}
|
}
|
||||||
|
if s.OnVoiceStateUpdate != nil {
|
||||||
|
s.OnVoiceStateUpdate(s, st)
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
case "USER_UPDATE":
|
case "USER_UPDATE":
|
||||||
if s.OnUserUpdate != nil {
|
if s.OnUserUpdate != nil {
|
||||||
var st *User
|
var st *User
|
||||||
|
@ -749,12 +757,6 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (err error)
|
||||||
// for the session user.
|
// for the session user.
|
||||||
func (s *Session) onVoiceStateUpdate(st *VoiceState) {
|
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
|
// Need to have this happen at login and store it in the Session
|
||||||
// TODO : This should be done upon connecting to Discord, or
|
// TODO : This should be done upon connecting to Discord, or
|
||||||
// be moved to a small helper function
|
// be moved to a small helper function
|
||||||
|
|
Loading…
Reference in a new issue