mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-07 09:52:30 -05:00
Fix duplicate commands in fuzzy help (#2798)
* Fix duplicate commands in fuzzy help Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Use help command's filter for all fuzzy Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
committed by
Michael H
parent
461f56bca1
commit
f3bbfdc64d
@@ -19,14 +19,18 @@ from typing import (
|
||||
Tuple,
|
||||
TypeVar,
|
||||
Union,
|
||||
Set,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
import discord
|
||||
from fuzzywuzzy import fuzz, process
|
||||
from redbot.core import commands
|
||||
|
||||
from .chat_formatting import box
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..commands import Command, Context
|
||||
|
||||
__all__ = [
|
||||
"bounded_gather",
|
||||
"safe_delete",
|
||||
@@ -180,12 +184,12 @@ async def async_enumerate(
|
||||
|
||||
|
||||
async def fuzzy_command_search(
|
||||
ctx: commands.Context,
|
||||
ctx: "Context",
|
||||
term: Optional[str] = None,
|
||||
*,
|
||||
commands: Optional[list] = None,
|
||||
commands: Optional[Set["Command"]] = None,
|
||||
min_score: int = 80,
|
||||
) -> Optional[List[commands.Command]]:
|
||||
) -> Optional[List["Command"]]:
|
||||
"""Search for commands which are similar in name to the one invoked.
|
||||
|
||||
Returns a maximum of 5 commands which must all be at least matched
|
||||
@@ -196,8 +200,11 @@ async def fuzzy_command_search(
|
||||
ctx : `commands.Context <redbot.core.commands.Context>`
|
||||
The command invocation context.
|
||||
term : Optional[str]
|
||||
The name of the invoked command. If ``None``, `Context.invoked_with`
|
||||
will be used instead.
|
||||
The name of the invoked command. If ``None``,
|
||||
`Context.invoked_with` will be used instead.
|
||||
commands : Optional[Set[commands.Command]]
|
||||
The commands available to choose from when doing a fuzzy match.
|
||||
When omitted, `Bot.walk_commands` will be used instead.
|
||||
min_score : int
|
||||
The minimum score for matched commands to reach. Defaults to 80.
|
||||
|
||||
@@ -239,7 +246,7 @@ async def fuzzy_command_search(
|
||||
|
||||
# Do the scoring. `extracted` is a list of tuples in the form `(command, score)`
|
||||
extracted = process.extract(
|
||||
term, (commands or ctx.bot.walk_commands()), limit=5, scorer=fuzz.QRatio
|
||||
term, (commands or set(ctx.bot.walk_commands())), limit=5, scorer=fuzz.QRatio
|
||||
)
|
||||
if not extracted:
|
||||
return
|
||||
@@ -257,10 +264,7 @@ async def fuzzy_command_search(
|
||||
|
||||
|
||||
async def format_fuzzy_results(
|
||||
ctx: commands.Context,
|
||||
matched_commands: List[commands.Command],
|
||||
*,
|
||||
embed: Optional[bool] = None,
|
||||
ctx: "Context", matched_commands: List["Command"], *, embed: Optional[bool] = None
|
||||
) -> Union[str, discord.Embed]:
|
||||
"""Format the result of a fuzzy command search.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user