|
@@ -18,7 +18,6 @@ import (
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"net/http"
|
|
|
- "runtime"
|
|
|
"sync/atomic"
|
|
|
"time"
|
|
|
|
|
@@ -741,55 +740,42 @@ func (s *Session) onVoiceServerUpdate(st *VoiceServerUpdate) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type identifyProperties struct {
|
|
|
- OS string `json:"$os"`
|
|
|
- Browser string `json:"$browser"`
|
|
|
- Device string `json:"$device"`
|
|
|
- Referer string `json:"$referer"`
|
|
|
- ReferringDomain string `json:"$referring_domain"`
|
|
|
-}
|
|
|
-
|
|
|
-type identifyData struct {
|
|
|
- Token string `json:"token"`
|
|
|
- Properties identifyProperties `json:"properties"`
|
|
|
- LargeThreshold int `json:"large_threshold"`
|
|
|
- Compress bool `json:"compress"`
|
|
|
- Shard *[2]int `json:"shard,omitempty"`
|
|
|
-}
|
|
|
-
|
|
|
type identifyOp struct {
|
|
|
- Op int `json:"op"`
|
|
|
- Data identifyData `json:"d"`
|
|
|
+ Op int `json:"op"`
|
|
|
+ Data Identify `json:"d"`
|
|
|
}
|
|
|
|
|
|
// identify sends the identify packet to the gateway
|
|
|
func (s *Session) identify() error {
|
|
|
+ s.log(LogDebug, "called")
|
|
|
|
|
|
- properties := identifyProperties{runtime.GOOS,
|
|
|
- "Discordgo v" + VERSION,
|
|
|
- "",
|
|
|
- "",
|
|
|
- "",
|
|
|
+ // TODO: This is a temporary block of code to help
|
|
|
+ // maintain backwards compatability
|
|
|
+ if s.Compress == false {
|
|
|
+ s.Identify.Compress = false
|
|
|
}
|
|
|
|
|
|
- data := identifyData{s.Token,
|
|
|
- properties,
|
|
|
- 250,
|
|
|
- s.Compress,
|
|
|
- nil,
|
|
|
+ // TODO: This is a temporary block of code to help
|
|
|
+ // maintain backwards compatability
|
|
|
+ if s.Token != "" && s.Identify.Token == "" {
|
|
|
+ s.Identify.Token = s.Token
|
|
|
}
|
|
|
|
|
|
+ // TODO: Below block should be refactored so ShardID and ShardCount
|
|
|
+ // can be deprecated and their usage moved to the Session.Identify
|
|
|
+ // struct
|
|
|
if s.ShardCount > 1 {
|
|
|
|
|
|
if s.ShardID >= s.ShardCount {
|
|
|
return ErrWSShardBounds
|
|
|
}
|
|
|
|
|
|
- data.Shard = &[2]int{s.ShardID, s.ShardCount}
|
|
|
+ s.Identify.Shard = &[2]int{s.ShardID, s.ShardCount}
|
|
|
}
|
|
|
|
|
|
- op := identifyOp{2, data}
|
|
|
-
|
|
|
+ // Send Identify packet to Discord
|
|
|
+ op := identifyOp{2, s.Identify}
|
|
|
+ s.log(LogDebug, "Identify Packet: \n%#v", op)
|
|
|
s.wsMutex.Lock()
|
|
|
err := s.wsConn.WriteJSON(op)
|
|
|
s.wsMutex.Unlock()
|