-
Notifications
You must be signed in to change notification settings - Fork 1
/
system.go
88 lines (74 loc) · 2.47 KB
/
system.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package pkgo
import (
"time"
)
// System holds all the data for a system
type System struct {
ID string `json:"id"`
Created time.Time `json:"created"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Tag string `json:"tag,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
Banner string `json:"banner,omitempty"`
Timezone string `json:"tz,omitempty"`
DescriptionPrivacy Privacy `json:"description_privacy,omitempty"`
MemberListPrivacy Privacy `json:"member_list_privacy,omitempty"`
FrontPrivacy Privacy `json:"front_privacy,omitempty"`
FrontHistoryPrivacy Privacy `json:"front_history_privacy,omitempty"`
}
// Me gets the current token's system.
// If force is set to true, this will always fetch the system from the API.
func (s *Session) Me(force bool) (sys *System, err error) {
if s.token == "" {
return nil, ErrNoToken
}
if !force && s.system != nil {
return s.system, nil
}
sys = &System{}
err = s.RequestJSON("GET", "/s", sys)
if err != nil {
return
}
s.system = sys
return
}
// System gets a system by its 5-character system ID.
// Some fields may be empty if unauthenticated and the system has chosen to make those fields private.
func (s *Session) System(id string) (sys *System, err error) {
if !idRe.MatchString(id) {
return nil, ErrInvalidID
}
sys = &System{}
err = s.RequestJSON("GET", "/s/"+id, sys)
return
}
// Account gets a system by a Discord snowflake (user ID).
func (s *Session) Account(id Snowflake) (sys *System, err error) {
sys = &System{}
err = s.RequestJSON("GET", "/a/"+id.String(), &sys)
return
}
// EditSystemData ...
type EditSystemData struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Tag string `json:"tag,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
Banner string `json:"banner,omitempty"`
Timezone string `json:"tz,omitempty"`
DescriptionPrivacy Privacy `json:"description_privacy,omitempty"`
MemberListPrivacy Privacy `json:"member_list_privacy,omitempty"`
FrontPrivacy Privacy `json:"front_privacy,omitempty"`
FrontHistoryPrivacy Privacy `json:"front_history_privacy,omitempty"`
}
// EditSystem edits your system with the provided data.
func (s *Session) EditSystem(psd EditSystemData) (sys *System, err error) {
sys = &System{}
err = s.RequestJSON("PATCH", "/s", sys, WithJSONBody(psd))
if err != nil {
return nil, err
}
return sys, err
}