Skip to content

Commit b791695

Browse files
committed
Add close matches support for registry
1 parent c6be686 commit b791695

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cogs/plugins.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import json
1010
from pkg_resources import parse_version
11+
from difflib import get_close_matches
1112
import random
1213

1314
import discord
@@ -289,11 +290,15 @@ def find_index(name):
289290
if plugin_name in self.registry:
290291
index = find_index(plugin_name)
291292
elif plugin_name is not None:
292-
return await ctx.send(embed=discord.Embed(
293+
em = discord.Embed(
293294
color=discord.Color.red(),
294295
description=f'Could not find a plugin with name "{plugin_name}" within the registry.'
295296
)
296-
)
297+
298+
matches = get_close_matches(plugin_name, self.registry.keys())
299+
if matches:
300+
em.add_field(name='Perhaps you meant', value='\n'.join(f'`{m}`' for m in matches))
301+
return await ctx.send(embed=em)
297302

298303
for name, info in registry:
299304
repo = f"https://github.com/{info['repository']}"

0 commit comments

Comments
 (0)