discord.py 2.0 update (3d914e08->2.0.1) (#5709)

This commit is contained in:
Jakub Kuczys
2022-10-03 16:07:15 +02:00
committed by GitHub
parent d7d6ab46f4
commit f02528378f
44 changed files with 454 additions and 317 deletions

View File

@@ -45,7 +45,6 @@ from .help import (
)
from .requires import (
CheckPredicate as CheckPredicate,
DM_PERMS as DM_PERMS,
GlobalPermissionModel as GlobalPermissionModel,
GuildPermissionModel as GuildPermissionModel,
PermissionModel as PermissionModel,
@@ -189,4 +188,14 @@ from discord.ext.commands import (
bot_has_any_role as bot_has_any_role,
before_invoke as before_invoke,
after_invoke as after_invoke,
CurrentChannel as CurrentChannel,
Author as Author,
param as param,
MissingRequiredAttachment as MissingRequiredAttachment,
Parameter as Parameter,
ForumChannelConverter as ForumChannelConverter,
CurrentGuild as CurrentGuild,
Range as Range,
RangeError as RangeError,
parameter as parameter,
)

View File

@@ -339,7 +339,7 @@ if TYPE_CHECKING or os.getenv("BUILDING_DOCS", False):
...
@property
def channel(self) -> Union[discord.TextChannel, discord.Thread]:
def channel(self) -> Union[discord.TextChannel, discord.VoiceChannel, discord.Thread]:
...
@property

View File

@@ -842,12 +842,12 @@ class RedHelpFormatter(HelpFormatterABC):
if (
not use_DMs # we're not in DMs
and delete_delay > 0 # delete delay is enabled
and ctx.channel.permissions_for(ctx.me).manage_messages # we can manage messages
and ctx.bot_permissions.manage_messages # we can manage messages
):
# We need to wrap this in a task to not block after-sending-help interactions.
# The channel has to be TextChannel or Thread as we can't bulk-delete from DMs
async def _delete_delay_help(
channel: Union[discord.TextChannel, discord.Thread],
channel: Union[discord.TextChannel, discord.VoiceChannel, discord.Thread],
messages: List[discord.Message],
delay: int,
):

View File

@@ -40,7 +40,6 @@ if TYPE_CHECKING:
__all__ = [
"CheckPredicate",
"DM_PERMS",
"GlobalPermissionModel",
"GuildPermissionModel",
"PermissionModel",
@@ -75,6 +74,7 @@ GlobalPermissionModel = Union[
discord.User,
discord.VoiceChannel,
discord.TextChannel,
discord.ForumChannel,
discord.CategoryChannel,
discord.Role,
discord.Guild,
@@ -83,6 +83,7 @@ GuildPermissionModel = Union[
discord.Member,
discord.VoiceChannel,
discord.TextChannel,
discord.ForumChannel,
discord.CategoryChannel,
discord.Role,
discord.Guild,
@@ -90,22 +91,6 @@ GuildPermissionModel = Union[
PermissionModel = Union[GlobalPermissionModel, GuildPermissionModel]
CheckPredicate = Callable[["Context"], Union[Optional[bool], Awaitable[Optional[bool]]]]
# Here we are trying to model DM permissions as closely as possible. The only
# discrepancy I've found is that users can pin messages, but they cannot delete them.
# This means manage_messages is only half True, so it's left as False.
# This is also the same as the permissions returned when `permissions_for` is used in DM.
DM_PERMS = discord.Permissions.none()
DM_PERMS.update(
add_reactions=True,
attach_files=True,
embed_links=True,
external_emojis=True,
mention_everyone=True,
read_message_history=True,
read_messages=True,
send_messages=True,
)
class PrivilegeLevel(enum.IntEnum):
"""Enumeration for special privileges."""
@@ -520,15 +505,11 @@ class Requires:
return await self._transition_state(ctx)
async def _verify_bot(self, ctx: "Context") -> None:
if ctx.guild is None:
bot_user = ctx.bot.user
else:
bot_user = ctx.guild.me
cog = ctx.cog
if cog and await ctx.bot.cog_disabled_in_guild(cog, ctx.guild):
raise discord.ext.commands.DisabledCommand()
cog = ctx.cog
if ctx.guild is not None and cog and await ctx.bot.cog_disabled_in_guild(cog, ctx.guild):
raise discord.ext.commands.DisabledCommand()
bot_perms = ctx.channel.permissions_for(bot_user)
bot_perms = ctx.bot_permissions
if not (bot_perms.administrator or bot_perms >= self.bot_perms):
raise BotMissingPermissions(missing=self._missing_perms(self.bot_perms, bot_perms))
@@ -574,7 +555,7 @@ class Requires:
return False
if self.user_perms is not None:
user_perms = ctx.channel.permissions_for(ctx.author)
user_perms = ctx.permissions
if user_perms.administrator or user_perms >= self.user_perms:
return True
@@ -633,17 +614,6 @@ class Requires:
return True
return await discord.utils.async_all(check(ctx) for check in self.checks)
@staticmethod
def _get_perms_for(ctx: "Context", user: discord.abc.User) -> discord.Permissions:
if ctx.guild is None:
return DM_PERMS
else:
return ctx.channel.permissions_for(user)
@classmethod
def _get_bot_perms(cls, ctx: "Context") -> discord.Permissions:
return cls._get_perms_for(ctx, ctx.guild.me if ctx.guild else ctx.bot.user)
@staticmethod
def _missing_perms(
required: discord.Permissions, actual: discord.Permissions
@@ -656,13 +626,6 @@ class Requires:
relative_complement = required.value & ~actual.value
return discord.Permissions(relative_complement)
@staticmethod
def _member_as_user(member: discord.abc.User) -> discord.User:
if isinstance(member, discord.Member):
# noinspection PyProtectedMember
return member._user
return member
def __repr__(self) -> str:
return (
f"<Requires privilege_level={self.privilege_level!r} user_perms={self.user_perms!r} "