[Core Commands] Add Help settings view (#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>
This commit is contained in:
Michael H 2020-08-05 21:38:34 -04:00 committed by GitHub
parent 29543ed118
commit 068ce24513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 2 deletions

View File

@ -30,7 +30,7 @@
import abc
import asyncio
from collections import namedtuple
from dataclasses import dataclass
from dataclasses import dataclass, asdict as dc_asdict
from typing import Union, List, AsyncIterator, Iterable, cast
import discord
@ -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
from ..utils.chat_formatting import box, pagify, humanize_timedelta
__all__ = ["red_help", "RedHelpFormatter", "HelpSettings", "HelpFormatterABC"]
@ -94,6 +94,42 @@ class HelpSettings:
settings = await context.bot._config.help.all()
return cls(**settings)
@property
def pretty(self):
""" Returns a discord safe representation of the settings """
def bool_transformer(val):
if val is False:
return _("No")
if val is True:
return _("Yes")
return val
data = {k: bool_transformer(v) for k, v in dc_asdict(self).items()}
if not self.delete_delay:
data["delete_delay"] = _("Disabled")
else:
data["delete_delay"] = humanize_timedelta(seconds=self.delete_delay)
if tag := data.pop("tagline", ""):
tagline_info = _("\nCustom Tagline: {tag}").format(tag=tag)
else:
tagline_info = ""
data["tagline_info"] = tagline_info
return _(
"Maximum characters per page: {page_char_limit}"
"\nMaximum pages per guild (only used if menus are not used): {max_pages_in_guild}"
"\nHelp is a menu: {use_menus}"
"\nHelp shows hidden commands: {show_hidden}"
"\nHelp only shows commands which can be used: {verify_checks}"
"\nHelp shows unusable commands when asked directly: {verify_exists}"
"\nDelete delay: {delete_delay}"
"{tagline_info}"
).format_map(data)
class NoCommand(Exception):
pass

View File

@ -2079,6 +2079,23 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
"""Manage settings for the help command."""
pass
@helpset.command(name="showsettings")
async def helpset_showsettings(self, ctx: commands.Context):
""" Show the current help settings """
help_settings = await commands.help.HelpSettings.from_context(ctx)
if type(ctx.bot._help_formatter) is commands.help.RedHelpFormatter:
message = help_settings.pretty
else:
message = _(
"Warning: The default formatter is not in use, these settings may not apply"
)
message += f"\n\n{help_settings.pretty}"
for page in pagify(message):
await ctx.send(page)
@helpset.command(name="resetformatter")
async def helpset_resetformatter(self, ctx: commands.Context):
""" This resets [botname]'s help formatter to the default formatter """