[V3 Fuzzy search] fix several issues with this feature (#1788)

* [V3 Fuzzy search] fix several issues with this feature

* Make it check if parent commands are hidden

* Check if compiler available in setup.py

* Let's just compile a dummy C file to check compiler availability

* Add a missing import + remove unneeded code
This commit is contained in:
palmtree5
2018-06-05 12:14:11 -08:00
committed by Kowlin
parent db5d4d5158
commit 0b78664792
7 changed files with 160 additions and 20 deletions

View File

@@ -3,11 +3,19 @@ __all__ = ["safe_delete", "fuzzy_command_search"]
from pathlib import Path
import os
import shutil
import logging
from redbot.core import commands
from fuzzywuzzy import process
from .chat_formatting import box
def fuzzy_filter(record):
return record.funcName != "extractWithoutOrder"
logging.getLogger().addFilter(fuzzy_filter)
def safe_delete(pth: Path):
if pth.exists():
for root, dirs, files in os.walk(str(pth)):
@@ -19,9 +27,49 @@ def safe_delete(pth: Path):
shutil.rmtree(str(pth), ignore_errors=True)
def fuzzy_command_search(ctx: commands.Context, term: str):
async def filter_commands(ctx: commands.Context, extracted: list):
return [
i
for i in extracted
if i[1] >= 90
and not i[0].hidden
and await i[0].can_run(ctx)
and all([await p.can_run(ctx) for p in i[0].parents])
and not any([p.hidden for p in i[0].parents])
]
async def fuzzy_command_search(ctx: commands.Context, term: str):
out = ""
for pos, extracted in enumerate(process.extract(term, ctx.bot.walk_commands(), limit=5), 1):
if ctx.guild is not None:
enabled = await ctx.bot.db.guild(ctx.guild).fuzzy()
else:
enabled = await ctx.bot.db.fuzzy()
if not enabled:
return None
alias_cog = ctx.bot.get_cog("Alias")
if alias_cog is not None:
is_alias, alias = await alias_cog.is_alias(ctx.guild, term)
if is_alias:
return None
customcom_cog = ctx.bot.get_cog("CustomCommands")
if customcom_cog is not None:
cmd_obj = customcom_cog.commandobj
try:
ccinfo = await cmd_obj.get(ctx.message, term)
except:
pass
else:
return None
extracted_cmds = await filter_commands(
ctx, process.extract(term, ctx.bot.walk_commands(), limit=5)
)
if not extracted_cmds:
return None
for pos, extracted in enumerate(extracted_cmds, 1):
out += "{0}. {1.prefix}{2.qualified_name}{3}\n".format(
pos,
ctx,