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

behavior: ctx.getNearestCommand only being able to lookup one Commands instance at the time #16

Closed
carafelix opened this issue May 2, 2024 · 0 comments · Fixed by #20 or #26
Closed

Comments

@carafelix
Copy link
Member

carafelix commented May 2, 2024

Since the plugin allows to organize commands into multiple and diverse Commands instances, would make sense to allow

getNearestCommand: (
        commands: Commands<C>,
        options?: Partial<JaroWinklerOptions>,
    ) => string | null

to search across a Commands array. Internally should be adjusted for that too.
In any case this could be kept as it is since it's possible to do something in the lines of:

bot
.filter(Context.has.filterQuery("::bot_command"))
.use(async (ctx) => {
 let suggestedCommand
 for(const commands of [userCommands, adminCommands]){
   const search = ctx.getNearestCommand(commands)
   if(search){
     suggestedCommand = search 
   }
 }

 if (suggestedCommand) {
   return ctx.reply(
     `Hmm... I don't know that command. Did you mean ${suggestedCommand}?`,
   );
 }
 await ctx.reply("Oops... I don't know that command :/");
});

But this is not ideal since fuzzySearch does not expose its returned value similarityThreshold. That could be exposed and let users do whatever logic they want or managed internally and return the most similar command.
Also prefix of the best match should be exposed too

@carafelix carafelix moved this to Todo in Plugins May 27, 2024
@carafelix carafelix moved this from Todo to In Progress in Plugins May 29, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Canceled in Plugins Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant