forked from pothtonswer/discordmuffin
Merge pull request #102 from iopred/voice
VoiceServerUpdate and VoiceStateUpdate. Closes #103
This commit is contained in:
commit
a9d0be6634
2 changed files with 16 additions and 9 deletions
|
@ -46,6 +46,7 @@ type Session struct {
|
|||
OnMessageAck func(*Session, *MessageAck)
|
||||
OnUserUpdate func(*Session, *User)
|
||||
OnPresenceUpdate func(*Session, *PresenceUpdate)
|
||||
OnVoiceServerUpdate func(*Session, *VoiceServerUpdate)
|
||||
OnVoiceStateUpdate func(*Session, *VoiceState)
|
||||
OnChannelCreate func(*Session, *Channel)
|
||||
OnChannelUpdate func(*Session, *Channel)
|
||||
|
|
20
wsapi.go
20
wsapi.go
|
@ -316,12 +316,21 @@ func (s *Session) event(messageType int, message []byte) {
|
|||
return
|
||||
}
|
||||
case "VOICE_SERVER_UPDATE":
|
||||
// TEMP CODE FOR TESTING VOICE
|
||||
if s.Voice == nil && s.OnVoiceServerUpdate == nil {
|
||||
break
|
||||
}
|
||||
var st *VoiceServerUpdate
|
||||
if err = unmarshalEvent(e, &st); err == nil {
|
||||
if s.Voice != nil {
|
||||
s.onVoiceServerUpdate(st)
|
||||
}
|
||||
if s.OnVoiceServerUpdate != nil {
|
||||
s.OnVoiceServerUpdate(s, st)
|
||||
}
|
||||
}
|
||||
if s.OnVoiceServerUpdate != nil {
|
||||
return
|
||||
}
|
||||
case "VOICE_STATE_UPDATE":
|
||||
if s.Voice == nil && s.OnVoiceStateUpdate == nil {
|
||||
break
|
||||
|
@ -333,9 +342,11 @@ func (s *Session) event(messageType int, message []byte) {
|
|||
}
|
||||
if s.OnVoiceStateUpdate != nil {
|
||||
s.OnVoiceStateUpdate(s, st)
|
||||
return
|
||||
}
|
||||
}
|
||||
if s.OnVoiceStateUpdate != nil {
|
||||
return
|
||||
}
|
||||
case "USER_UPDATE":
|
||||
if s.OnUserUpdate != nil {
|
||||
var st *User
|
||||
|
@ -782,11 +793,6 @@ func (s *Session) onVoiceStateUpdate(st *VoiceState) {
|
|||
// connection and should happen after the VOICE_STATE event.
|
||||
func (s *Session) onVoiceServerUpdate(st *VoiceServerUpdate) {
|
||||
|
||||
// This shouldn't ever be the case, I don't think.
|
||||
if s.Voice == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Store values for later use
|
||||
s.Voice.token = st.Token
|
||||
s.Voice.endpoint = st.Endpoint
|
||||
|
|
Loading…
Reference in a new issue