1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-02 11:52:56 +00:00

Bot: clearer subcommand not found error

This commit is contained in:
diamondburned 2020-11-14 22:11:10 -08:00
parent 0932e2903b
commit ee9d6b0d4d
2 changed files with 20 additions and 12 deletions

View file

@ -351,20 +351,14 @@ func (ctx *Context) findCommand(parts []string) ([]string, *MethodContext, *Subc
return nil, nil, nil, Break
}
return nil, nil, nil, &ErrUnknownCommand{
Parts: parts,
Subcmd: s,
}
return nil, nil, nil, newErrUnknownCommand(s, parts)
}
if ctx.SilentUnknown.Command {
return nil, nil, nil, Break
}
return nil, nil, nil, &ErrUnknownCommand{
Parts: parts,
Subcmd: ctx.Subcommand,
}
return nil, nil, nil, newErrUnknownCommand(ctx.Subcommand, parts)
}
// searchStringAndSlice searches if str is equal to isString or any of the given

View file

@ -2,6 +2,7 @@ package bot
import (
"errors"
"fmt"
"strings"
)
@ -10,15 +11,28 @@ type ErrUnknownCommand struct {
Subcmd *Subcommand
}
func (err *ErrUnknownCommand) Error() string {
if len(err.Parts) > 2 {
err.Parts = err.Parts[:2]
func newErrUnknownCommand(s *Subcommand, parts []string) error {
if len(parts) > 2 {
parts = parts[:2]
}
return &ErrUnknownCommand{
Parts: parts,
Subcmd: s,
}
}
func (err *ErrUnknownCommand) Error() string {
return UnknownCommandString(err)
}
var UnknownCommandString = func(err *ErrUnknownCommand) string {
return "unknown command: " + strings.Join(err.Parts, " ")
// Subcommand check.
if err.Subcmd.StructName == "" || len(err.Parts) < 2 {
return "unknown command: " + err.Parts[0]
}
return fmt.Sprintf("unknown %s subcommand: %s", err.Parts[0], err.Parts[1])
}
var (