-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.go
52 lines (42 loc) · 855 Bytes
/
chat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package distance
import (
"net/http"
"net/url"
)
// Chat sends a message using the given player token obtained from calling
// Link() and the private Distance token.
func (c *Client) Chat(playerToken, message string) error {
type chat struct {
Message string
}
cookie := http.Cookie{
Name: "DistanceSession",
Value: playerToken,
}
r, err := c.doJSON("POST",
url.URL{Path: "/chat"},
chat{message},
http.Header{"Cookie": {cookie.String()}},
)
if err != nil {
return err
}
r.Body.Close()
return nil
}
// ServerChat sends a message as the server using the private Distance token.
func (c *Client) ServerChat(message string) error {
type chat struct {
Message string
}
r, err := c.doJSON("POST",
url.URL{Path: "/serverchat"},
chat{message},
nil,
)
if err != nil {
return err
}
r.Body.Close()
return nil
}