mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-07 12:38:05 +00:00
Bot: Fixed CustomParser trim not using aliases and plumbs
This commit is contained in:
parent
af63bb2e66
commit
42724e0b91
|
@ -261,12 +261,10 @@ func (ctx *Context) callMessageCreate(mc *gateway.MessageCreateEvent, value refl
|
||||||
// have erroneous hanging quotes.
|
// have erroneous hanging quotes.
|
||||||
parseErr = nil
|
parseErr = nil
|
||||||
|
|
||||||
content = strings.TrimSpace(content)
|
content = trimPrefixStringAndSlice(content, sub.Command, sub.Aliases)
|
||||||
content = strings.TrimPrefix(content, cmd.Command)
|
|
||||||
|
|
||||||
if !sub.IsPlumbed() {
|
if !sub.IsPlumbed() && cmd.Command != "" {
|
||||||
content = strings.TrimSpace(content)
|
content = trimPrefixStringAndSlice(content, cmd.Command, cmd.Aliases)
|
||||||
content = strings.TrimPrefix(content, sub.Command)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method with the raw unparsed command:
|
// Call the method with the raw unparsed command:
|
||||||
|
@ -377,6 +375,22 @@ func searchStringAndSlice(str string, isString string, otherStrings []string) bo
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trimPrefixStringAndSlice behaves similarly to searchStringAndSlice, but it
|
||||||
|
// trims the prefix and the surrounding spaces after a match.
|
||||||
|
func trimPrefixStringAndSlice(str string, prefix string, prefixes []string) string {
|
||||||
|
if strings.HasPrefix(str, prefix) {
|
||||||
|
return strings.TrimSpace(str[len(prefix):])
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, prefix := range prefixes {
|
||||||
|
if strings.HasPrefix(str, prefix) {
|
||||||
|
return strings.TrimSpace(str[len(prefix):])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
func errNoBreak(err error) error {
|
func errNoBreak(err error) error {
|
||||||
if errors.Is(err, Break) {
|
if errors.Is(err, Break) {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue