-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
53 lines (42 loc) · 1.14 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
package disroute
import (
"strings"
"github.com/bwmarrin/discordgo"
)
type handlerData struct {
path string
opts map[string]*DiscordCmdOption
}
func buildHandlerData(i *discordgo.Interaction) *handlerData {
d := i.ApplicationCommandData()
pathParts := []string{d.Name}
options := buildOptionsMap(d.Options)
if len(d.Options) == 0 {
return &handlerData{
path: strings.Join(pathParts, ":"),
opts: options,
}
}
if d.Options[0].Type == discordgo.ApplicationCommandOptionSubCommand {
pathParts = append(pathParts, d.Options[0].Name)
options = buildOptionsMap(d.Options[0].Options)
}
if d.Options[0].Type == discordgo.ApplicationCommandOptionSubCommandGroup {
pathParts = append(pathParts,
d.Options[0].Name,
d.Options[0].Options[0].Name,
)
options = buildOptionsMap(d.Options[0].Options[0].Options)
}
return &handlerData{
path: strings.Join(pathParts, ":"),
opts: options,
}
}
func buildOptionsMap(options []*DiscordCmdOption) map[string]*DiscordCmdOption {
commandOptions := make(map[string]*DiscordCmdOption)
for _, option := range options {
commandOptions[option.Name] = option
}
return commandOptions
}