aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-02-09 13:38:12 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-02-09 13:38:12 +0300
commit66cda4fd2a0b26e2f9e983f1597a15bfb9527143 (patch)
tree772e003ee76f65093f618041d738bd0f23f4c6cb
parentMoves Off Topic Name Translator (diff)
Makes Off Topic Name Search Case Insensitive
Modifies the off topic channel name search to match upper and lower cased letters, as well as punctuation. Signed-off-by: Hassan Abouelela <[email protected]>
-rw-r--r--bot/exts/fun/off_topic_names.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/bot/exts/fun/off_topic_names.py b/bot/exts/fun/off_topic_names.py
index 7fc93b88c..845b8175c 100644
--- a/bot/exts/fun/off_topic_names.py
+++ b/bot/exts/fun/off_topic_names.py
@@ -139,10 +139,20 @@ class OffTopicNames(Cog):
@has_any_role(*MODERATION_ROLES)
async def search_command(self, ctx: Context, *, query: OffTopicName) -> None:
"""Search for an off-topic name."""
- result = await self.bot.api_client.get('bot/off-topic-channel-names')
- in_matches = {name for name in result if query in name}
- close_matches = difflib.get_close_matches(query, result, n=10, cutoff=0.70)
- lines = sorted(f"• {name}" for name in in_matches.union(close_matches))
+ query = OffTopicName.translate_name(query, from_unicode=False).lower()
+
+ # Map normalized names to returned names for search purposes
+ result = {
+ OffTopicName.translate_name(name, from_unicode=False).lower(): name
+ for name in await self.bot.api_client.get('bot/off-topic-channel-names')
+ }
+
+ # Search normalized keys
+ in_matches = {name for name in result.keys() if query in name}
+ close_matches = difflib.get_close_matches(query, result.keys(), n=10, cutoff=0.70)
+
+ # Send Results
+ lines = sorted(f"• {result[name]}" for name in in_matches.union(close_matches))
embed = Embed(
title="Query results",
colour=Colour.blue()