Use unique user in unknown command test to avoid last-command fallback interference. Add plugin architecture with registered commands. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 lines
979 B
Go
37 lines
979 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
type HelpPlugin struct{}
|
|
|
|
func (p HelpPlugin) Name() string { return "help" }
|
|
func (p HelpPlugin) ShortHelp() string { return "List commands or get help for a specific command" }
|
|
func (p HelpPlugin) DetailedHelp() string {
|
|
return "help [command]\n\nWith no arguments, lists all available commands.\nWith a command name, shows detailed help for that command.\n\nExamples:\n help\n help math"
|
|
}
|
|
func (p HelpPlugin) Execute(msg BotMessage, args string) string {
|
|
if args == "" {
|
|
names := make([]string, 0, len(registry))
|
|
for name := range registry {
|
|
names = append(names, name)
|
|
}
|
|
sort.Strings(names)
|
|
|
|
var sb strings.Builder
|
|
for _, name := range names {
|
|
fmt.Fprintf(&sb, "%s — %s\n", name, registry[name].ShortHelp())
|
|
}
|
|
return sb.String()
|
|
}
|
|
|
|
if plugin, ok := registry[args]; ok {
|
|
return plugin.DetailedHelp()
|
|
}
|
|
|
|
return fmt.Sprintf("No help found for '%s'. Try 'help' to see all commands.", args)
|
|
}
|