diff options
| author | 2020-02-18 17:33:07 +0200 | |
|---|---|---|
| committer | 2020-02-18 17:33:07 +0200 | |
| commit | b3ad47a507ef03fdf3a1dffb56d92d6d4f627c87 (patch) | |
| tree | f95308f4cc3a9ec33ec9147afc4beffbb0f45bc3 | |
| parent | Merge pull request #752 from python-discord/infr-edit-permanent-fix (diff) | |
Feature: suggest command usage for misspelt commands
| -rw-r--r-- | bot/cogs/tags.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py index 54a51921c..5f7c810b8 100644 --- a/bot/cogs/tags.py +++ b/bot/cogs/tags.py @@ -12,6 +12,8 @@ from bot.converters import TagContentConverter, TagNameConverter from bot.decorators import with_role from bot.pagination import LinePaginator +from fuzzywuzzy import process + log = logging.getLogger(__name__) TEST_CHANNELS = ( @@ -138,6 +140,23 @@ class Tags(Cog): title='Did you mean ...', description='\n'.join(tag['title'] for tag in founds[:10]) )) + else: + # No similar tag found, searching for a similar command + command_name = ctx.invoked_with + raw_commands = [cmd.name for cmd in self.bot.walk_commands()] + similar_command_data = process.extractOne(command_name, raw_commands) + # The match is not very similar, no need to suggest it + log.debug(similar_command_data) + if similar_command_data[1] < 65: + log.debug("No similar commands found") + return + similar_command = self.bot.get_command(similar_command_data[0]) + if similar_command.can_run(ctx): + misspelled_content = ctx.message.content + await ctx.send( + f"Did you mean:\n**{misspelled_content.replace(command_name, similar_command.name)}**" + ) + return else: tags = self._cache.values() |