Skip to content

Commit fcdf850

Browse files
committed
Merge branch 'master' into feature/ws-eventsub
2 parents 157c024 + 14342e6 commit fcdf850

File tree

5 files changed

+59
-17
lines changed

5 files changed

+59
-17
lines changed

docs/changelog.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
:orphan:
22

33

4+
Master
5+
======
6+
- TwitchIO
7+
- Additions
8+
- Added optional ``started_at`` and ``ended_at`` arguments to :func:`~twitchio.PartialUser.fetch_clips`
9+
- Updated docstring regarding new HypeTrain contribution method ``OTHER`` for :attr:`~twitchio.HypeTrainContribution.type`
10+
11+
- Bug fixes
12+
- Fix :func:`~twitchio.PartialUser.fetch_bits_leaderboard` not handling ``started_at`` and :class:`~twitchio.BitsLeaderboard` not correctly parsing
13+
14+
- ext.eventsub
15+
- Additions
16+
- Updated docs regarding new HypeTrain contribution method ``other`` for :attr:`~twitchio.ext.eventsub.HypeTrainContributor.type`
17+
418
2.5.0
519
======
620
- TwitchIO

twitchio/ext/eventsub/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ class HypeTrainContributor:
760760
user: :class:`twitchio.PartialUser`
761761
The user
762762
type: :class:`str`
763-
One of "bits" or "subscription". The way they contributed to the hype train
763+
One of "bits, "subscription" or "other". The way they contributed to the hype train
764764
total: :class:`int`
765765
How many points they've contributed to the Hype Train
766766
"""
@@ -769,7 +769,7 @@ class HypeTrainContributor:
769769

770770
def __init__(self, client: EventSubClient, data: dict):
771771
self.user = _transform_user(client, data, "user")
772-
self.type: Literal["bits", "subscription"] = data["type"] # one of bits, subscription
772+
self.type: Literal["bits", "subscription", "other"] = data["type"] # one of bits, subscription
773773
self.total: int = data["total"]
774774

775775

twitchio/http.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,24 @@ async def get_game_analytics(
315315
raise NotImplementedError # TODO
316316

317317
async def get_bits_board(
318-
self, token: str, period: str = "all", user_id: str = None, started_at: datetime.datetime = None
318+
self,
319+
token: str,
320+
period: str = "all",
321+
user_id: Optional[str] = None,
322+
started_at: Optional[datetime.datetime] = None,
319323
):
320324
assert period in {"all", "day", "week", "month", "year"}
325+
query = [
326+
("period", period),
327+
("started_at", started_at.isoformat() if started_at else None),
328+
("user_id", user_id),
329+
]
330+
321331
route = Route(
322332
"GET",
323333
"bits/leaderboard",
324334
"",
325-
query=[
326-
("period", period),
327-
("started_at", started_at.isoformat() if started_at else None),
328-
("user_id", user_id),
329-
],
335+
query=[q for q in query if q[1] is not None],
330336
token=token,
331337
)
332338
return await self.request(route, full_body=True, paginate=False)
@@ -551,6 +557,11 @@ async def get_clips(
551557
ended_at: Optional[datetime.datetime] = None,
552558
token: Optional[str] = None,
553559
):
560+
if started_at and started_at.tzinfo is None:
561+
started_at = started_at.replace(tzinfo=datetime.timezone.utc)
562+
if ended_at and ended_at.tzinfo is None:
563+
ended_at = ended_at.replace(tzinfo=datetime.timezone.utc)
564+
554565
q = [
555566
("broadcaster_id", broadcaster_id),
556567
("game_id", game_id),

twitchio/models.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ class BitsLeaderboard:
8585
8686
Attributes
8787
------------
88-
started_at: :class:`datetime.datetime`
88+
started_at: Optional[:class:`datetime.datetime`]
8989
The time the leaderboard started.
90-
ended_at: :class`datetime.datetime`
90+
ended_at: Optional[:class:`datetime.datetime`]
9191
The time the leaderboard ended.
9292
leaders: List[:class:`BitLeaderboardUser`]
9393
The current leaders of the Leaderboard.
@@ -97,8 +97,10 @@ class BitsLeaderboard:
9797

9898
def __init__(self, http: "TwitchHTTP", data: dict):
9999
self._http = http
100-
self.started_at = datetime.datetime.fromisoformat(data["date_range"]["started_at"])
101-
self.ended_at = datetime.datetime.fromisoformat(data["date_range"]["ended_at"])
100+
self.started_at = (
101+
parse_timestamp(data["date_range"]["started_at"]) if data["date_range"]["started_at"] else None
102+
)
103+
self.ended_at = parse_timestamp(data["date_range"]["ended_at"]) if data["date_range"]["ended_at"] else None
102104
self.leaders = [BitLeaderboardUser(http, x) for x in data["data"]]
103105

104106
def __repr__(self):
@@ -333,7 +335,7 @@ class HypeTrainContribution:
333335
If type is ``SUBS``, aggregate total where 500, 1000, or 2500 represent tier 1, 2, or 3 subscriptions respectively.
334336
For example, if top contributor has gifted a tier 1, 2, and 3 subscription, total would be 4000.
335337
type: :class:`str`
336-
Identifies the contribution method, either BITS or SUBS.
338+
Identifies the contribution method, either BITS, SUBS or OTHER.
337339
user: :class:`~twitchio.PartialUser`
338340
The user making the contribution.
339341
"""

