Browse Source

Fix: color=primary_color and add types

pull/10214/head
makerze 3 weeks ago
parent
commit
ee963d05a6
  1. 16
      discord/guild.py
  2. 17
      discord/role.py
  3. 2
      discord/types/role.py

16
discord/guild.py

@ -3757,24 +3757,20 @@ class Guild(Hashable):
else:
fields['color'] = actual_colour.value
actual_secondary_colour = secondary_colour or secondary_color
actual_secondary_colour = secondary_colour or secondary_color or Colour.default()
actual_tertiary_colour = tertiary_colour or tertiary_color
colours = {
'primary_color': fields['color'],
}
if actual_secondary_colour is not MISSING:
if actual_secondary_colour is None:
colours['secondary_color'] = None
elif isinstance(actual_secondary_colour, int):
if isinstance(actual_secondary_colour, int):
colours['secondary_color'] = actual_secondary_colour
else:
colours['secondary_color'] = actual_secondary_colour.value
if actual_tertiary_colour is not MISSING:
if actual_tertiary_colour is None:
colours['tertiary_color'] = None
elif isinstance(actual_tertiary_colour, int):
if actual_tertiary_colour is not MISSING and actual_tertiary_colour is not None:
if isinstance(actual_tertiary_colour, int):
colours['tertiary_color'] = actual_tertiary_colour
else:
colours['tertiary_color'] = actual_tertiary_colour.value

17
discord/role.py

@ -222,7 +222,6 @@ class Role(Hashable):
'tags',
'_flags',
'_state',
'_primary_colour',
'_secondary_colour',
'_tertiary_colour',
)
@ -288,7 +287,6 @@ class Role(Hashable):
self.tags: Optional[RoleTags]
self._flags: int = data.get('flags', 0)
colors = data.get('colors', {})
self._primary_colour = colors.get('primary_colour', None)
self._secondary_colour = colors.get('secondary_colour', None)
self._tertiary_colour = colors.get('tertiary_colour', None)
@ -330,16 +328,6 @@ class Role(Hashable):
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)
@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
def secondary_colour(self) -> Optional[Colour]:
"""Optional[:class:`Colour`]: The role's secondary colour."""
@ -568,7 +556,10 @@ class Role(Hashable):
colours = {
'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 None:
colours['secondary_color'] = None

2
discord/types/role.py

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

Loading…
Cancel
Save