-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.go
78 lines (66 loc) · 1.33 KB
/
util.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
package dgrs
import (
"context"
"strings"
"time"
"github.com/bwmarrin/discordgo"
)
func (s *State) joinKeys(keys ...string) string {
n := len(s.options.KeyPrefix) + len(keys)
for i := 0; i < len(keys); i++ {
n += len(keys[i])
}
b := strings.Builder{}
b.Grow(n)
b.WriteString(s.options.KeyPrefix)
for _, s := range keys {
b.WriteRune(keySeperator)
b.WriteString(s)
}
return b.String()
}
func (s *State) getContext() (ctx context.Context, cf context.CancelFunc) {
if s.options.CommandTimeout > 0 {
ctx, cf = context.WithTimeout(context.Background(), s.options.CommandTimeout)
} else {
cf = func() {}
ctx = context.Background()
}
return
}
func (s *State) getLifetime(v interface{}) (d time.Duration) {
lt := s.options.Lifetimes
switch v.(type) {
case *discordgo.Guild:
d = lt.Guild
case *discordgo.Member:
d = lt.Member
case *discordgo.User:
d = lt.User
case *discordgo.Role:
d = lt.Role
case *discordgo.Channel:
d = lt.Channel
case *discordgo.Emoji:
d = lt.Emoji
case *discordgo.Message:
d = lt.Message
case *discordgo.VoiceState:
d = lt.VoiceState
case *discordgo.Presence:
d = lt.Presence
}
if d < 0 || d == 0 && lt.OverrrideZero {
d = lt.General
}
return
}
func optBool(v []bool) bool {
return len(v) != 0 && v[0]
}
func optInt(v []int) (i int) {
if len(v) != 0 {
i = v[0]
}
return
}