mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
More privatization, and some error helpers (#2976)
* More privatization, and some error helpers This makes a lot more things private. Continued from #2967, fixes #2984 Adds public methods for various things. Below is a brief summary of things available elsewhere, though this particular set of changes may warrant a detailed section in the release notes. - bot.db.locale -> redbot.core.i18n.get_locale - Note: This one already existed. - bot.db.help -> redbot.core.commands.help.HelpSettings - bot db whitelist/blaclist? -> bot.allowed_by_whitelist_blacklist - This has also been made a single cannonical function for this purpose including check usage - bot color? -> bot.get_embed_color/bot.get_embed_colour - bot.id.api_tokens? -> - bot.get_shared_api_tokens - bot.set_shared_api_tokens - bot.remove_shared_api_tokens -bot.db.prefix -> bot.get_valid_prefixes - (Note: This is a wrapper around bot.get_prefix) Other changes include - removing `bot.counter` as it was never used anywhere - Adding properties with helpful error messages for moved and renamed things - making bot.uptime a property with an error on set - adding a migration to the bot config for shared_api_tokens * Remove overly encompassing message redaction, eval is a risk, dont run in dev if you cant manage it * address Flame's feedback * rephrase example * changelog extras * You saw nothing
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
# Warning: The implementation below touches several private attributes.
|
||||
# While this implementation will be updated, and public interfaces maintained, derived classes
|
||||
# should not assume these private attributes are version safe, and use the provided HelpSettings
|
||||
# class for these settings.
|
||||
|
||||
# This is a full replacement of discord.py's help command
|
||||
#
|
||||
# At a later date, there should be things added to support extra formatter
|
||||
@@ -29,6 +34,7 @@
|
||||
|
||||
import asyncio
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
from typing import Union, List, AsyncIterator, Iterable, cast
|
||||
|
||||
import discord
|
||||
@@ -40,7 +46,7 @@ from ..i18n import Translator
|
||||
from ..utils import menus, fuzzy_command_search, format_fuzzy_results
|
||||
from ..utils.chat_formatting import box, pagify
|
||||
|
||||
__all__ = ["red_help", "RedHelpFormatter"]
|
||||
__all__ = ["red_help", "RedHelpFormatter", "HelpSettings"]
|
||||
|
||||
T_ = Translator("Help", __file__)
|
||||
|
||||
@@ -53,6 +59,36 @@ EmbedField = namedtuple("EmbedField", "name value inline")
|
||||
EMPTY_STRING = "\N{ZERO WIDTH SPACE}"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class HelpSettings:
|
||||
"""
|
||||
A representation of help settings.
|
||||
"""
|
||||
|
||||
page_char_limit: int = 1000
|
||||
max_pages_in_guild: int = 2
|
||||
use_menus: bool = False
|
||||
show_hidden: bool = False
|
||||
verify_checks: bool = True
|
||||
verify_exists: bool = False
|
||||
tagline: str = ""
|
||||
|
||||
# Contrib Note: This is intentional to not accept the bot object
|
||||
# There are plans to allow guild and user specific help settings
|
||||
# Adding a non-context based method now would involve a breaking change later.
|
||||
# At a later date, more methods should be exposed for non-context based creation.
|
||||
#
|
||||
# This is also why we aren't just caching the
|
||||
# current state of these settings on the bot object.
|
||||
@classmethod
|
||||
async def from_context(cls, context: Context):
|
||||
"""
|
||||
Get the HelpSettings for the current context
|
||||
"""
|
||||
settings = await context.bot._config.help.all()
|
||||
return cls(**settings)
|
||||
|
||||
|
||||
class NoCommand(Exception):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user