Bot: Help generators now allow generating hidden commands
This commit is contained in:
parent
bf7ca8450d
commit
56b1a7cce8
13
bot/ctx.go
13
bot/ctx.go
|
@ -372,8 +372,15 @@ func (ctx *Context) Call(event interface{}) error {
|
|||
}
|
||||
|
||||
// Help generates a full Help message. It serves mainly as a reference for
|
||||
// people to reimplement and change.
|
||||
// people to reimplement and change. It doesn't show hidden commands.
|
||||
func (ctx *Context) Help() string {
|
||||
return ctx.HelpGenerate(false)
|
||||
}
|
||||
|
||||
// HelpGenerate generates a full Help message. It serves mainly as a reference
|
||||
// for people to reimplement and change. If showHidden is true, then hidden
|
||||
// subcommands and commands will be shown.
|
||||
func (ctx *Context) HelpGenerate(showHidden bool) string {
|
||||
// Generate the header.
|
||||
buf := strings.Builder{}
|
||||
buf.WriteString("__Help__")
|
||||
|
@ -400,11 +407,11 @@ func (ctx *Context) Help() string {
|
|||
var subhelps = make([]string, 0, len(subcommands))
|
||||
|
||||
for _, sub := range subcommands {
|
||||
if sub.Hidden {
|
||||
if sub.Hidden && !showHidden {
|
||||
continue
|
||||
}
|
||||
|
||||
help := sub.Help()
|
||||
help := sub.HelpShowHidden(showHidden)
|
||||
if help == "" {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -174,25 +174,33 @@ func (sub *Subcommand) ChangeCommandInfo(methodName, cmd, desc string) {
|
|||
}
|
||||
|
||||
// Help calls the subcommand's Help() or auto-generates one with HelpGenerate()
|
||||
// if the subcommand doesn't implement CanHelp.
|
||||
// if the subcommand doesn't implement CanHelp. It doesn't show hidden commands
|
||||
// by default.
|
||||
func (sub *Subcommand) Help() string {
|
||||
return sub.HelpShowHidden(false)
|
||||
}
|
||||
|
||||
// HelpShowHidden does the same as Help(), except it will render hidden commands
|
||||
// if the subcommand doesn't implement CanHelp and showHiddeen is true.
|
||||
func (sub *Subcommand) HelpShowHidden(showHidden bool) string {
|
||||
// Check if the subcommand implements CanHelp.
|
||||
if sub.helper != nil {
|
||||
return sub.helper()
|
||||
}
|
||||
return sub.HelpGenerate()
|
||||
return sub.HelpGenerate(showHidden)
|
||||
}
|
||||
|
||||
// HelpGenerate auto-generates a help message. Use this only if you want to
|
||||
// override the Subcommand's help, else use Help().
|
||||
func (sub *Subcommand) HelpGenerate() string {
|
||||
// override the Subcommand's help, else use Help(). This function will show
|
||||
// hidden commands if showHidden is true.
|
||||
func (sub *Subcommand) HelpGenerate(showHidden bool) string {
|
||||
// A wider space character.
|
||||
const s = "\u2000"
|
||||
|
||||
var buf strings.Builder
|
||||
|
||||
for i, cmd := range sub.Commands {
|
||||
if cmd.Hidden {
|
||||
if cmd.Hidden && !showHidden {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue