/
gen-commands-docs.go
81 lines (61 loc) · 2.09 KB
/
gen-commands-docs.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
package main
import (
"bytes"
"os"
"strings"
"github.com/jonas747/dcmd"
"github.com/jonas747/yagpdb/commands"
)
func GenCommandsDocs() {
// func GenerateHelp(d *Data, container *Container, formatter HelpFormatter) (embeds []*discordgo.MessageEmbed) {
sets := dcmd.SortCommands(commands.CommandSystem.Root, commands.CommandSystem.Root)
var out bytes.Buffer
out.WriteString("## Legend\n\n")
out.WriteString("`<required arg>` `[optional arg]`\n\n")
out.WriteString("Text arguments containing multiple words needs be to put in quotes (\"arg here\") or code ticks (`arg here`) if it's not the last argument and there's more than 1 text argument.\n\n")
out.WriteString("For example with the poll command if you want the question to have multiple words: `-poll \"whats your favorite color\" red blue green2`\n\n")
stdHelpFmt := &dcmd.StdHelpFormatter{}
mockCmdData := &dcmd.Data{}
for _, set := range sets {
out.WriteString("## " + set.Name() + " " + set.Emoji() + "\n\n")
for _, entry := range set.Commands {
// get the main name
nameStr := entry.Container.FullName(false)
if nameStr != "" {
nameStr += " "
}
nameStr += entry.Cmd.Trigger.Names[0]
// then aliases
aliases := strings.Join(entry.Cmd.Trigger.Names[1:], "/")
// arguments and switches
args := stdHelpFmt.ArgDefs(entry.Cmd, mockCmdData)
switches := stdHelpFmt.Switches(entry.Cmd.Command)
// grab the description
desc := ""
if cast, ok := entry.Cmd.Command.(dcmd.CmdWithDescriptions); ok {
short, long := cast.Descriptions(mockCmdData)
if long != "" {
desc = long
} else if short != "" {
desc = short
} else {
desc = "No description for this command"
}
}
out.WriteString("### " + nameStr + "\n\n")
if aliases != "" {
out.WriteString("**Aliases:** " + aliases + "\n\n")
}
out.WriteString(desc)
out.WriteString("\n\n")
out.WriteString("**Usage:**\n")
out.WriteString("```\n" + args + "\n```\n")
if switches != "" {
out.WriteString("```\n" + switches + "\n```\n")
}
out.WriteString("\n")
}
}
os.Stdout.Write(out.Bytes())
return
}