Bot: Allow variadic functions to have empty trailing arguments

This commit is contained in:
diamondburned (Forefront) 2020-05-03 21:22:19 -07:00
parent 6ece6e72ff
commit 4a14c4d059
3 changed files with 9 additions and 5 deletions

View File

@ -277,6 +277,12 @@ func (ctx *Context) callMessageCreate(mc *gateway.MessageCreateEvent) error {
if argdelta := len(arguments) - len(cmd.Arguments); argdelta != 0 {
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 {
// If there aren't enough arguments given.
case argdelta < 0:

View File

@ -20,9 +20,7 @@ func (h *hasPlumb) Normal(_ *gateway.MessageCreateEvent) error {
return nil
}
func (h *hasPlumb) PーPlumber(
_ *gateway.MessageCreateEvent, c Content) error {
func (h *hasPlumb) PーPlumber(_ *gateway.MessageCreateEvent, c RawArguments) error {
h.Plumbed = string(c)
return nil
}

View File

@ -214,9 +214,9 @@ func TestContext(t *testing.T) {
t.Run("call command custom trailing manual parser", func(t *testing.T) {
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)
}
})