Skip to content

Commit 365f2ad

Browse files
committed
make Chatter.is_subscriber return true for founders
1 parent bc6b655 commit 365f2ad

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
======
55
- TwitchIO
66
- :class:`Chatter` fixed the docstring for the `badges` property
7+
- :func:`Chatter.is_subscriber` will now return True for founders
78
- :class:`Client` change docstring on `fetch_channel`
89
- Add support for the predictions API routes
910
- :class:`Prediction`, :class:`Predictor`, :class:`PredictionOutcome`

twitchio/chatter.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
DEALINGS IN THE SOFTWARE.
2323
"""
2424

25-
from typing import Optional, TYPE_CHECKING
25+
from typing import Optional, TYPE_CHECKING, Dict
2626

2727
from .abcs import Messageable
2828
from .enums import PredictionEnum
2929

3030
if TYPE_CHECKING:
31-
from .channel import Channel
3231
from .user import User
3332
from .websocket import WSConnection
3433

@@ -92,6 +91,7 @@ class Chatter(PartialChatter):
9291
"_channel",
9392
"_tags",
9493
"_badges",
94+
"_cached_badges",
9595
"_ws",
9696
"id",
9797
"_turbo",
@@ -126,6 +126,10 @@ def __init__(self, websocket: "WSConnection", **kwargs):
126126
self._display_name = self._tags["display-name"]
127127
self._colour = self._tags["color"]
128128

129+
self._cached_badges: Optional[Dict[str, str]] = None
130+
if self._badges:
131+
self._cached_badges = {k: v for k, v in [badge.split("/") for badge in self._badges.split(",")]}
132+
129133
def _bot_is_mod(self):
130134
cache = self._ws._cache[self._channel.name] # noqa
131135
for user in cache:
@@ -145,7 +149,10 @@ def name(self) -> str:
145149
@property
146150
def badges(self) -> dict:
147151
"""The users badges."""
148-
return {k: v for k, v in [badge.split("/") for badge in self._badges.split(",")]}
152+
if self._cached_badges:
153+
return self._cached_badges.copy()
154+
155+
return {}
149156

150157
@property
151158
def display_name(self) -> str:
@@ -178,12 +185,14 @@ def is_turbo(self) -> Optional[bool]:
178185
return self._turbo
179186

180187
@property
181-
def is_subscriber(self) -> Optional[bool]:
188+
def is_subscriber(self) -> bool:
182189
"""A boolean indicating whether the User is a subscriber of the current channel.
183190
184-
Could be None if no Tags were received.
191+
.. note::
192+
193+
changed in 2.1.0: return value is no longer optional. founders will now appear as subscribers
185194
"""
186-
return self._sub or "founder" in self._tags
195+
return self._sub or "founder" in self.badges
187196

188197
@property
189198
def prediction(self) -> Optional[PredictionEnum]:
@@ -194,10 +203,10 @@ def prediction(self) -> Optional[PredictionEnum]:
194203
--------
195204
Optional[:class:`twitchio.enums.PredictionEnum`]
196205
"""
197-
if "blue-1" in self._badges:
206+
if "blue-1" in self.badges:
198207
return PredictionEnum("blue-1")
199208

200-
elif "pink-2" in self._badges:
209+
elif "pink-2" in self.badges:
201210
return PredictionEnum("pink-2")
202211

203212
return None

0 commit comments

Comments
 (0)