Skip to content

Commit

Permalink
Bot: fixed bug where subcommands with no visible commands would show
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Jan 26, 2020
1 parent 6255d1d commit 77729ea
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions bot/subcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,46 +154,51 @@ func (sub *Subcommand) Help(prefix, indent string, hideAdmin bool) string {
return ""
}

if len(sub.Commands) == 0 {
return ""
}
// The header part:
var header string

var subHelp string
if sub.Command != "" {
subHelp += indent + sub.Command
header += indent + sub.Command
}

if sub.Description != "" {
if subHelp != "" {
subHelp += ": "
if header != "" {
header += ": "
} else {
subHelp += indent
header += indent
}

subHelp += sub.Description
header += sub.Description
}

subHelp += "\n"
header += "\n"

// The commands part:
var commands = ""

for _, cmd := range sub.Commands {
if cmd.Flag.Is(AdminOnly) && hideAdmin {
continue
}

subHelp += indent + indent +
commands += indent + indent +
prefix + sub.Command + " " + cmd.Command

switch {
case len(cmd.Usage()) > 0:
subHelp += " " + strings.Join(cmd.Usage(), " ")
commands += " " + strings.Join(cmd.Usage(), " ")
case cmd.Description != "":
subHelp += ": " + cmd.Description
commands += ": " + cmd.Description
}

subHelp += "\n"
commands += "\n"
}

if commands == "" {
return ""
}

return subHelp
return header + commands
}

func (sub *Subcommand) reflectCommands() error {
Expand Down

0 comments on commit 77729ea

Please sign in to comment.