Browse Source

Fix: types and broken none

pull/10214/head
makerze 4 weeks ago
parent
commit
95c4744a30
  1. 35
      discord/guild.py
  2. 18
      discord/role.py
  3. 1
      discord/types/guild.py
  4. 9
      discord/types/role.py

35
discord/guild.py

@ -3648,8 +3648,8 @@ class Guild(Hashable):
hoist: bool = ..., hoist: bool = ...,
display_icon: Union[bytes, str] = MISSING, display_icon: Union[bytes, str] = MISSING,
mentionable: bool = ..., mentionable: bool = ...,
secondary_colour: Union[Colour, int, None] = ..., secondary_colour: Optional[Union[Colour, int]] = ...,
tertiary_colour: Union[Colour, int, None] = ..., tertiary_colour: Optional[Union[Colour, int]] = ...,
) -> Role: ) -> Role:
... ...
@ -3664,8 +3664,8 @@ class Guild(Hashable):
hoist: bool = ..., hoist: bool = ...,
display_icon: Union[bytes, str] = MISSING, display_icon: Union[bytes, str] = MISSING,
mentionable: bool = ..., mentionable: bool = ...,
secondary_color: Union[Colour, int, None] = ..., secondary_color: Optional[Union[Colour, int]] = ...,
tertiary_color: Union[Colour, int, None] = ..., tertiary_color: Optional[Union[Colour, int]] = ...,
) -> Role: ) -> Role:
... ...
@ -3680,10 +3680,10 @@ class Guild(Hashable):
display_icon: Union[bytes, str] = MISSING, display_icon: Union[bytes, str] = MISSING,
mentionable: bool = MISSING, mentionable: bool = MISSING,
reason: Optional[str] = None, reason: Optional[str] = None,
secondary_color: Union[Colour, int, None] = MISSING, secondary_color: Optional[Union[Colour, int]] = MISSING,
tertiary_color: Union[Colour, int, None] = MISSING, tertiary_color: Optional[Union[Colour, int]] = MISSING,
secondary_colour: Union[Colour, int, None] = MISSING, secondary_colour: Optional[Union[Colour, int]] = MISSING,
tertiary_colour: Union[Colour, int, None] = MISSING, tertiary_colour: Optional[Union[Colour, int]] = MISSING,
) -> Role: ) -> Role:
"""|coro| """|coro|
@ -3712,9 +3712,9 @@ class Guild(Hashable):
colour: Union[:class:`Colour`, :class:`int`] colour: Union[:class:`Colour`, :class:`int`]
The colour for the role. Defaults to :meth:`Colour.default`. The colour for the role. Defaults to :meth:`Colour.default`.
This is aliased to ``color`` as well. This is aliased to ``color`` as well.
secondary_colour: Union[:class:`Colour`, :class:`int`, None] secondary_colour: Optional[Union[:class:`Colour`, :class:`int`]]
The secondary colour for the role. The secondary colour for the role.
tertiary_colour: Union[:class:`Colour`, :class:`int`, None] tertiary_colour: Optional[Union[:class:`Colour`, :class:`int`]]
The tertiary colour for the role. Can only be used for the holographic role preset, The tertiary colour for the role. Can only be used for the holographic role preset,
which is ``(11127295, 16759788, 16761760)`` which is ``(11127295, 16759788, 16761760)``
hoist: :class:`bool` hoist: :class:`bool`
@ -3757,20 +3757,25 @@ class Guild(Hashable):
else: else:
fields['color'] = actual_colour.value fields['color'] = actual_colour.value
actual_secondary_colour = secondary_colour or secondary_color or Colour.default() actual_secondary_colour = secondary_colour or secondary_color
actual_tertiary_colour = tertiary_colour or tertiary_color actual_tertiary_colour = tertiary_colour or tertiary_color
colours = {
colours: Dict[str, Any] = {
'primary_color': fields['color'], 'primary_color': fields['color'],
} }
if actual_secondary_colour is not MISSING: if actual_secondary_colour is not MISSING:
if isinstance(actual_secondary_colour, int): if actual_secondary_colour is None:
colours['secondary_color'] = None
elif isinstance(actual_secondary_colour, int):
colours['secondary_color'] = actual_secondary_colour colours['secondary_color'] = actual_secondary_colour
else: else:
colours['secondary_color'] = actual_secondary_colour.value colours['secondary_color'] = actual_secondary_colour.value
if actual_tertiary_colour is not MISSING and actual_tertiary_colour is not None: if actual_tertiary_colour is not MISSING:
if isinstance(actual_tertiary_colour, int): if actual_tertiary_colour is None:
colours['tertiary_color'] = None
elif isinstance(actual_tertiary_colour, int):
colours['tertiary_color'] = actual_tertiary_colour colours['tertiary_color'] = actual_tertiary_colour
else: else:
colours['tertiary_color'] = actual_tertiary_colour.value colours['tertiary_color'] = actual_tertiary_colour.value

