Skip to content

Commit 068ce24

Browse files
[Core Commands] Add Help settings view (Cog-Creators#4022)
* add help settings view * Update redbot/core/commands/help.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * natural language handling of time intervals is useful Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
1 parent 29543ed commit 068ce24

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

redbot/core/commands/help.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import abc
3131
import asyncio
3232
from collections import namedtuple
33-
from dataclasses import dataclass
33+
from dataclasses import dataclass, asdict as dc_asdict
3434
from typing import Union, List, AsyncIterator, Iterable, cast
3535

3636
import discord
@@ -42,7 +42,7 @@
4242
from ..utils import menus
4343
from ..utils.mod import mass_purge
4444
from ..utils._internal_utils import fuzzy_command_search, format_fuzzy_results
45-
from ..utils.chat_formatting import box, pagify
45+
from ..utils.chat_formatting import box, pagify, humanize_timedelta
4646

4747
__all__ = ["red_help", "RedHelpFormatter", "HelpSettings", "HelpFormatterABC"]
4848

@@ -94,6 +94,42 @@ async def from_context(cls, context: Context):
9494
settings = await context.bot._config.help.all()
9595
return cls(**settings)
9696

97+
@property
98+
def pretty(self):
99+
""" Returns a discord safe representation of the settings """
100+
101+
def bool_transformer(val):
102+
if val is False:
103+
return _("No")
104+
if val is True:
105+
return _("Yes")
106+
return val
107+
108+
data = {k: bool_transformer(v) for k, v in dc_asdict(self).items()}
109+
110+
if not self.delete_delay:
111+
data["delete_delay"] = _("Disabled")
112+
else:
113+
data["delete_delay"] = humanize_timedelta(seconds=self.delete_delay)
114+
115+
if tag := data.pop("tagline", ""):
116+
tagline_info = _("\nCustom Tagline: {tag}").format(tag=tag)
117+
else:
118+
tagline_info = ""
119+
120+
data["tagline_info"] = tagline_info
121+
122+
return _(
123+
"Maximum characters per page: {page_char_limit}"
124+
"\nMaximum pages per guild (only used if menus are not used): {max_pages_in_guild}"
125+
"\nHelp is a menu: {use_menus}"
126+
"\nHelp shows hidden commands: {show_hidden}"
127+
"\nHelp only shows commands which can be used: {verify_checks}"
128+
"\nHelp shows unusable commands when asked directly: {verify_exists}"
129+
"\nDelete delay: {delete_delay}"
130+
"{tagline_info}"
131+
).format_map(data)
132+
97133

98134
class NoCommand(Exception):
99135
pass

redbot/core/core_commands.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,23 @@ async def helpset(self, ctx: commands.Context):
20792079
"""Manage settings for the help command."""
20802080
pass
20812081

2082+
@helpset.command(name="showsettings")
2083+
async def helpset_showsettings(self, ctx: commands.Context):
2084+
""" Show the current help settings """
2085+
2086+
help_settings = await commands.help.HelpSettings.from_context(ctx)
2087+
2088+
if type(ctx.bot._help_formatter) is commands.help.RedHelpFormatter:
2089+
message = help_settings.pretty
2090+
else:
2091+
message = _(
2092+
"Warning: The default formatter is not in use, these settings may not apply"
2093+
)
2094+
message += f"\n\n{help_settings.pretty}"
2095+
2096+
for page in pagify(message):
2097+
await ctx.send(page)
2098+
20822099
@helpset.command(name="resetformatter")
20832100
async def helpset_resetformatter(self, ctx: commands.Context):
20842101
""" This resets [botname]'s help formatter to the default formatter """

0 commit comments

Comments
 (0)