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)
|
OnMessageAck func(*Session, *MessageAck)
|
||||||
OnUserUpdate func(*Session, *User)
|
OnUserUpdate func(*Session, *User)
|
||||||
OnPresenceUpdate func(*Session, *PresenceUpdate)
|
OnPresenceUpdate func(*Session, *PresenceUpdate)
|
||||||
|
OnVoiceServerUpdate func(*Session, *VoiceServerUpdate)
|
||||||
OnVoiceStateUpdate func(*Session, *VoiceState)
|
OnVoiceStateUpdate func(*Session, *VoiceState)
|
||||||
OnChannelCreate func(*Session, *Channel)
|
OnChannelCreate func(*Session, *Channel)
|
||||||
OnChannelUpdate 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
|
return
|
||||||
}
|
}
|
||||||
case "VOICE_SERVER_UPDATE":
|
case "VOICE_SERVER_UPDATE":
|
||||||
// TEMP CODE FOR TESTING VOICE
|
if s.Voice == nil && s.OnVoiceServerUpdate == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
var st *VoiceServerUpdate
|
var st *VoiceServerUpdate
|
||||||
if err = unmarshalEvent(e, &st); err == nil {
|
if err = unmarshalEvent(e, &st); err == nil {
|
||||||
|
if s.Voice != nil {
|
||||||
s.onVoiceServerUpdate(st)
|
s.onVoiceServerUpdate(st)
|
||||||
}
|
}
|
||||||
|
if s.OnVoiceServerUpdate != nil {
|
||||||
|
s.OnVoiceServerUpdate(s, st)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if s.OnVoiceServerUpdate != nil {
|
||||||
return
|
return
|
||||||
|
}
|
||||||
case "VOICE_STATE_UPDATE":
|
case "VOICE_STATE_UPDATE":
|
||||||
if s.Voice == nil && s.OnVoiceStateUpdate == nil {
|
if s.Voice == nil && s.OnVoiceStateUpdate == nil {
|
||||||
break
|
break
|
||||||
|
@ -333,9 +342,11 @@ func (s *Session) event(messageType int, message []byte) {
|
||||||
}
|
}
|
||||||
if s.OnVoiceStateUpdate != nil {
|
if s.OnVoiceStateUpdate != nil {
|
||||||
s.OnVoiceStateUpdate(s, st)
|
s.OnVoiceStateUpdate(s, st)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if s.OnVoiceStateUpdate != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
case "USER_UPDATE":
|
case "USER_UPDATE":
|
||||||
if s.OnUserUpdate != nil {
|
if s.OnUserUpdate != nil {
|
||||||
var st *User
|
var st *User
|
||||||
|
@ -782,11 +793,6 @@ func (s *Session) onVoiceStateUpdate(st *VoiceState) {
|
||||||
// connection and should happen after the VOICE_STATE event.
|
// connection and should happen after the VOICE_STATE event.
|
||||||
func (s *Session) onVoiceServerUpdate(st *VoiceServerUpdate) {
|
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
|
// Store values for later use
|
||||||
s.Voice.token = st.Token
|
s.Voice.token = st.Token
|
||||||
s.Voice.endpoint = st.Endpoint
|
s.Voice.endpoint = st.Endpoint
|
||||||
|
|
Loading…
Reference in a new issue