18
discord/role.py

@ -287,8 +287,8 @@ class Role(Hashable):
self.tags: Optional[RoleTags] self.tags: Optional[RoleTags]
self._flags: int = data.get('flags', 0) self._flags: int = data.get('flags', 0)
colors = data.get('colors', {}) colors = data.get('colors', {})
self._secondary_colour = colors.get('secondary_colour', None) self._secondary_colour = colors.get('secondary_color', None)
self._tertiary_colour = colors.get('tertiary_colour', None) self._tertiary_colour = colors.get('tertiary_color', None)
try: try:
self.tags = RoleTags(data['tags']) # pyright: ignore[reportTypedDictNotRequiredAccess] self.tags = RoleTags(data['tags']) # pyright: ignore[reportTypedDictNotRequiredAccess]
@ -450,10 +450,10 @@ class Role(Hashable):
mentionable: bool = MISSING, mentionable: bool = MISSING,
position: int = MISSING, position: int = MISSING,
reason: Optional[str] = MISSING, reason: Optional[str] = MISSING,
secondary_color: Union[Colour, int, None] = MISSING, secondary_color: Optional[Union[Colour, int]] = MISSING,
tertiary_color: Union[Colour, int, None] = MISSING, tertiary_color: Optional[Union[Colour, int]] = MISSING,
secondary_colour: Union[Colour, int, None] = MISSING, secondary_colour: Optional[Union[Colour, int]] = MISSING,
tertiary_colour: Union[Colour, int, None] = MISSING, tertiary_colour: Optional[Union[Colour, int]] = MISSING,
) -> Optional[Role]: ) -> Optional[Role]:
"""|coro| """|coro|
@ -484,9 +484,9 @@ class Role(Hashable):
The new permissions to change to. The new permissions to change to.
colour: Union[:class:`Colour`, :class:`int`] colour: Union[:class:`Colour`, :class:`int`]
The new colour to change to. (aliased to color as well) The new colour to change to. (aliased to color as well)
secondary_colour: Union[:class:`Colour`, :class:`int`, None] secondary_colour: Optional[Union[:class:`Colour`, :class:`int`]]
The new secondary colour for the role. The new secondary colour for the role.
tertiary_colour: Union[:class:`Colour`, :class:`int`, None] tertiary_colour: Optional[Union[:class:`Colour`, :class:`int`]]
The new tertiary colour for the role. Can only be used for the holographic role preset, The new tertiary colour for the role. Can only be used for the holographic role preset,
which is ``(11127295, 16759788, 16761760)`` which is ``(11127295, 16759788, 16761760)``
hoist: :class:`bool` hoist: :class:`bool`
@ -553,7 +553,7 @@ class Role(Hashable):
if mentionable is not MISSING: if mentionable is not MISSING:
payload['mentionable'] = mentionable payload['mentionable'] = mentionable
colours = { colours: Dict[str, Any] = {
'primary_color': payload['color'], 'primary_color': payload['color'],
} }

1
discord/types/guild.py

@ -90,6 +90,7 @@ GuildFeature = Literal[
'VERIFIED', 'VERIFIED',
'VIP_REGIONS', 'VIP_REGIONS',
'WELCOME_SCREEN_ENABLED', 'WELCOME_SCREEN_ENABLED',
'ENHANCED_ROLE_COLORS',
'RAID_ALERTS_DISABLED', 'RAID_ALERTS_DISABLED',
'SOUNDBOARD', 'SOUNDBOARD',
'MORE_SOUNDBOARD', 'MORE_SOUNDBOARD',

9
discord/types/role.py

@ -30,12 +30,17 @@ from typing_extensions import NotRequired
from .snowflake import Snowflake from .snowflake import Snowflake
class RoleColours(TypedDict):
primary_color: int
secondary_color: Optional[int]
tertiary_color: Optional[int]
class Role(TypedDict): class Role(TypedDict):
id: Snowflake id: Snowflake
name: str name: str
color: int color: int
secondary_color: NotRequired[Optional[int]] colors: RoleColours
tertiary_color: NotRequired[Optional[int]]
hoist: bool hoist: bool
position: int position: int
permissions: str permissions: str

Loading…
Cancel
Save