From 332141b083d64a95537b876a367a0418c1ae8125 Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Fri, 18 Dec 2015 20:51:48 -0600 Subject: [PATCH] Updated VoiceChannelJoin func to use struct for data sent over websocket. Also returns an error now. --- wsapi.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/wsapi.go b/wsapi.go index 3c5fe89..c276f0b 100644 --- a/wsapi.go +++ b/wsapi.go @@ -448,29 +448,38 @@ type VoiceServerUpdate struct { Endpoint string `json:"endpoint"` } +type voiceChannelJoinData struct { + GuildID string `json:"guild_id"` + ChannelID string `json:"channel_id"` + SelfMute bool `json:"self_mute"` + SelfDeaf bool `json:"self_deaf"` +} + +type voiceChannelJoinOp struct { + Op int `json:"op"` + Data voiceChannelJoinData `json:"d"` +} + // VoiceChannelJoin joins the authenticated session user to // a voice channel. All the voice magic starts with this. -func (s *Session) VoiceChannelJoin(guildID, channelID string) { +func (s *Session) VoiceChannelJoin(guildID, channelID string) (err error) { if s.wsConn == nil { fmt.Println("error: no websocket connection exists.") return // TODO return error } - // Odd, but.. it works. map interface caused odd unknown opcode error - // Later I'll test with a struct - json := []byte(fmt.Sprintf(`{"op":4,"d":{"guild_id":"%s","channel_id":"%s","self_mute":false,"self_deaf":false}}`, - guildID, channelID)) - - err := s.wsConn.WriteMessage(websocket.TextMessage, json) + data := voiceChannelJoinOp{4, voiceChannelJoinData{guildID, channelID, false, false}} + err = s.wsConn.WriteJSON(data) if err != nil { - fmt.Println("error:", err) return } // Probably will be removed later. s.VGuildID = guildID s.VChannelID = channelID + + return } // onVoiceStateUpdate handles Voice State Update events on the data