/
settings.go
61 lines (50 loc) · 1.53 KB
/
settings.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
package role
import "github.com/skwair/harmony/optional"
// Settings describes how to modify a guild role. All fields are optional.
type Settings struct {
Name *optional.String `json:"name,omitempty"`
Permissions *optional.Int `json:"permissions,omitempty"`
Color *optional.Int `json:"color,omitempty"`
Hoist *optional.Bool `json:"hoist,omitempty"`
Mentionable *optional.Bool `json:"mentionable,omitempty"`
}
// Setting is a function that configures a guild role.
type Setting func(*Settings)
// NewSettings returns new Settings to modify a a guild role.
func NewSettings(opts ...Setting) *Settings {
s := &Settings{}
for _, opt := range opts {
opt(s)
}
return s
}
// WithName sets the name of guild a role.
func WithName(name string) Setting {
return func(s *Settings) {
s.Name = optional.NewString(name)
}
}
// WithPermissions sets the permissions of guild a role.
func WithPermissions(perm int) Setting {
return func(s *Settings) {
s.Permissions = optional.NewInt(perm)
}
}
// WithColor sets the color of guild a role. It accepts hexadecimal value.
func WithColor(hexCode int) Setting {
return func(s *Settings) {
s.Color = optional.NewInt(hexCode)
}
}
// WithHoist sets whether this guild role is hoisted.
func WithHoist(yes bool) Setting {
return func(s *Settings) {
s.Hoist = optional.NewBool(yes)
}
}
// WithMentionable sets whether this guild role is mentionable by others.
func WithMentionable(yes bool) Setting {
return func(s *Settings) {
s.Mentionable = optional.NewBool(yes)
}
}