Skip to content

Commit 114950a

Browse files
committed
Additional UserBan attributes
Additional UserBan attributes Add new slots Docs
1 parent 3d421a9 commit 114950a

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Master
2424
- :func:`~twitchio.Client.update_chatter_color`
2525
- Add ``duration`` and ``vod_offset`` attributes to :class:`~twitchio.Clip`
2626
- Added repr for :class:`~twitchio.CustomReward`
27+
- Add extra attributes to :class:`~twitchio.UserBan`
2728
- Bug fixes
2829
- Added ``self.registered_callbacks = {}`` to :func:`~twitchio.Client.from_client_credentials`
2930
- Allow empty or missing initial_channels to trigger :func:`~twitchio.Client.event_ready`

docs/reference.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ AutomodCheckResponse
2727
:members:
2828
:inherited-members:
2929

30+
Ban
31+
----------
32+
.. attributetable:: Ban
33+
34+
.. autoclass:: Ban
35+
:members:
36+
:inherited-members:
37+
3038
BanEvent
3139
----------
3240
.. attributetable:: BanEvent
@@ -332,6 +340,14 @@ Team
332340
:members:
333341
:inherited-members:
334342

343+
Timeout
344+
----------
345+
.. attributetable:: Timeout
346+
347+
.. autoclass:: Timeout
348+
:members:
349+
:inherited-members:
350+
335351
User
336352
------
337353
.. attributetable:: PartialUser

twitchio/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
"ChatSettings",
7373
"Raid",
7474
"ChatterColor",
75+
"Timeout",
76+
"Ban",
7577
)
7678

7779

twitchio/user.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,14 +1438,39 @@ def __init__(self, http: "TwitchHTTP", data: dict):
14381438

14391439

14401440
class UserBan(PartialUser):
1441-
1442-
__slots__ = ("expires_at",)
1441+
"""
1442+
Represents a banned user or one in timeout.
1443+
1444+
Attributes
1445+
----------
1446+
id: :class:`int`
1447+
The ID of the banned user.
1448+
name: :class:`str`
1449+
The name of the banned user.
1450+
created_at: :class:`datetime.datetime`
1451+
The date and time the ban was created.
1452+
expires_at: Optional[:class:`datetime.datetime`]
1453+
The date and time the timeout will expire.
1454+
Is None if it's a ban.
1455+
reason: :class:`str`
1456+
The reason for the ban/timeout.
1457+
moderator: :class:`~twitchio.PartialUser`
1458+
The moderator that banned the user.
1459+
"""
1460+
1461+
__slots__ = ("created_at", "expires_at", "reason", "moderator")
14431462

14441463
def __init__(self, http: "TwitchHTTP", data: dict):
1445-
super(UserBan, self).__init__(http, name=data["user_login"], id=data["user_id"])
1446-
self.expires_at = (
1447-
datetime.datetime.strptime(data["expires_at"], "%Y-%m-%dT%H:%M:%SZ") if data["expires_at"] else None
1464+
super(UserBan, self).__init__(http, id=data["user_id"], name=data["user_login"])
1465+
self.created_at: datetime.datetime = parse_timestamp(data["created_at"])
1466+
self.expires_at: Optional[datetime.datetime] = (
1467+
parse_timestamp(data["expires_at"]) if data["expires_at"] else None
14481468
)
1469+
self.reason: str = data["reason"]
1470+
self.moderator = PartialUser(http, id=data["moderator_id"], name=data["moderator_login"])
1471+
1472+
def __repr__(self):
1473+
return f"<UserBan {super().__repr__()} created_at={self.created_at} expires_at={self.expires_at} reason={self.reason}>"
14491474

14501475

14511476
class SearchUser(PartialUser):

0 commit comments

Comments
 (0)