mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +00:00
Change abc.GuildChannel.overwrites to have Object keys if cache failed
Ultimately despite it not being the prettiest, Object keys ended up being the sanest solution to this without destroying ergonomics.
This commit is contained in:
@ -471,6 +471,8 @@ class GuildChannel:
|
|||||||
|
|
||||||
if isinstance(target, Role):
|
if isinstance(target, Role):
|
||||||
payload['type'] = _Overwrites.ROLE
|
payload['type'] = _Overwrites.ROLE
|
||||||
|
elif isinstance(target, Object):
|
||||||
|
payload['type'] = _Overwrites.ROLE if target.type is Role else _Overwrites.MEMBER
|
||||||
else:
|
else:
|
||||||
payload['type'] = _Overwrites.MEMBER
|
payload['type'] = _Overwrites.MEMBER
|
||||||
|
|
||||||
@ -548,14 +550,13 @@ class GuildChannel:
|
|||||||
""":class:`datetime.datetime`: Returns the channel's creation time in UTC."""
|
""":class:`datetime.datetime`: Returns the channel's creation time in UTC."""
|
||||||
return utils.snowflake_time(self.id)
|
return utils.snowflake_time(self.id)
|
||||||
|
|
||||||
def overwrites_for(self, obj: Union[Role, User]) -> PermissionOverwrite:
|
def overwrites_for(self, obj: Union[Role, User, Object]) -> PermissionOverwrite:
|
||||||
"""Returns the channel-specific overwrites for a member or a role.
|
"""Returns the channel-specific overwrites for a member or a role.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
-----------
|
-----------
|
||||||
obj: Union[:class:`~discord.Role`, :class:`~discord.abc.User`]
|
obj: Union[:class:`~discord.Role`, :class:`~discord.abc.User`, :class:`~discord.Object`]
|
||||||
The role or user denoting
|
The role or user denoting whose overwrite to get.
|
||||||
whose overwrite to get.
|
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
---------
|
---------
|
||||||
@ -579,16 +580,19 @@ class GuildChannel:
|
|||||||
return PermissionOverwrite()
|
return PermissionOverwrite()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def overwrites(self) -> Dict[Union[Role, Member], PermissionOverwrite]:
|
def overwrites(self) -> Dict[Union[Role, Member, Object], PermissionOverwrite]:
|
||||||
"""Returns all of the channel's overwrites.
|
"""Returns all of the channel's overwrites.
|
||||||
|
|
||||||
This is returned as a dictionary where the key contains the target which
|
This is returned as a dictionary where the key contains the target which
|
||||||
can be either a :class:`~discord.Role` or a :class:`~discord.Member` and the value is the
|
can be either a :class:`~discord.Role` or a :class:`~discord.Member` and the value is the
|
||||||
overwrite as a :class:`~discord.PermissionOverwrite`.
|
overwrite as a :class:`~discord.PermissionOverwrite`.
|
||||||
|
|
||||||
|
.. versionchanged:: 2.0
|
||||||
|
Overwrites can now be type-aware :class:`~discord.Object` in case of cache lookup failure
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
--------
|
--------
|
||||||
Dict[Union[:class:`~discord.Role`, :class:`~discord.Member`], :class:`~discord.PermissionOverwrite`]
|
Dict[Union[:class:`~discord.Role`, :class:`~discord.Member`, :class:`~discord.Object`], :class:`~discord.PermissionOverwrite`]
|
||||||
The channel's permission overwrites.
|
The channel's permission overwrites.
|
||||||
"""
|
"""
|
||||||
ret = {}
|
ret = {}
|
||||||
@ -603,13 +607,11 @@ class GuildChannel:
|
|||||||
elif ow.is_member():
|
elif ow.is_member():
|
||||||
target = self.guild.get_member(ow.id)
|
target = self.guild.get_member(ow.id)
|
||||||
|
|
||||||
# TODO: There is potential data loss here in the non-chunked
|
if target is None:
|
||||||
# case, i.e. target is None because get_member returned nothing.
|
target_type = Role if ow.is_role() else User
|
||||||
# This can be fixed with a slight breaking change to the return type,
|
target = Object(id=ow.id, type=target_type) # type: ignore
|
||||||
# i.e. adding discord.Object to the list of it
|
|
||||||
# However, for now this is an acceptable compromise.
|
ret[target] = overwrite
|
||||||
if target is not None:
|
|
||||||
ret[target] = overwrite
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -38,6 +38,7 @@ from typing import (
|
|||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Sequence,
|
Sequence,
|
||||||
Tuple,
|
Tuple,
|
||||||
|
TypeVar,
|
||||||
Union,
|
Union,
|
||||||
overload,
|
overload,
|
||||||
)
|
)
|
||||||
@ -72,6 +73,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
from .types.threads import ThreadArchiveDuration
|
from .types.threads import ThreadArchiveDuration
|
||||||
from .role import Role
|
from .role import Role
|
||||||
|
from .object import Object
|
||||||
from .member import Member, VoiceState
|
from .member import Member, VoiceState
|
||||||
from .abc import Snowflake, SnowflakeTime
|
from .abc import Snowflake, SnowflakeTime
|
||||||
from .embeds import Embed
|
from .embeds import Embed
|
||||||
@ -96,6 +98,8 @@ if TYPE_CHECKING:
|
|||||||
)
|
)
|
||||||
from .types.snowflake import SnowflakeList
|
from .types.snowflake import SnowflakeList
|
||||||
|
|
||||||
|
OverwriteKeyT = TypeVar('OverwriteKeyT', Role, BaseUser, Object, Union[Role, Member, Object])
|
||||||
|
|
||||||
|
|
||||||
class ThreadWithMessage(NamedTuple):
|
class ThreadWithMessage(NamedTuple):
|
||||||
thread: Thread
|
thread: Thread
|
||||||
@ -293,7 +297,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
slowmode_delay: int = ...,
|
slowmode_delay: int = ...,
|
||||||
default_auto_archive_duration: ThreadArchiveDuration = ...,
|
default_auto_archive_duration: ThreadArchiveDuration = ...,
|
||||||
type: ChannelType = ...,
|
type: ChannelType = ...,
|
||||||
overwrites: Mapping[Union[Role, Member, Snowflake], PermissionOverwrite] = ...,
|
overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ...,
|
||||||
) -> TextChannel:
|
) -> TextChannel:
|
||||||
...
|
...
|
||||||
|
|
||||||
@ -1329,7 +1333,7 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
|
|||||||
position: int = ...,
|
position: int = ...,
|
||||||
sync_permissions: int = ...,
|
sync_permissions: int = ...,
|
||||||
category: Optional[CategoryChannel] = ...,
|
category: Optional[CategoryChannel] = ...,
|
||||||
overwrites: Mapping[Union[Role, Member], PermissionOverwrite] = ...,
|
overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ...,
|
||||||
rtc_region: Optional[str] = ...,
|
rtc_region: Optional[str] = ...,
|
||||||
video_quality_mode: VideoQualityMode = ...,
|
video_quality_mode: VideoQualityMode = ...,
|
||||||
reason: Optional[str] = ...,
|
reason: Optional[str] = ...,
|
||||||
@ -1629,7 +1633,7 @@ class StageChannel(VocalGuildChannel):
|
|||||||
position: int = ...,
|
position: int = ...,
|
||||||
sync_permissions: int = ...,
|
sync_permissions: int = ...,
|
||||||
category: Optional[CategoryChannel] = ...,
|
category: Optional[CategoryChannel] = ...,
|
||||||
overwrites: Mapping[Union[Role, Member], PermissionOverwrite] = ...,
|
overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ...,
|
||||||
rtc_region: Optional[str] = ...,
|
rtc_region: Optional[str] = ...,
|
||||||
video_quality_mode: VideoQualityMode = ...,
|
video_quality_mode: VideoQualityMode = ...,
|
||||||
reason: Optional[str] = ...,
|
reason: Optional[str] = ...,
|
||||||
@ -1802,7 +1806,7 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
name: str = ...,
|
name: str = ...,
|
||||||
position: int = ...,
|
position: int = ...,
|
||||||
nsfw: bool = ...,
|
nsfw: bool = ...,
|
||||||
overwrites: Mapping[Union[Role, Member], PermissionOverwrite] = ...,
|
overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ...,
|
||||||
reason: Optional[str] = ...,
|
reason: Optional[str] = ...,
|
||||||
) -> CategoryChannel:
|
) -> CategoryChannel:
|
||||||
...
|
...
|
||||||
@ -2114,7 +2118,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
slowmode_delay: int = ...,
|
slowmode_delay: int = ...,
|
||||||
default_auto_archive_duration: ThreadArchiveDuration = ...,
|
default_auto_archive_duration: ThreadArchiveDuration = ...,
|
||||||
type: ChannelType = ...,
|
type: ChannelType = ...,
|
||||||
overwrites: Mapping[Union[Role, Member, Snowflake], PermissionOverwrite] = ...,
|
overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ...,
|
||||||
) -> ForumChannel:
|
) -> ForumChannel:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -1119,6 +1119,7 @@ The following changes have been made:
|
|||||||
- :attr:`AuditLogEntry.target` may now be a :class:`PartialMessageable`.
|
- :attr:`AuditLogEntry.target` may now be a :class:`PartialMessageable`.
|
||||||
- :attr:`PartialMessage.channel` may now be a :class:`PartialMessageable`.
|
- :attr:`PartialMessage.channel` may now be a :class:`PartialMessageable`.
|
||||||
- :attr:`Guild.preferred_locale` is now of type :class:`Locale`.
|
- :attr:`Guild.preferred_locale` is now of type :class:`Locale`.
|
||||||
|
- :attr:`abc.GuildChannel.overwrites` keys can now have :class:`Object` in them.
|
||||||
|
|
||||||
Removals
|
Removals
|
||||||
----------
|
----------
|
||||||
|
Reference in New Issue
Block a user