diff --git a/discord.go b/discord.go index aa9efd6..a453a4d 100644 --- a/discord.go +++ b/discord.go @@ -41,7 +41,7 @@ func New(token string) (s *Session, err error) { MaxRestRetries: 3, Client: &http.Client{Timeout: (20 * time.Second)}, UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")", - Sequence: new(int64), + sequence: new(int64), LastHeartbeatAck: time.Now().UTC(), } diff --git a/event.go b/event.go index 308a779..84dbdc7 100644 --- a/event.go +++ b/event.go @@ -243,5 +243,5 @@ func (s *Session) onInterface(i interface{}) { func (s *Session) onReady(r *Ready) { // Store the SessionID within the Session struct. - s.SessionID = r.SessionID + s.sessionID = r.SessionID } diff --git a/structs.go b/structs.go index 9399bf6..02adaa1 100644 --- a/structs.go +++ b/structs.go @@ -115,14 +115,14 @@ type Session struct { // When nil, the session is not listening. listening chan interface{} - // Sequence tracks the current gateway api websocket sequence number - Sequence *int64 + // sequence tracks the current gateway api websocket sequence number + sequence *int64 // stores sessions current Discord Gateway gateway string - // SessionID stores session ID of current Gateway connection - SessionID string + // stores session ID of current Gateway connection + sessionID string // used to make sure gateway websocket writes do not happen concurrently wsMutex sync.Mutex diff --git a/wsapi.go b/wsapi.go index eb12794..f2c228d 100644 --- a/wsapi.go +++ b/wsapi.go @@ -123,8 +123,8 @@ func (s *Session) Open() error { // Now we send either an Op 2 Identity if this is a brand new // connection or Op 6 Resume if we are resuming an existing connection. - sequence := atomic.LoadInt64(s.Sequence) - if s.SessionID == "" && sequence == 0 { + sequence := atomic.LoadInt64(s.sequence) + if s.sessionID == "" && sequence == 0 { // Send Op 2 Identity Packet err = s.identify() @@ -139,7 +139,7 @@ func (s *Session) Open() error { p := resumePacket{} p.Op = 6 p.Data.Token = s.Token - p.Data.SessionID = s.SessionID + p.Data.SessionID = s.sessionID p.Data.Sequence = sequence s.log(LogInformational, "sending resume packet to gateway") @@ -291,7 +291,7 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{} s.RLock() last := s.LastHeartbeatAck s.RUnlock() - sequence := atomic.LoadInt64(s.Sequence) + sequence := atomic.LoadInt64(s.sequence) s.log(LogDebug, "sending gateway websocket heartbeat seq %d", sequence) s.wsMutex.Lock() s.LastHeartbeatSent = time.Now().UTC() @@ -518,7 +518,7 @@ func (s *Session) onEvent(messageType int, message []byte) (*Event, error) { if e.Operation == 1 { s.log(LogInformational, "sending heartbeat in response to Op1") s.wsMutex.Lock() - err = s.wsConn.WriteJSON(heartbeatOp{1, atomic.LoadInt64(s.Sequence)}) + err = s.wsConn.WriteJSON(heartbeatOp{1, atomic.LoadInt64(s.sequence)}) s.wsMutex.Unlock() if err != nil { s.log(LogError, "error sending heartbeat in response to Op1") @@ -574,7 +574,7 @@ func (s *Session) onEvent(messageType int, message []byte) (*Event, error) { } // Store the message sequence - atomic.StoreInt64(s.Sequence, e.Sequence) + atomic.StoreInt64(s.sequence, e.Sequence) // Map event to registered event handlers and pass it along to any registered handlers. if eh, ok := registeredInterfaceProviders[e.Type]; ok {