aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kosayoda <[email protected]>2020-07-14 12:49:39 +0800
committerGravatar kosayoda <[email protected]>2020-07-14 12:49:39 +0800
commit8d62214b0b009d1cc9b343c9589a5a1fe8f4692b (patch)
tree06e6f0fa5d31f33e73d0a85babe3ddb82f0bedd3
parentWhitelisting some popular communities (diff)
Invoke fuzzywuzzy's processor before matching
Trying to match a string with only non-alphanumeric characters results in a warning by fuzzywuzzy. Processing the string before matching lets us avoid the warning, which which uses the root logger and thus isn't supressible.
-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 832f6ea6b..198e88b55 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
@@ -146,7 +147,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 full_process(string):
+ result = process.extractBests(string, choices, scorer=fuzz.ratio, score_cutoff=60, processor=None)
+ else:
+ result = []
return HelpQueryNotFound(f'Query "{string}" not found.', dict(result))