Bump discord.py to 1.7.0 (#4928)

* Bump discord.py, but to the git version for now

* Import GuildConverter from d.py and deprecate our implementation

* Import PartialMessageConverter in our commands extension

* Use newly added `Cog.has_error_handler()` rather than private method

* Update snowflake regex to use 20 as max length

See Rapptz/discord.py#6501

* Use new supported way for custom cooldown buckets

* Include group args in command signature

* Update code to use `Client.close()` over `Client.logout()`

* Add StageChannelConverter and StoreChannelConverter

* Fix AttributeError in licenseinfo
This commit is contained in:
jack1142
2021-04-05 21:33:19 +02:00
committed by GitHub
parent 9008410fa4
commit adda30cbee
13 changed files with 69 additions and 56 deletions

View File

@@ -21,7 +21,6 @@ from .commands import (
from .context import Context as Context, GuildContext as GuildContext, DMContext as DMContext
from .converter import (
DictConverter as DictConverter,
GuildConverter as GuildConverter,
TimedeltaConverter as TimedeltaConverter,
get_dict_converter as get_dict_converter,
get_timedelta_converter as get_timedelta_converter,
@@ -84,6 +83,7 @@ from ._dpy_reimplements import (
from discord.ext.commands import (
BadArgument as BadArgument,
EmojiConverter as EmojiConverter,
GuildConverter as GuildConverter,
InvalidEndOfQuotedStringError as InvalidEndOfQuotedStringError,
MemberConverter as MemberConverter,
BotMissingRole as BotMissingRole,
@@ -103,6 +103,7 @@ from discord.ext.commands import (
ExtensionError as ExtensionError,
Cooldown as Cooldown,
CheckFailure as CheckFailure,
PartialMessageConverter as PartialMessageConverter,
MessageConverter as MessageConverter,
MissingPermissions as MissingPermissions,
BadUnionArgument as BadUnionArgument,
@@ -130,6 +131,8 @@ from discord.ext.commands import (
ColourConverter as ColourConverter,
ColorConverter as ColorConverter,
VoiceChannelConverter as VoiceChannelConverter,
StageChannelConverter as StageChannelConverter,
StoreChannelConverter as StoreChannelConverter,
NSFWChannelRequired as NSFWChannelRequired,
IDConverter as IDConverter,
MissingRequiredArgument as MissingRequiredArgument,
@@ -147,6 +150,7 @@ from discord.ext.commands import (
MaxConcurrencyReached as MaxConcurrencyReached,
bot_has_guild_permissions as bot_has_guild_permissions,
CommandRegistrationError as CommandRegistrationError,
GuildNotFound as GuildNotFound,
MessageNotFound as MessageNotFound,
MemberNotFound as MemberNotFound,
UserNotFound as UserNotFound,

View File

@@ -35,7 +35,6 @@ if TYPE_CHECKING:
__all__ = [
"DictConverter",
"GuildConverter",
"UserInputOptional",
"NoParseOptional",
"TimedeltaConverter",
@@ -47,7 +46,7 @@ __all__ = [
_ = Translator("commands.converter", __file__)
ID_REGEX = re.compile(r"([0-9]{15,21})")
ID_REGEX = re.compile(r"([0-9]{15,20})")
# Taken with permission from
@@ -134,29 +133,46 @@ def parse_timedelta(
return None
class GuildConverter(discord.Guild):
class _GuildConverter(discord.Guild):
"""Converts to a `discord.Guild` object.
The lookup strategy is as follows (in order):
1. Lookup by ID.
2. Lookup by name.
.. deprecated-removed:: 3.4.8 60
``GuildConverter`` is now only provided within ``redbot.core.commands`` namespace.
"""
@classmethod
async def convert(cls, ctx: "Context", argument: str) -> discord.Guild:
match = ID_REGEX.fullmatch(argument)
return await dpy_commands.GuildConverter().convert(ctx, argument)
if match is None:
ret = discord.utils.get(ctx.bot.guilds, name=argument)
else:
guild_id = int(match.group(1))
ret = ctx.bot.get_guild(guild_id)
if ret is None:
raise BadArgument(_('Server "{name}" not found.').format(name=argument))
_GuildConverter.__name__ = "GuildConverter"
return ret
def __getattr__(name: str, *, stacklevel: int = 2) -> Any:
# Let me just say it one more time... This is awesome! (PEP-562)
if name == "GuildConverter":
# let's not waste time on importing this when we don't need it
# (and let's not put in the public API)
from redbot.core.utils._internal_utils import deprecated_removed
deprecated_removed(
"`GuildConverter` from `redbot.core.commands.converter` namespace",
"3.4.8",
60,
"Use `GuildConverter` from `redbot.core.commands` namespace instead.",
stacklevel=2,
)
return globals()["_GuildConverter"]
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
def __dir__() -> List[str]:
return [*globals().keys(), "GuildConverter"]
# Below this line are a lot of lies for mypy about things that *end up* correct when

View File

@@ -275,6 +275,20 @@ class RedHelpFormatter(HelpFormatterABC):
"You can also type {ctx.clean_prefix}help <category> for more info on a category."
).format(ctx=ctx)
@staticmethod
def get_command_signature(ctx: Context, command: commands.Command) -> str:
parent = command.parent
entries = []
while parent is not None:
if not parent.signature or parent.invoke_without_command:
entries.append(parent.name)
else:
entries.append(parent.name + " " + parent.signature)
parent = parent.parent
parent_sig = (" ".join(reversed(entries)) + " ") if entries else ""
return f"{ctx.clean_prefix}{parent_sig}{command.name} {command.signature}"
async def format_command_help(
self, ctx: Context, obj: commands.Command, help_settings: HelpSettings
):
@@ -300,9 +314,9 @@ class RedHelpFormatter(HelpFormatterABC):
description = command.description or ""
tagline = (help_settings.tagline) or self.get_default_tagline(ctx)
signature = _(
"Syntax: {ctx.clean_prefix}{command.qualified_name} {command.signature}"
).format(ctx=ctx, command=command)
signature = _("Syntax: {command_signature}").format(
command_signature=self.get_command_signature(ctx, command)
)
aliases = command.aliases
if help_settings.show_aliases and aliases:

View File

@@ -28,7 +28,6 @@ from typing import (
import discord
from discord.ext.commands import check
from .converter import GuildConverter
from .errors import BotMissingPermissions
if TYPE_CHECKING:
@@ -70,7 +69,7 @@ GlobalPermissionModel = Union[
discord.TextChannel,
discord.CategoryChannel,
discord.Role,
GuildConverter, # Unfortunately this will have to do for now
discord.Guild,
]
GuildPermissionModel = Union[
discord.Member,
@@ -78,7 +77,7 @@ GuildPermissionModel = Union[
discord.TextChannel,
discord.CategoryChannel,
discord.Role,
GuildConverter,
discord.Guild,
]
PermissionModel = Union[GlobalPermissionModel, GuildPermissionModel]
CheckPredicate = Callable[["Context"], Union[Optional[bool], Awaitable[Optional[bool]]]]