mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Show command aliases in help with setting to disable (#3040)
* Update help.py
* Create 3040.enhance.rst
* remove towncrier entry
* Make it i18n friendly.
* That was uneeded to change this actually.
* ...
* ..
* .
* Add a setting for aliases.
* DOTS
* Update redbot/core/core_commands.py
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
* Address requested changes maybe
* New format + changes requested.
* okay we'll get there someday
* honk
* aaaaaaaaaaaaaaa
* Black
* Fix missing humanize_timedelta import.
* style
* Two things from my very old pending review, see commit desc
```py
valid_alias_list = [
af
for a in aliases
if (af := f"{a}")
and len(af) < 500
and ((a_counter + len(af)) < 500)
and (a_counter := a_counter + len(af))
]
```
^ This can be simplified:
```suggestion
valid_alias_list = [
alias
for alias in aliases
if (a_counter := a_counter + len(alias)) < 500
]
```
Although I think it would be somewhat clearer to use a `for` loop rather than a list comprehension (+ we can just `break` when there's not gonna be another alias that could fit in the list since it's sorted):
```suggestion
valid_alias_list = []
for alias in aliases:
if (a_counter := a_counter + len(alias)) < 500:
valid_alias_list.append(alias)
else:
break
```
* style *again*
* use qualified name of the parent command
* meh
* another meh
* Revert the last commit...
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
parent
4138410d33
commit
dcf7368e54
@ -110,6 +110,7 @@ class RedBase(
|
||||
help__delete_delay=0,
|
||||
help__use_menus=False,
|
||||
help__show_hidden=False,
|
||||
help__show_aliases=True,
|
||||
help__verify_checks=True,
|
||||
help__verify_exists=False,
|
||||
help__tagline="",
|
||||
|
||||
@ -42,7 +42,7 @@ from ..i18n import Translator
|
||||
from ..utils import menus
|
||||
from ..utils.mod import mass_purge
|
||||
from ..utils._internal_utils import fuzzy_command_search, format_fuzzy_results
|
||||
from ..utils.chat_formatting import box, pagify, humanize_timedelta
|
||||
from ..utils.chat_formatting import box, humanize_list, humanize_number, humanize_timedelta, pagify
|
||||
|
||||
__all__ = ["red_help", "RedHelpFormatter", "HelpSettings", "HelpFormatterABC"]
|
||||
|
||||
@ -72,6 +72,7 @@ class HelpSettings:
|
||||
max_pages_in_guild: int = 2
|
||||
use_menus: bool = False
|
||||
show_hidden: bool = False
|
||||
show_aliases: bool = True
|
||||
verify_checks: bool = True
|
||||
verify_exists: bool = False
|
||||
tagline: str = ""
|
||||
@ -300,10 +301,42 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
|
||||
tagline = (help_settings.tagline) or self.get_default_tagline(ctx)
|
||||
signature = _(
|
||||
"`Syntax: {ctx.clean_prefix}{command.qualified_name} {command.signature}`"
|
||||
"Syntax: {ctx.clean_prefix}{command.qualified_name} {command.signature}"
|
||||
).format(ctx=ctx, command=command)
|
||||
subcommands = None
|
||||
|
||||
aliases = command.aliases
|
||||
if help_settings.show_aliases and aliases:
|
||||
alias_fmt = _("Aliases") if len(command.aliases) > 1 else _("Alias")
|
||||
aliases = sorted(aliases, key=len)
|
||||
|
||||
a_counter = 0
|
||||
valid_alias_list = []
|
||||
for alias in aliases:
|
||||
if (a_counter := a_counter + len(alias)) < 500:
|
||||
valid_alias_list.append(alias)
|
||||
else:
|
||||
break
|
||||
|
||||
a_diff = len(aliases) - len(valid_alias_list)
|
||||
aliases_list = [
|
||||
f"{ctx.clean_prefix}{command.parent.qualified_name + ' ' if command.parent else ''}{alias}"
|
||||
for alias in valid_alias_list
|
||||
]
|
||||
if len(valid_alias_list) < 10:
|
||||
aliases_content = humanize_list(aliases_list)
|
||||
else:
|
||||
aliases_formatted_list = ", ".join(aliases_list)
|
||||
if a_diff > 1:
|
||||
aliases_content = _("{aliases} and {number} more aliases.").format(
|
||||
aliases=aliases_formatted_list, number=humanize_number(a_diff)
|
||||
)
|
||||
else:
|
||||
aliases_content = _("{aliases} and one more alias.").format(
|
||||
aliases=aliases_formatted_list
|
||||
)
|
||||
signature += f"\n{alias_fmt}: {aliases_content}"
|
||||
|
||||
subcommands = None
|
||||
if hasattr(command, "all_commands"):
|
||||
grp = cast(commands.Group, command)
|
||||
subcommands = await self.get_group_help_mapping(ctx, grp, help_settings=help_settings)
|
||||
@ -315,7 +348,7 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
emb["embed"]["title"] = f"*{description[:250]}*"
|
||||
|
||||
emb["footer"]["text"] = tagline
|
||||
emb["embed"]["description"] = signature
|
||||
emb["embed"]["description"] = box(signature)
|
||||
|
||||
command_help = command.format_help_for_context(ctx)
|
||||
if command_help:
|
||||
@ -375,7 +408,7 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
None,
|
||||
(
|
||||
description,
|
||||
signature[1:-1],
|
||||
signature,
|
||||
command.format_help_for_context(ctx),
|
||||
subtext_header,
|
||||
subtext,
|
||||
|
||||
@ -2347,6 +2347,22 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
else:
|
||||
await ctx.send(_("Help will filter hidden commands."))
|
||||
|
||||
@helpset.command(name="showaliases")
|
||||
async def helpset_showaliases(self, ctx: commands.Context, show_aliases: bool = None):
|
||||
"""
|
||||
This allows the help command to show existing commands aliases if there is any.
|
||||
|
||||
This defaults to True.
|
||||
Using this without a setting will toggle.
|
||||
"""
|
||||
if show_aliases is None:
|
||||
show_aliases = not await ctx.bot._config.help.show_aliases()
|
||||
await ctx.bot._config.help.show_aliases.set(show_aliases)
|
||||
if show_aliases:
|
||||
await ctx.send(_("Help will show commands aliases."))
|
||||
else:
|
||||
await ctx.send(_("Help will not show commands aliases."))
|
||||
|
||||
@helpset.command(name="usetick")
|
||||
async def helpset_usetick(self, ctx: commands.Context, use_tick: bool = None):
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user