Browse Source

Fix: color=primary_color and add types

pull/10214/head
makerze 4 weeks ago
parent
commit
ee963d05a6
  1. 14
      discord/guild.py
  2. 15
      discord/role.py
  3. 2
      discord/types/role.py

14
discord/guild.py

@ -3757,24 +3757,20 @@ 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 = {
'primary_color': fields['color'], 'primary_color': fields['color'],
} }
if actual_secondary_colour is not MISSING: if actual_secondary_colour is not MISSING:
if actual_secondary_colour is None: if isinstance(actual_secondary_colour, int):
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:
if actual_tertiary_colour is None: if actual_tertiary_colour is not MISSING and actual_tertiary_colour is not None:
colours['tertiary_color'] = None if isinstance(actual_tertiary_colour, int):
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

15
discord/role.py

@ -222,7 +222,6 @@ class Role(Hashable):
'tags', 'tags',
'_flags', '_flags',
'_state', '_state',
'_primary_colour',
'_secondary_colour', '_secondary_colour',
'_tertiary_colour', '_tertiary_colour',
) )
@ -288,7 +287,6 @@ 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._primary_colour = colors.get('primary_colour', None)
self._secondary_colour = colors.get('secondary_colour', None) self._secondary_colour = colors.get('secondary_colour', None)
self._tertiary_colour = colors.get('tertiary_colour', None) self._tertiary_colour = colors.get('tertiary_colour', None)
@ -330,16 +328,6 @@ class Role(Hashable):
me = self.guild.me me = self.guild.me
return not self.is_default() and not self.managed and (me.top_role > self or me.id == self.guild.owner_id) return not self.is_default() and not self.managed and (me.top_role > self or me.id == self.guild.owner_id)
@property
def primary_colour(self) -> Optional[Colour]:
"""Optional[:class:`Colour`]: The role's primary colour."""
return Colour(self._primary_colour) if self._primary_colour is not None else None
@property
def primary_color(self) -> Optional[Colour]:
"""Optional[:class:`Colour`]: Alias for :attr:`primary_colour`."""
return self.primary_colour
@property @property
def secondary_colour(self) -> Optional[Colour]: def secondary_colour(self) -> Optional[Colour]:
"""Optional[:class:`Colour`]: The role's secondary colour.""" """Optional[:class:`Colour`]: The role's secondary colour."""
@ -569,6 +557,9 @@ class Role(Hashable):
'primary_color': payload['color'], 'primary_color': payload['color'],
} }
actual_secondary_colour = secondary_colour or secondary_color
actual_tertiary_colour = tertiary_colour or tertiary_color
if actual_secondary_colour is not MISSING: if actual_secondary_colour is not MISSING:
if actual_secondary_colour is None: if actual_secondary_colour is None:
colours['secondary_color'] = None colours['secondary_color'] = None

2
discord/types/role.py

@ -34,6 +34,8 @@ class Role(TypedDict):
id: Snowflake id: Snowflake
name: str name: str
color: int color: int
secondary_color: NotRequired[Optional[int]]
tertiary_color: NotRequired[Optional[int]]
hoist: bool hoist: bool
position: int position: int
permissions: str permissions: str

Loading…
Cancel
Save