-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappcmds.go
96 lines (81 loc) · 2.4 KB
/
appcmds.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
package discord
import (
"github.com/bwmarrin/discordgo"
"github.com/Clinet/clinet_cmds"
"github.com/Clinet/clinet_services"
)
func CmdToAppCommand(cmd *cmds.Cmd) *discordgo.ApplicationCommand {
appCmd := &discordgo.ApplicationCommand{
Name: cmd.Name,
Description: cmd.Description,
}
//Convert command arguments
if len(cmd.Args) > 0 {
for _, arg := range cmd.Args {
appCmdOpt := &discordgo.ApplicationCommandOption{
Name: arg.Name,
Description: arg.Description,
Required: arg.Required,
}
switch arg.Value.(type) {
case string:
appCmdOpt.Type = discordgo.ApplicationCommandOptionString
case int:
appCmdOpt.Type = discordgo.ApplicationCommandOptionInteger
case bool:
appCmdOpt.Type = discordgo.ApplicationCommandOptionBoolean
case *services.User:
appCmdOpt.Type = discordgo.ApplicationCommandOptionUser
}
Log.Trace("- Built appCmdOpt: ", appCmdOpt)
appCmd.Options = append(appCmd.Options, appCmdOpt)
}
}
//Convert subcommands
if len(cmd.Subcommands) > 0 {
for _, subCmd := range cmd.Subcommands {
appCmd.Options = append(appCmd.Options, CmdToAppSubCommand(subCmd))
}
}
Log.Trace("- Built cmd: ", appCmd)
return appCmd
}
func CmdToAppSubCommand(cmd *cmds.Cmd) *discordgo.ApplicationCommandOption {
appSubCmd := &discordgo.ApplicationCommandOption{
Type: discordgo.ApplicationCommandOptionSubCommand,
Name: cmd.Name,
Description: cmd.Description,
}
//Convert command arguments
if len(cmd.Args) > 0 {
for _, arg := range cmd.Args {
appCmdOpt := &discordgo.ApplicationCommandOption{
Name: arg.Name,
Description: arg.Description,
Required: arg.Required,
}
switch arg.Value.(type) {
case string:
appCmdOpt.Type = discordgo.ApplicationCommandOptionString
case int:
appCmdOpt.Type = discordgo.ApplicationCommandOptionInteger
case bool:
appCmdOpt.Type = discordgo.ApplicationCommandOptionBoolean
case *services.User:
appCmdOpt.Type = discordgo.ApplicationCommandOptionUser
}
Log.Trace("- Built appSubCmdOpt: ", appCmdOpt)
appSubCmd.Options = append(appSubCmd.Options, appCmdOpt)
}
}
Log.Trace("- Built subcmd: ", appSubCmd)
return appSubCmd
}
func CmdsToAppCommands() []*discordgo.ApplicationCommand {
appCmds := make([]*discordgo.ApplicationCommand, 0)
for _, cmd := range cmds.Commands {
//Add finalized cmd to list
appCmds = append(appCmds, CmdToAppCommand(cmd))
}
return appCmds
}