From 8d62214b0b009d1cc9b343c9589a5a1fe8f4692b Mon Sep 17 00:00:00 2001 From: kosayoda Date: Tue, 14 Jul 2020 12:49:39 +0800 Subject: 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. --- bot/cogs/help.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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)) -- cgit v1.2.3 From eec57c86999bb2e9486dd6443b44cfd29026c823 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Wed, 15 Jul 2020 11:39:17 +0800 Subject: Pass processed string to `extractBests` Fixes a regression where the string to be matched was not processed beforehand. --- bot/cogs/help.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/help.py b/bot/cogs/help.py index 198e88b55..5f3fc4750 100644 --- a/bot/cogs/help.py +++ b/bot/cogs/help.py @@ -150,8 +150,8 @@ class CustomHelpCommand(HelpCommand): # 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) + if (processed := full_process(string)): + result = process.extractBests(processed, choices, scorer=fuzz.ratio, score_cutoff=60, processor=None) else: result = [] -- cgit v1.2.3