Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1379.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds Role.is_gradient and Role.is_holographic properties to check whether a role is gradient or holographic.
20 changes: 20 additions & 0 deletions disnake/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,26 @@ def tertiary_color(self) -> Optional[Colour]:
"""
return self.tertiary_colour

@property
def is_gradient(self) -> bool:
"""Whether the role is gradient.

.. versionadded:: 2.11.1

:return type: :class:`bool`
"""
return self.secondary_color is not None and self.tertiary_color is None

@property
def is_holographic(self) -> bool:
"""Whether the role is holographic.

.. versionadded:: 2.11.1

:return type: :class:`bool`
"""
return self.tertiary_color is not None

@property
def icon(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Returns the role's icon asset, if available.
Expand Down
31 changes: 31 additions & 0 deletions tests/test_role_gradient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def make_role(primary=None, secondary=None, tertiary=None):
class DummyRole:
def __init__(self, p, s, t):
self.primary_color = p
self.secondary_color = s
self.tertiary_color = t

@property
def is_gradient(self) -> bool:
return self.secondary_color is not None and self.tertiary_color is None

@property
def is_holographic(self) -> bool:
return self.tertiary_color is not None

return DummyRole(primary, secondary, tertiary)

def test_is_gradient_true():
r = make_role(primary=0x111111, secondary=0x222222, tertiary=None)
assert r.is_gradient is True
assert r.is_holographic is False

def test_is_holographic_true():
r = make_role(primary=0x111111, secondary=0x222222, tertiary=0x333333)
assert r.is_holographic is True
assert r.is_gradient is False

def test_basic_role():
r = make_role(primary=0x111111, secondary=None, tertiary=None)
assert r.is_gradient is False
assert r.is_holographic is False
Loading