From 922c32c0eb16e0dc92d61a77eccb931c93daff14 Mon Sep 17 00:00:00 2001 From: "diamondburned (Forefront)" Date: Wed, 8 Apr 2020 23:06:46 -0700 Subject: [PATCH] Bot: Added FindCommand --- bot/subcommand.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bot/subcommand.go b/bot/subcommand.go index 6310a1c..486c79c 100644 --- a/bot/subcommand.go +++ b/bot/subcommand.go @@ -153,6 +153,18 @@ func (sub *Subcommand) NeedsName() { sub.Flag = flag } +// FindCommand finds the command. Nil is returned if nothing is found. It's a +// better idea to not handle nil, as they would become very subtle bugs. +func (sub *Subcommand) FindCommand(methodName string) *CommandContext { + for _, c := range sub.Commands { + if c.MethodName != methodName { + continue + } + return c + } + return nil +} + // ChangeCommandInfo changes the matched methodName's Command and Description. // Empty means unchanged. The returned bool is true when the method is found. func (sub *Subcommand) ChangeCommandInfo(methodName, cmd, desc string) bool {