From a089b52f64e87992794a62d3640468ad95dd4244 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Wed, 22 Aug 2018 21:04:44 -0400 Subject: [PATCH] feature: add ChannelVoiceJoinManual This resolves #577. ChannelVoiceJoinManual is a wrapper over sending an OP4 to Discord, for initiating a voice server connection. The library's builtin voice connection management locks/maps are skipped, and the library will not attempt to manage this voice connection. Users are expected to hook the VoiceServerUpdate event and forward the data to an outside voice manager, such as Lavalink. --- wsapi.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/wsapi.go b/wsapi.go index 80e85ac..93c3bea 100644 --- a/wsapi.go +++ b/wsapi.go @@ -623,6 +623,30 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *Voi return } +// ChannelVoiceJoinManual initiates a voice session to a voice channel, but does not complete it. +// +// This should only be used when the VoiceServerUpdate will be intercepted and used elsewhere. +// +// gID : Guild ID of the channel to join. +// 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. +func (s *Session) ChannelVoiceJoinManual(gID, cID string, mute, deaf bool) (err error) { + + s.log(LogInformational, "called") + + // Send the request to Discord that we want to join the voice channel + data := voiceChannelJoinOp{4, voiceChannelJoinData{&gID, &cID, mute, deaf}} + s.wsMutex.Lock() + err = s.wsConn.WriteJSON(data) + s.wsMutex.Unlock() + if err != nil { + return + } + + return +} + // onVoiceStateUpdate handles Voice State Update events on the data websocket. func (s *Session) onVoiceStateUpdate(st *VoiceStateUpdate) {