mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 18:57:59 -05:00
Refactor fuzzy help and clean up help command (#2122)
What's changed: - Fixed issues mentioned on #2031 - Fuzzy help displays more like help manual - Fuzzy help is easier and more flexible to use - Fuzzy help string-matching ratio lowered to 80 - Help formatter is more extendable - Help command has been optimized, cleaned up and better incorporates fuzzy help - Added async_filter and async_enumerate utility functions because I was using them for this PR, then no longer needed them, but decided they might be useful anyway. - Added `Context.me` property which is a shortcut to `Context.guild.me` or `Context.bot.user`, depending on the channel type.
This commit is contained in:
@@ -106,6 +106,36 @@ class Command(commands.Command):
|
||||
# We should expose anything which might be a bug in the converter
|
||||
raise exc
|
||||
|
||||
async def can_see(self, ctx: "Context"):
|
||||
"""Check if this command is visible in the given context.
|
||||
|
||||
In short, this will verify whether the user can run the
|
||||
command, and also whether the command is hidden or not.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ctx : `Context`
|
||||
The invocation context to check with.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
``True`` if this command is visible in the given context.
|
||||
|
||||
"""
|
||||
for cmd in (self, *self.parents):
|
||||
if cmd.hidden:
|
||||
return False
|
||||
try:
|
||||
can_run = await self.can_run(ctx)
|
||||
except commands.CheckFailure:
|
||||
return False
|
||||
else:
|
||||
if can_run is False:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def disable_in(self, guild: discord.Guild) -> bool:
|
||||
"""Disable this command in the given guild.
|
||||
|
||||
|
||||
@@ -237,3 +237,20 @@ class Context(commands.Context):
|
||||
)
|
||||
else:
|
||||
return await self.send(message)
|
||||
|
||||
@property
|
||||
def clean_prefix(self) -> str:
|
||||
"""str: The command prefix, but a mention prefix is displayed nicer."""
|
||||
me = self.me
|
||||
return self.prefix.replace(me.mention, f"@{me.display_name}")
|
||||
|
||||
@property
|
||||
def me(self) -> discord.abc.User:
|
||||
"""discord.abc.User: The bot member or user object.
|
||||
|
||||
If the context is DM, this will be a `discord.User` object.
|
||||
"""
|
||||
if self.guild is not None:
|
||||
return self.guild.me
|
||||
else:
|
||||
return self.bot.user
|
||||
|
||||
Reference in New Issue
Block a user