Skip to content

Commit 9dc6ee2

Browse files
committed
Make Colour Optional for ChatterColor
1 parent 5774dee commit 9dc6ee2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

twitchio/models/chat.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,28 @@ class ChatterColor:
9797
-----------
9898
user: PartialUser
9999
PartialUser of the chatter.
100-
colour: Colour
100+
colour: Colour | None
101101
The :class:`~twitchio.utils.Colour`. There is an alias to this named `color`.
102+
This is `None` if a colour is not set.
102103
"""
103104

104105
__slots__ = ("_colour", "user")
105106

106107
def __init__(self, data: UserChatColorResponseData, *, http: HTTPClient) -> None:
107108
self.user = PartialUser(data["user_id"], data["user_login"], data["user_name"], http=http)
108-
self._colour: Colour = Colour.from_hex(data["color"])
109+
self._colour: Colour | None = Colour.from_hex(data["color"]) if data.get("color") else None
109110

110111
def __repr__(self) -> str:
111112
return f"<ChatterColor user={self.user} color={self.colour}>"
112113

113114
@property
114-
def colour(self) -> Colour:
115+
def colour(self) -> Colour | None:
115116
return self._colour
116117

117118
color = colour
118119

119120
def __str__(self) -> str:
120-
return self._colour.hex
121+
return self._colour.hex if self._colour is not None else ""
121122

122123

123124
class ChatBadge:

0 commit comments

Comments
 (0)