mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-05 19:57:02 +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 {
|
||||
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:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue