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

Prompt - Choices / options with custom types #206

Open
AntonyGarand opened this issue Mar 18, 2021 · 0 comments
Open

Prompt - Choices / options with custom types #206

AntonyGarand opened this issue Mar 18, 2021 · 0 comments

Comments

@AntonyGarand
Copy link

Hey!
I'm trying to propose choices for typo's to the users with one of my custom argument type, and this doesn't look feasible within Akairo.

The idea

The idea: Providing choices for the user to pick from when a custom argument type value isn't valid
Here are few sample scenarios:

Typo and confirmation

!pokemon pikacho
[bot] Did you mean: pickachu?
yes

With a positive answer (yes), the value pikachu would be sent to the custom argument function and hopefully be accepted.

Options

!definition cot
[bot] Did you mean: cat (1) or cut (2)
1

In this case, as options were presented, the first option cat would be sent.

Solutions

Here is how I think such a feature could be integrated within the framework

Resolver returning metadata

The resolver could return a normalized object instead of only null | value
This way we can transfer metadata between the resolver and the prompt.
Then, using a prompt function, we can access the metadata and provide the choices, or provide a global default.

Resolver options

The previous solution requires each command's prompt to handle the new cases.
Instead, we can do it at the resolver level, by registering a matching prompt function with the resolver itself.

Something like the following:

function pokemonPrompt(message, phrase, data){
    return { options: data.choices, text: "This pokemon was not found! Did you mean:" }
}
this.commandHandler.resolver.addType("pokemon", pokemonResolver, pokemonPrompt);

Alternatives

Here are few ways to perform a similar action I can think of, working with Akairo's existing structure.

Sending a message from the argument resolver

As we have access to the Message object itself from the resolver, we can reply to the message directly
This would send two messages:

  • The choice[s] from the resolver
  • The prompt message

Then, the user would have to manually enter the proper value.

This has few drawbacks:

  • Sending two messages
  • Not having the context of the command

Doing this within an async resolver

This is similar to the previous option, but with a twist.
You can send a message and listen to the reactions or to an event, before returning the proper result.
This means only one message will be sent, but unlike normal prompts you won't receive text answers to the channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant