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

bug: getNearestCommand main use case being unreachable for custom prefixes #23

Open
carafelix opened this issue Jun 18, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@carafelix
Copy link
Member

carafelix commented Jun 18, 2024

Currently the main use case for getNearestCommand is to work as a 404 for messages containing unknown. commands
Example:

// after all our command registration
bot
   .filter(Context.has.filterQuery('::bot_command'))
   .use(async (ctx) => {
      const suggestedCommand = ctx.getNearestCommand(myCommands)
   })

A command registered with a custom prefix, would never trigger the filter ::bot_command, like +doX

As me and @roziscoding talked, it's needed to overwrite the ctx.entities("bot_command") method for one that hydrates with not only commands entities, but also commands registered with custom prefixes

A ready to use 404 function could also be useful, e.g:

// after all our command registration
bot.use(
   command404(
      'did you mean $COMMAND',
      'msg for not found',
   ).localize('es', 'quisiste decir $COMMAND', 'comando no encontrado'),
)
@roziscoding
Copy link
Contributor

I think we don't really need the commandNotFound middleware. As you said somewhere else (I don't remember where lol) this can be easily achieved with i18n + getNearestCommand and a simple example on the docs would be enough

@carafelix
Copy link
Member Author

a simple example on the docs would be enough

Yeah, I forgot lol.

In any case, we have to come with a 404 implementation that does not depend on Contex.has.filterQuery(::bot_command), maybe implement some static method inside the Commands class, that archives the same thing + commands with custom prefixes. I'll come up with something soon

@roziscoding
Copy link
Contributor

@carafelix we could add a different function, perhaps something like commandEntities, that would call ctx.entities("bot_command") and return that + custom prefixed commands.
It'd probably need to take in the commands tho, or it'd be an instance method to the Commands class.

@carafelix carafelix self-assigned this Jun 24, 2024
@carafelix carafelix added the bug Something isn't working label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants