-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add role parameters to support new gradient and holographic roles #10214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
44fb360
4d05813
89961e5
e230384
59a35a2
c8542c4
9e78b95
d26e4d6
f1047a5
8bcc0c7
8644374
8b5895c
ee963d0
95c4744
98e3668
343130f
70b5a17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3648,6 +3648,8 @@ async def create_role( | |
| hoist: bool = ..., | ||
| display_icon: Union[bytes, str] = MISSING, | ||
| mentionable: bool = ..., | ||
| secondary_colour: Union[Colour, int, None] = ..., | ||
| tertiary_colour: Union[Colour, int, None] = ..., | ||
| ) -> Role: | ||
| ... | ||
|
|
||
|
|
@@ -3662,6 +3664,8 @@ async def create_role( | |
| hoist: bool = ..., | ||
| display_icon: Union[bytes, str] = MISSING, | ||
| mentionable: bool = ..., | ||
| secondary_color: Union[Colour, int, None] = ..., | ||
| tertiary_color: Union[Colour, int, None] = ..., | ||
| ) -> Role: | ||
| ... | ||
|
|
||
|
|
@@ -3676,6 +3680,10 @@ async def create_role( | |
| display_icon: Union[bytes, str] = MISSING, | ||
| mentionable: bool = MISSING, | ||
| reason: Optional[str] = None, | ||
| secondary_color: Union[Colour, int, None] = MISSING, | ||
| tertiary_color: Union[Colour, int, None] = MISSING, | ||
| secondary_colour: Union[Colour, int, None] = MISSING, | ||
| tertiary_colour: Union[Colour, int, None] = MISSING, | ||
| ) -> Role: | ||
| """|coro| | ||
|
|
||
|
|
@@ -3704,6 +3712,11 @@ async def create_role( | |
| colour: Union[:class:`Colour`, :class:`int`] | ||
| The colour for the role. Defaults to :meth:`Colour.default`. | ||
| This is aliased to ``color`` as well. | ||
| secondary_colour: Union[:class:`Colour`, :class:`int`, None] | ||
| The secondary colour for the role. | ||
| tertiary_colour: Union[:class:`Colour`, :class:`int`, None] | ||
| The tertiary colour for the role. Can only be used for the holographic role preset, | ||
| which is ``(11127295, 16759788, 16761760)`` | ||
makerze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| hoist: :class:`bool` | ||
| Indicates if the role should be shown separately in the member list. | ||
| Defaults to ``False``. | ||
|
|
@@ -3744,6 +3757,26 @@ async def create_role( | |
| else: | ||
| fields['color'] = actual_colour.value | ||
|
||
|
|
||
| actual_secondary_colour = secondary_colour or secondary_color or Colour.default() | ||
makerze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| actual_tertiary_colour = tertiary_colour or tertiary_color | ||
| colours = { | ||
| 'primary_color': fields['color'], | ||
| } | ||
|
|
||
| if actual_secondary_colour is not MISSING: | ||
| if isinstance(actual_secondary_colour, int): | ||
| colours['secondary_color'] = actual_secondary_colour | ||
| else: | ||
makerze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| colours['secondary_color'] = actual_secondary_colour.value | ||
|
|
||
| if actual_tertiary_colour is not MISSING and actual_tertiary_colour is not None: | ||
makerze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if isinstance(actual_tertiary_colour, int): | ||
| colours['tertiary_color'] = actual_tertiary_colour | ||
| else: | ||
| colours['tertiary_color'] = actual_tertiary_colour.value | ||
makerze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| fields['colors'] = colours | ||
|
|
||
| if hoist is not MISSING: | ||
| fields['hoist'] = hoist | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,6 +222,8 @@ class Role(Hashable): | |
| 'tags', | ||
| '_flags', | ||
| '_state', | ||
| '_secondary_colour', | ||
| '_tertiary_colour', | ||
| ) | ||
|
|
||
| def __init__(self, *, guild: Guild, state: ConnectionState, data: RolePayload): | ||
|
|
@@ -284,6 +286,9 @@ def _update(self, data: RolePayload): | |
| self.mentionable: bool = data.get('mentionable', False) | ||
| self.tags: Optional[RoleTags] | ||
| self._flags: int = data.get('flags', 0) | ||
| colors = data.get('colors', {}) | ||
| self._secondary_colour = colors.get('secondary_colour', None) | ||
| self._tertiary_colour = colors.get('tertiary_colour', None) | ||
|
|
||
| try: | ||
| self.tags = RoleTags(data['tags']) # pyright: ignore[reportTypedDictNotRequiredAccess] | ||
|
|
@@ -323,6 +328,26 @@ def is_assignable(self) -> bool: | |
| 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 secondary_colour(self) -> Optional[Colour]: | ||
| """Optional[:class:`Colour`]: The role's secondary colour.""" | ||
| return Colour(self._secondary_colour) if self._secondary_colour is not None else None | ||
|
|
||
| @property | ||
| def secondary_color(self) -> Optional[Colour]: | ||
| """Optional[:class:`Colour`]: Alias for :attr:`secondary_colour`.""" | ||
| return self.secondary_colour | ||
|
|
||
| @property | ||
| def tertiary_colour(self) -> Optional[Colour]: | ||
| """Optional[:class:`Colour`]: The role's tertiary colour.""" | ||
| return Colour(self._tertiary_colour) if self._tertiary_colour is not None else None | ||
|
|
||
| @property | ||
| def tertiary_color(self) -> Optional[Colour]: | ||
| """Optional[:class:`Colour`]: Alias for :attr:`tertiary_colour`.""" | ||
| return self.tertiary_colour | ||
|
|
||
| @property | ||
| def permissions(self) -> Permissions: | ||
| """:class:`Permissions`: Returns the role's permissions.""" | ||
|
|
@@ -425,6 +450,10 @@ async def edit( | |
| mentionable: bool = MISSING, | ||
| position: int = MISSING, | ||
| reason: Optional[str] = MISSING, | ||
| secondary_color: Union[Colour, int, None] = MISSING, | ||
| tertiary_color: Union[Colour, int, None] = MISSING, | ||
| secondary_colour: Union[Colour, int, None] = MISSING, | ||
| tertiary_colour: Union[Colour, int, None] = MISSING, | ||
| ) -> Optional[Role]: | ||
| """|coro| | ||
|
|
||
|
|
@@ -455,6 +484,11 @@ async def edit( | |
| The new permissions to change to. | ||
| colour: Union[:class:`Colour`, :class:`int`] | ||
| The new colour to change to. (aliased to color as well) | ||
| secondary_colour: Union[:class:`Colour`, :class:`int`, None] | ||
| The new secondary colour for the role. | ||
| tertiary_colour: Union[:class:`Colour`, :class:`int`, None] | ||
| The new tertiary colour for the role. Can only be used for the holographic role preset, | ||
| which is ``(11127295, 16759788, 16761760)`` | ||
| hoist: :class:`bool` | ||
| Indicates if the role should be shown separately in the member list. | ||
| display_icon: Optional[Union[:class:`bytes`, :class:`str`]] | ||
|
|
@@ -519,6 +553,29 @@ async def edit( | |
| if mentionable is not MISSING: | ||
| payload['mentionable'] = mentionable | ||
|
|
||
| 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 | ||
| elif 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): | ||
| colours['tertiary_color'] = actual_tertiary_colour | ||
| else: | ||
| colours['tertiary_color'] = actual_tertiary_colour.value | ||
|
|
||
| payload['colors'] = colours | ||
makerze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| data = await self._state.http.edit_role(self.guild.id, self.id, reason=reason, **payload) | ||
| return Role(guild=self.guild, data=data, state=self._state) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.