From 1af71182d020339a5d0808fbe2a3d5c5b486d12d Mon Sep 17 00:00:00 2001 From: diamondburned Date: Mon, 3 Oct 2022 22:37:40 -0700 Subject: [PATCH] session: Add DontWaitForReady This is a workaround for some cases where ReadyEvent cannot be delivered successfully, e.g. in the case of an unmarshal failure. We should handle BackgroundErrorEvents in the future that fatally exits on any unmarshal errors. --- session/session.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/session/session.go b/session/session.go index ef9f4a5..9f98f7f 100644 --- a/session/session.go +++ b/session/session.go @@ -32,6 +32,14 @@ type Session struct { // internal state to not be copied around. state *sessionState + + // Options, all of which default to the zero value. + + // DontWaitForReady makes Open not wait for the Ready event. This is useful + // for non-bots, since Discord may send over a READY_SUPPLEMENT instead. If + // this is true, then any event sent by Discord will unblock Open (usually + // HELLO). + DontWaitForReady bool } type sessionState struct { @@ -261,6 +269,10 @@ func (s *Session) Open(ctx context.Context) error { return s.state.gateway.LastError() case ev := <-evCh: + if s.DontWaitForReady { + return nil + } + switch ev.(type) { case *gateway.ReadyEvent, *gateway.ResumedEvent: return nil