aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dennis Pham <[email protected]>2020-07-15 19:00:56 -0400
committerGravatar GitHub <[email protected]>2020-07-15 19:00:56 -0400
commit730c05925ba867cd34aa6aefd189df2c3062f433 (patch)
tree23d41ad3823cb0d0e3106f3e46e0b2eba58a37d3
parentMerge pull request #1054 from python-discord/dm_relay (diff)
parentMerge branch 'master' into bug/980/fuzzy-processing (diff)
Merge pull request #1045 from python-discord/bug/980/fuzzy-processing
Invoke fuzzywuzzy's processor before matching
-rw-r--r--bot/cogs/help.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/bot/cogs/help.py b/bot/cogs/help.py
index 70e62d590..3d1d6fd10 100644
--- a/bot/cogs/help.py
+++ b/bot/cogs/help.py
@@ -8,6 +8,7 @@ from typing import List, Union
from discord import Colour, Embed, Member, Message, NotFound, Reaction, User
from discord.ext.commands import Bot, Cog, Command, Context, Group, HelpCommand
from fuzzywuzzy import fuzz, process
+from fuzzywuzzy.utils import full_process
from bot import constants
from bot.constants import Channels, Emojis, STAFF_ROLES
@@ -145,7 +146,13 @@ class CustomHelpCommand(HelpCommand):
Will return an instance of the `HelpQueryNotFound` exception with the error message and possible matches.
"""
choices = await self.get_all_help_choices()
- result = process.extractBests(string, choices, scorer=fuzz.ratio, score_cutoff=60)
+
+ # Run fuzzywuzzy's processor beforehand, and avoid matching if processed string is empty
+ # This avoids fuzzywuzzy from raising a warning on inputs with only non-alphanumeric characters
+ if (processed := full_process(string)):
+ result = process.extractBests(processed, choices, scorer=fuzz.ratio, score_cutoff=60, processor=None)
+ else:
+ result = []
return HelpQueryNotFound(f'Query "{string}" not found.', dict(result))