Skip to content

Commit b350ca1

Browse files
committed
Add is_vip property to Chatter
Add is_vip property to Chatter
1 parent d89efe9 commit b350ca1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Master
44
======
55
- TwitchIO
6+
- Additions
7+
- Added :func:`~twitchio.Chatter.is_vip` property to Chatter
68
- Bug fixes
79
- Fix whispers that were not able to be parsed
810

twitchio/chatter.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __init__(self, websocket: "WSConnection", **kwargs):
122122
self._mod = None
123123
self._display_name = None
124124
self._colour = None
125+
self._vip = None
125126
return
126127

127128
self.id = self._tags.get("user-id")
@@ -131,9 +132,10 @@ def __init__(self, websocket: "WSConnection", **kwargs):
131132
self._mod = int(self._tags["mod"])
132133
self._display_name = self._tags["display-name"]
133134
self._colour = self._tags["color"]
135+
self._vip = int(self._tags.get("vip", 0))
134136

135137
if self._badges:
136-
self._cached_badges = {k: v for k, v in [badge.split("/") for badge in self._badges.split(",")]}
138+
self._cached_badges = dict([badge.split("/") for badge in self._badges.split(",")])
137139

138140
def _bot_is_mod(self):
139141
cache = self._ws._cache[self._channel.name] # noqa
@@ -154,10 +156,7 @@ def name(self) -> str:
154156
@property
155157
def badges(self) -> dict:
156158
"""The users badges."""
157-
if self._cached_badges:
158-
return self._cached_badges.copy()
159-
160-
return {}
159+
return self._cached_badges.copy() if self._cached_badges else {}
161160

162161
@property
163162
def display_name(self) -> str:
@@ -188,10 +187,12 @@ def is_broadcaster(self) -> bool:
188187
@property
189188
def is_mod(self) -> bool:
190189
"""A boolean indicating whether the User is a moderator of the current channel."""
191-
if self._mod == 1:
192-
return True
190+
return True if self._mod == 1 else self.channel.name == self.name.lower()
193191

194-
return self.channel.name == self.name.lower()
192+
@property
193+
def is_vip(self) -> bool:
194+
"""A boolean indicating whether the User is a VIP of the current channel."""
195+
return bool(self._vip)
195196

196197
@property
197198
def is_turbo(self) -> Optional[bool]:

0 commit comments

Comments
 (0)