mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-07 12:38:05 +00:00
Bot: Allow variadic functions to have empty trailing arguments
This commit is contained in:
parent
6ece6e72ff
commit
4a14c4d059
|
@ -277,6 +277,12 @@ func (ctx *Context) callMessageCreate(mc *gateway.MessageCreateEvent) error {
|
||||||
if argdelta := len(arguments) - len(cmd.Arguments); argdelta != 0 {
|
if argdelta := len(arguments) - len(cmd.Arguments); argdelta != 0 {
|
||||||
var err error // no err if nil
|
var err error // no err if nil
|
||||||
|
|
||||||
|
// If the function is variadic, then we can allow the last argument to
|
||||||
|
// be empty.
|
||||||
|
if cmd.Variadic {
|
||||||
|
argdelta++
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
// If there aren't enough arguments given.
|
// If there aren't enough arguments given.
|
||||||
case argdelta < 0:
|
case argdelta < 0:
|
||||||
|
|
|
@ -20,9 +20,7 @@ func (h *hasPlumb) Normal(_ *gateway.MessageCreateEvent) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hasPlumb) PーPlumber(
|
func (h *hasPlumb) PーPlumber(_ *gateway.MessageCreateEvent, c RawArguments) error {
|
||||||
_ *gateway.MessageCreateEvent, c Content) error {
|
|
||||||
|
|
||||||
h.Plumbed = string(c)
|
h.Plumbed = string(c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,9 +214,9 @@ func TestContext(t *testing.T) {
|
||||||
|
|
||||||
t.Run("call command custom trailing manual parser", func(t *testing.T) {
|
t.Run("call command custom trailing manual parser", func(t *testing.T) {
|
||||||
ctx.HasPrefix = NewPrefix("!")
|
ctx.HasPrefix = NewPrefix("!")
|
||||||
expects := []string{"arikawa"}
|
expects := []string{}
|
||||||
|
|
||||||
if err := testReturn(expects, "!trailCustom hime arikawa"); err != nil {
|
if err := testReturn(expects, "!trailCustom hime_arikawa"); err != nil {
|
||||||
t.Fatal("Unexpected call error:", err)
|
t.Fatal("Unexpected call error:", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue