mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
[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:
parent
29543ed118
commit
068ce24513
@ -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
|
||||
|
||||
@ -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 """
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user