From aa53661b60409d1a33c5ece0b72f3365082d4ae3 Mon Sep 17 00:00:00 2001 From: "diamondburned (Forefront)" Date: Thu, 9 Apr 2020 23:10:21 -0700 Subject: [PATCH] Bot: Prettier help formatting --- bot/ctx_call.go | 9 +++++++-- bot/subcommand.go | 28 ++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/bot/ctx_call.go b/bot/ctx_call.go index fe4f6ee..7ccebd5 100644 --- a/bot/ctx_call.go +++ b/bot/ctx_call.go @@ -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) diff --git a/bot/subcommand.go b/bot/subcommand.go index 1cf2cc5..23dae54 100644 --- a/bot/subcommand.go +++ b/bot/subcommand.go @@ -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 }