-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
122 lines (108 loc) · 2.68 KB
/
config.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package paginator
import (
"time"
"github.com/disgoorg/disgo/discord"
)
func DefaultConfig() *Config {
return &Config{
ButtonsConfig: ButtonsConfig{
First: &ComponentOptions{
Emoji: discord.ComponentEmoji{
Name: "⏮",
},
Style: discord.ButtonStylePrimary,
},
Back: &ComponentOptions{
Emoji: discord.ComponentEmoji{
Name: "◀",
},
Style: discord.ButtonStylePrimary,
},
Stop: &ComponentOptions{
Emoji: discord.ComponentEmoji{
Name: "🗑",
},
Style: discord.ButtonStyleDanger,
},
Next: &ComponentOptions{
Emoji: discord.ComponentEmoji{
Name: "▶",
},
Style: discord.ButtonStylePrimary,
},
Last: &ComponentOptions{
Emoji: discord.ComponentEmoji{
Name: "⏩",
},
Style: discord.ButtonStylePrimary,
},
},
NoPermissionMessage: "You can't interact with this paginator because it's not yours.",
CustomIDPrefix: "paginator",
EmbedColor: 0x4c50c1,
CleanupInterval: 30 * time.Second,
ExpireTime: 5 * time.Minute,
}
}
type Config struct {
ButtonsConfig ButtonsConfig
NoPermissionMessage string
CustomIDPrefix string
EmbedColor int
CleanupInterval time.Duration
ExpireTime time.Duration
}
type ButtonsConfig struct {
First *ComponentOptions
Back *ComponentOptions
Stop *ComponentOptions
Next *ComponentOptions
Last *ComponentOptions
}
type ComponentOptions struct {
Emoji discord.ComponentEmoji
Label string
Style discord.ButtonStyle
}
type ConfigOpt func(config *Config)
func (c *Config) Apply(opts []ConfigOpt) {
for _, opt := range opts {
opt(c)
}
}
//goland:noinspection GoUnusedExportedFunction
func WithButtonsConfig(buttonsConfig ButtonsConfig) ConfigOpt {
return func(config *Config) {
config.ButtonsConfig = buttonsConfig
}
}
//goland:noinspection GoUnusedExportedFunction
func WithNoPermissionMessage(noPermissionMessage string) ConfigOpt {
return func(config *Config) {
config.NoPermissionMessage = noPermissionMessage
}
}
//goland:noinspection GoUnusedExportedFunction
func WithCustomIDPrefix(prefix string) ConfigOpt {
return func(config *Config) {
config.CustomIDPrefix = prefix
}
}
//goland:noinspection GoUnusedExportedFunction
func WithEmbedColor(color int) ConfigOpt {
return func(config *Config) {
config.EmbedColor = color
}
}
//goland:noinspection GoUnusedExportedFunction
func WithCleanupInterval(cleanupInterval time.Duration) ConfigOpt {
return func(config *Config) {
config.CleanupInterval = cleanupInterval
}
}
//goland:noinspection GoUnusedExportedFunction
func WithTimeout(timeout time.Duration) ConfigOpt {
return func(config *Config) {
config.ExpireTime = timeout
}
}