mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-12-11 16:05:00 +00:00
Bot: clearer subcommand not found error
This commit is contained in:
parent
0932e2903b
commit
ee9d6b0d4d
|
@ -351,20 +351,14 @@ func (ctx *Context) findCommand(parts []string) ([]string, *MethodContext, *Subc
|
||||||
return nil, nil, nil, Break
|
return nil, nil, nil, Break
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil, nil, &ErrUnknownCommand{
|
return nil, nil, nil, newErrUnknownCommand(s, parts)
|
||||||
Parts: parts,
|
|
||||||
Subcmd: s,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.SilentUnknown.Command {
|
if ctx.SilentUnknown.Command {
|
||||||
return nil, nil, nil, Break
|
return nil, nil, nil, Break
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil, nil, &ErrUnknownCommand{
|
return nil, nil, nil, newErrUnknownCommand(ctx.Subcommand, parts)
|
||||||
Parts: parts,
|
|
||||||
Subcmd: ctx.Subcommand,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// searchStringAndSlice searches if str is equal to isString or any of the given
|
// searchStringAndSlice searches if str is equal to isString or any of the given
|
||||||
|
|
22
bot/error.go
22
bot/error.go
|
@ -2,6 +2,7 @@ package bot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,15 +11,28 @@ type ErrUnknownCommand struct {
|
||||||
Subcmd *Subcommand
|
Subcmd *Subcommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err *ErrUnknownCommand) Error() string {
|
func newErrUnknownCommand(s *Subcommand, parts []string) error {
|
||||||
if len(err.Parts) > 2 {
|
if len(parts) > 2 {
|
||||||
err.Parts = err.Parts[:2]
|
parts = parts[:2]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &ErrUnknownCommand{
|
||||||
|
Parts: parts,
|
||||||
|
Subcmd: s,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err *ErrUnknownCommand) Error() string {
|
||||||
return UnknownCommandString(err)
|
return UnknownCommandString(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var UnknownCommandString = func(err *ErrUnknownCommand) string {
|
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 (
|
var (
|
||||||
|
|
Loading…
Reference in a new issue