Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return a cancel flag if a user cancels a prompt #139

Merged
merged 1 commit into from
Jul 14, 2020
Merged

fix: return a cancel flag if a user cancels a prompt #139

merged 1 commit into from
Jul 14, 2020

Conversation

Norviah
Copy link
Contributor

@Norviah Norviah commented Jul 14, 2020

issue

When executing Argument.runSeparate, provided arguments are pushed into an array, but if a user provides an incorrect argument type and cancels the prompt, a cancel Flag is generated but it's pushed into the array. Since the flag is in an Array, Argument.isShortCircuit returns false and the command executes, even though the user cancelled.

example

If the args array for a command is:

// command aliases: numbers
[
  {
    id: 'amount',
    match: 'separate',
    type: 'number',
    prompt: { start: 'please provide a valid number.', retry: 'please provide a valid number to use.' },
  }
]

and you execute the command with:

!numbers not_a_number1 not_a_number2

As the arguments aren't numbers, the user will be prompted to provide a valid argument for each invalid argument. So they're prompted to provide a number for not_a_number1, and if they cancel, the client will respond with the cancel text, and then respond with the retry text to provide a valid argument for not_a_number2, and if the user enters cancel again, the command executes with the args object as:

{ amount: [ Flag { type: 'cancel' }, Flag { type: 'cancel' } ] }

solution

To fix this, Argument.runSeparate asks the user for a valid argument, and if the user cancels, the method returns the flag, otherwise, the response is pushed into the array.

This allows Argument.isShortCircuit to successfully determine if the given flag is a cancel flag.

@1Computer1
Copy link
Member

Could you see if this fixes #97?

@Norviah
Copy link
Contributor Author

Norviah commented Jul 14, 2020

Could you see if this fixes #97?

Yup, it does.

@1Computer1 1Computer1 merged commit 8f8281d into discord-akairo:master Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants