mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-27 17:23:00 +00:00
Bot: Prettier help formatting
This commit is contained in:
parent
70ace8e5e4
commit
aa53661b60
|
@ -281,8 +281,13 @@ func (ctx *Context) callMessageCreate(mc *gateway.MessageCreateEvent) error {
|
|||
})
|
||||
|
||||
case cmd.Arguments[0].custom != nil:
|
||||
// For consistent behavior, clear the subcommand name off:
|
||||
content = content[len(sub.Command):]
|
||||
var pad = len(cmd.Command)
|
||||
if len(sub.Command) > 0 { // if this is also a subcommand:
|
||||
pad += len(sub.Command) + 1
|
||||
}
|
||||
|
||||
// For consistent behavior, clear the subcommand (and command) name off:
|
||||
content = content[pad:]
|
||||
// Trim space if there are any:
|
||||
content = strings.TrimSpace(content)
|
||||
|
||||
|
|
|
@ -32,6 +32,17 @@ var (
|
|||
}()
|
||||
)
|
||||
|
||||
// HelpUnderline formats command arguments with an underline, similar to
|
||||
// manpages.
|
||||
var HelpUnderline = true
|
||||
|
||||
func underline(word string) string {
|
||||
if HelpUnderline {
|
||||
return "__" + word + "__"
|
||||
}
|
||||
return word
|
||||
}
|
||||
|
||||
// Subcommand is any form of command, which could be a top-level command or a
|
||||
// subcommand.
|
||||
//
|
||||
|
@ -212,7 +223,7 @@ func (sub *Subcommand) Help(indent string, hideAdmin bool) string {
|
|||
var header string
|
||||
|
||||
if sub.Command != "" {
|
||||
header += sub.Command
|
||||
header += "**" + sub.Command + "**"
|
||||
}
|
||||
|
||||
if sub.Description != "" {
|
||||
|
@ -233,15 +244,20 @@ func (sub *Subcommand) Help(indent string, hideAdmin bool) string {
|
|||
continue
|
||||
}
|
||||
|
||||
if sub.Command != "" {
|
||||
switch {
|
||||
case sub.Command != "" && cmd.Command != "":
|
||||
commands += indent + sub.Command + " " + cmd.Command
|
||||
} else {
|
||||
case sub.Command != "":
|
||||
commands += indent + sub.Command
|
||||
default:
|
||||
commands += indent + cmd.Command
|
||||
}
|
||||
|
||||
switch {
|
||||
case len(cmd.Usage()) > 0:
|
||||
commands += " **" + strings.Join(cmd.Usage(), " ") + "**"
|
||||
switch usage := cmd.Usage(); {
|
||||
case len(usage) > 0:
|
||||
for _, usage := range usage {
|
||||
commands += " " + underline(usage)
|
||||
}
|
||||
case cmd.Description != "":
|
||||
commands += ": " + cmd.Description
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue