Skip to content

Commit b929339

Browse files
committed
Add PartualUser method fetch_shield_mode_status
Add PartualUser method fetch_shield_mode_status
1 parent fba82bc commit b929339

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Master
1212
- Added :attr:`~twitchio.Game.igdb_id` to :class:`~twitchio.Game`
1313
- Added ``igdb_ids`` argument to :func:`~twitchio.Client.fetch_games`
1414
- Added ``tags`` attribute to :class:`~twitchio.Stream`, :class:`~twitchio.ChannelInfo` and :class:`~twitchio.SearchUser`
15+
- Added :func:`~twitchio.PartialUser.fetch_shield_mode_status`
1516

1617
- Bug fixes
1718
- Fix :func:`~twitchio.PartialUser.fetch_bits_leaderboard` not handling ``started_at`` and :class:`~twitchio.BitsLeaderboard` not correctly parsing

twitchio/http.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,3 +1108,9 @@ async def get_follow_count(
11081108
full_body=True,
11091109
paginate=False,
11101110
)
1111+
1112+
async def get_shield_mode_status(self, token: str, broadcaster_id: str, moderator_id: str):
1113+
q = [("broadcaster_id", broadcaster_id), ("moderator_id", moderator_id)]
1114+
return await self.request(
1115+
Route("GET", "moderation/shield_mode", query=q, token=token), paginate=False, full_body=False
1116+
)

twitchio/models.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,3 +1790,37 @@ def __init__(self, http: "TwitchHTTP", data: dict):
17901790

17911791
def __repr__(self):
17921792
return f"<Timeout broadcaster={self.broadcaster} user={self.user} created_at={self.created_at} end_time={self.end_time}>"
1793+
1794+
1795+
class ShieldStatus:
1796+
"""
1797+
Represents a Shield Mode activation status.
1798+
1799+
Attributes
1800+
-----------
1801+
moderator: :class:`~twitchio.PartialUser`
1802+
The moderator that last activated Shield Mode.
1803+
display_name: :class:`str`
1804+
The moderator's display name. Is an empty string if Shield Mode hasn't been previously activated.
1805+
last_activated_at: :class:`datetime.datetime`
1806+
The UTC datetime of when Shield Mode was last activated.
1807+
Is an empty string if Shield Mode hasn't been previously activated.
1808+
is_active: :class:`bool`
1809+
A Boolean value that determines whether Shield Mode is active.
1810+
Is true if the broadcaster activated Shield Mode; otherwise, false.
1811+
"""
1812+
1813+
__slots__ = ("moderator", "display_name", "last_activated_at", "is_active")
1814+
1815+
def __init__(self, http: "TwitchHTTP", data: dict):
1816+
self.moderator: Optional[PartialUser] = (
1817+
PartialUser(http, data["moderator_id"], data["moderator_login"]) if data["moderator_id"] else None
1818+
)
1819+
self.display_name: Optional[str] = data.get("moderator_name")
1820+
self.is_active: bool = data["is_active"]
1821+
self.last_activated_at: Optional[datetime.datetime] = (
1822+
parse_timestamp(data["last_activated_at"]) if data["last_activated_at"] else None
1823+
)
1824+
1825+
def __repr__(self):
1826+
return f"<ShieldStatus moderator={self.moderator} is_active={self.is_active} last_activated_at={self.last_activated_at}>"

twitchio/user.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,30 @@ async def send_whisper(self, token: str, user_id: int, message: str):
15021502

15031503
await self._http.post_whisper(token=token, from_user_id=str(self.id), to_user_id=str(user_id), message=message)
15041504

1505+
async def fetch_shield_mode_status(self, token: str, moderator_id: int):
1506+
"""|coro|
1507+
1508+
Fetches the user's Shield Mode activation status.
1509+
1510+
Parameters
1511+
-----------
1512+
token: :class:`str`
1513+
An oauth user token with the ``moderator:read:shield_mode`` or ``moderator:manage:shield_mode`` scope.
1514+
moderator_id: :class:`int`
1515+
The ID of the broadcaster or a user that is one of the broadcaster's moderators. This ID must match the user ID in the access token.
1516+
1517+
Returns
1518+
--------
1519+
:class:`twitchio.ShieldStatus`
1520+
"""
1521+
from .models import ShieldStatus
1522+
1523+
data = await self._http.get_shield_mode_status(
1524+
broadcaster_id=str(self.id), moderator_id=str(moderator_id), token=token
1525+
)
1526+
1527+
return ShieldStatus(self._http, data[0])
1528+
15051529

15061530
class BitLeaderboardUser(PartialUser):
15071531

0 commit comments

Comments
 (0)