+
Skip to content

Prompt - Choices / options with custom types #206

@AntonyGarand

Description

@AntonyGarand

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载