switchblade icon indicating copy to clipboard operation
switchblade copied to clipboard

"Did you mean?" option for command typos

Open pedrofracassi opened this issue 6 years ago • 5 comments

Let's say someone types s!showertoughts. Currently, as it's not a valid command, the bot wouldn't do anything, and the user might get confused.

A good solution to that is allowing server owners to turn on a "did you mean" feature, that could use https://fusejs.io/ to find the closest match to what the user just typed and send a message like this on the channel:

Did you mean s!showerthoughts?

pedrofracassi avatar Oct 19 '19 17:10 pedrofracassi

ps: this should be guild-configurable. iirc, Discord Bot List and some servers like those don't like that much when that happens

dsgpaiva avatar Oct 22 '19 20:10 dsgpaiva

A good solution to that is allowing server owners to turn on a "did you mean" feature

Opt-in, yeah

pedrofracassi avatar Oct 22 '19 23:10 pedrofracassi

const commandList = ['showerthoughts', 'furry', 'e621', 'play', 'queue']

const Fuse = require('fuse.js')
const fuse = new Fuse(commandList, { shouldSort: true, threshold: 0.6, location: 0, distance: 100, maxPatternLength: 32, minMatchCharLength: 1 })
const result = fuse.search("queeu")

// It should return "[ 4 ]", meaning that result[0] is going to return the position in which the command is more reliable to be what the user wanted to pick. The usage for that is commandList[`${result[0]}`], or something more clean.

dsgpaiva avatar Oct 31 '19 15:10 dsgpaiva

Yup, that looks good

pedrofracassi avatar Oct 31 '19 15:10 pedrofracassi

I've used Fuse for the LoR commands btw, give them a look

pedrofracassi avatar Oct 31 '19 15:10 pedrofracassi

Not possible due the new discord bot system

Doges avatar Sep 15 '22 19:09 Doges