From 7ec5304bc9c176c4011626ff4103b1ed93dc5f44 Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Tue, 15 Mar 2016 08:30:05 -0500 Subject: [PATCH] ChannelVoiceJoin now waits for the connection. You can return to the previous behaviour just by calling the function as a goroutine. However I feel most uses of it require the connection to be ready before the next step. --- wsapi.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/wsapi.go b/wsapi.go index b4dd701..94edb1d 100644 --- a/wsapi.go +++ b/wsapi.go @@ -336,23 +336,19 @@ type voiceChannelJoinOp struct { // cID : Channel ID of the channel to join. // mute : If true, you will be set to muted upon joining. // deaf : If true, you will be set to deafened upon joining. -// timeout : If timeout > 0 then func will wait up to timeout for voice -// connection to be ready. If it does not become ready in that -// time frame then it will return an error and close out the voice -// connection entirely. -func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool, timeout int) (voice *VoiceConnection, err error) { +func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *VoiceConnection, err error) { // If a voice connection alreadyy exists for this guild then // return that connection. If the channel differs, also change channels. // TODO: check if the voice connection is really valid or just a shell // because we might want to allow setting variables prior to getting here // like debug, and other things. - if voice, ok := s.VoiceConnections[gID]; ok { + var ok bool + if voice, ok = s.VoiceConnections[gID]; ok { if voice.ChannelID != cID { err = voice.ChangeChannel(cID) } - return voice, err - // TODO: ugh, ugly.. + return } // Create a new voice session @@ -366,7 +362,7 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool, timeout int ChannelID: cID, } - // Store voice in VoiceConnections map for thils GuildID + // Store voice in VoiceConnections map for this GuildID s.VoiceConnections[gID] = voice // Send the request to Discord that we want to join the voice channel @@ -377,13 +373,11 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool, timeout int } // doesn't exactly work perfect yet.. TODO - if timeout > 0 { - err = voice.WaitUntilConnected() - if err != nil { - voice.Close() - delete(s.VoiceConnections, gID) - return - } + err = voice.WaitUntilConnected() + if err != nil { + voice.Close() + delete(s.VoiceConnections, gID) + return } return