twitchio/user.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ async def create_custom_reward(
261261
raise
262262

263263
async def fetch_bits_leaderboard(
264-
self, token: str, period: str = "all", user_id: int = None, started_at: datetime.datetime = None
264+
self,
265+
token: str,
266+
period: str = "all",
267+
user_id: Optional[int] = None,
268+
started_at: Optional[datetime.datetime] = None,
265269
) -> "BitsLeaderboard":
266270
"""|coro|
267271
@@ -280,7 +284,7 @@ async def fetch_bits_leaderboard(
280284
"""
281285
from .models import BitsLeaderboard
282286

283-
data = await self._http.get_bits_board(token, period, user_id, started_at)
287+
data = await self._http.get_bits_board(token, period, str(user_id), started_at)
284288
return BitsLeaderboard(self._http, data)
285289

286290
async def start_commercial(self, token: str, length: int) -> dict:
@@ -322,19 +326,30 @@ async def create_clip(self, token: str, has_delay=False) -> dict:
322326
data = await self._http.post_create_clip(token, self.id, has_delay)
323327
return data[0]
324328

325-
async def fetch_clips(self) -> List["Clip"]:
329+
async def fetch_clips(
330+
self, started_at: Optional[datetime.datetime] = None, ended_at: Optional[datetime.datetime] = None
331+
) -> List["Clip"]:
326332
"""|coro|
327333
328334
Fetches clips from the api. This will only return clips from the specified user.
329335
Use :class:`Client.fetch_clips` to fetch clips by id
330336
337+
Parameters
338+
-----------
339+
started_at: Optional[:class:`datetime.datetime`]
340+
Starting date/time for returned clips.
341+
If this is specified, ended_at also should be specified; otherwise, the ended_at date/time will be 1 week after the started_at value.
342+
ended_at: Optional[:class:`datetime.datetime`]
343+
Ending date/time for returned clips.
344+
If this is specified, started_at also must be specified; otherwise, the time period is ignored.
345+
331346
Returns
332347
--------
333348
List[:class:`twitchio.Clip`]
334349
"""
335350
from .models import Clip
336351

337-
data = await self._http.get_clips(self.id)
352+
data = await self._http.get_clips(self.id, started_at=started_at, ended_at=ended_at)
338353

339354
return [Clip(self._http, x) for x in data]
340355

0 commit comments

Comments
 (0)