forked from pothtonswer/discordmuffin
Converted to using structs for data websocket handshake. Also using VERSION variable in $browser setting
This commit is contained in:
parent
383b4645da
commit
d59d47967c
1 changed files with 21 additions and 18 deletions
39
wsapi.go
39
wsapi.go
|
@ -31,28 +31,31 @@ func (s *Session) Open() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe this is SendOrigin? not sure the right name here
|
type handshakeProperties struct {
|
||||||
// also bson.M vs string interface map? Read about
|
OS string `json:"$os"`
|
||||||
// how to send JSON the right way.
|
Browser string `json:"$browser"`
|
||||||
|
Device string `json:"$device"`
|
||||||
|
Referer string `json:"$referer"`
|
||||||
|
ReferringDomain string `json:"$referring_domain"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type handshakeData struct {
|
||||||
|
Version int `json:"v"`
|
||||||
|
Token string `json:"token"`
|
||||||
|
Properties handshakeProperties `json:"properties"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type handshakeOp struct {
|
||||||
|
Op int `json:"op"`
|
||||||
|
Data handshakeData `json:"d"`
|
||||||
|
}
|
||||||
|
|
||||||
// Handshake sends the client data to Discord during websocket initial connection.
|
// Handshake sends the client data to Discord during websocket initial connection.
|
||||||
func (s *Session) Handshake() (err error) {
|
func (s *Session) Handshake() (err error) {
|
||||||
|
// maybe this is SendOrigin? not sure the right name here
|
||||||
|
|
||||||
err = s.wsConn.WriteJSON(map[string]interface{}{
|
data := handshakeOp{2, handshakeData{3, s.Token, handshakeProperties{runtime.GOOS, "DiscordGo v" + VERSION, "", "", ""}}}
|
||||||
"op": 2,
|
err = s.wsConn.WriteJSON(data)
|
||||||
"d": map[string]interface{}{
|
|
||||||
"v": 3,
|
|
||||||
"token": s.Token,
|
|
||||||
"properties": map[string]string{
|
|
||||||
"$os": runtime.GOOS,
|
|
||||||
"$browser": "Discordgo",
|
|
||||||
"$device": "Discordgo",
|
|
||||||
"$referer": "",
|
|
||||||
"$referring_domain": "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue