Skip to content

Commit f0daae7

Browse files
committed
ES shared chat sessions
1 parent 411d2e8 commit f0daae7

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed

twitchio/eventsub/payloads.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,51 @@ def condition(self) -> Condition:
362362
return {"broadcaster_user_id": self.broadcaster_user_id, "user_id": self.user_id}
363363

364364

365+
class SharedChatSessionBeginSubscription(SubscriptionPayload):
366+
type: ClassVar[Literal["channel.shared_chat.begin"]] = "channel.shared_chat.begin"
367+
version: ClassVar[Literal["1"]] = "1"
368+
369+
def __init__(self, **condition: Unpack[Condition]) -> None:
370+
self.broadcaster_user_id: str = condition.get("broadcaster_user_id", "")
371+
372+
if not self.broadcaster_user_id:
373+
raise ValueError('The parameter "broadcaster_user_id" must be passed.')
374+
375+
@property
376+
def condition(self) -> Condition:
377+
return {"broadcaster_user_id": self.broadcaster_user_id}
378+
379+
380+
class SharedChatSessionUpdateSubscription(SubscriptionPayload):
381+
type: ClassVar[Literal["channel.shared_chat.update"]] = "channel.shared_chat.update"
382+
version: ClassVar[Literal["1"]] = "1"
383+
384+
def __init__(self, **condition: Unpack[Condition]) -> None:
385+
self.broadcaster_user_id: str = condition.get("broadcaster_user_id", "")
386+
387+
if not self.broadcaster_user_id:
388+
raise ValueError('The parameter "broadcaster_user_id" must be passed.')
389+
390+
@property
391+
def condition(self) -> Condition:
392+
return {"broadcaster_user_id": self.broadcaster_user_id}
393+
394+
395+
class SharedChatSessionEndSubscription(SubscriptionPayload):
396+
type: ClassVar[Literal["channel.shared_chat.end"]] = "channel.shared_chat.end"
397+
version: ClassVar[Literal["1"]] = "1"
398+
399+
def __init__(self, **condition: Unpack[Condition]) -> None:
400+
self.broadcaster_user_id: str = condition.get("broadcaster_user_id", "")
401+
402+
if not self.broadcaster_user_id:
403+
raise ValueError('The parameter "broadcaster_user_id" must be passed.')
404+
405+
@property
406+
def condition(self) -> Condition:
407+
return {"broadcaster_user_id": self.broadcaster_user_id}
408+
409+
365410
class ChannelSubscribeSubscription(SubscriptionPayload):
366411
type: ClassVar[Literal["channel.subscribe"]] = "channel.subscribe"
367412
version: ClassVar[Literal["1"]] = "1"

twitchio/models/eventsub_.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,114 @@ def full_message(self) -> str:
14961496
return " ".join(fragment.text for fragment in self.fragments if fragment.type == "text")
14971497

14981498

1499+
class BaseSharedChatSession(BaseEvent):
1500+
__slots__ = (
1501+
"session_id",
1502+
"broadcaster",
1503+
"host",
1504+
)
1505+
1506+
def __init__(
1507+
self,
1508+
payload: ChannelSharedChatSessionBeginEvent | ChannelSharedChatSessionUpdateEvent | ChannelSharedChatSessionEndEvent,
1509+
*,
1510+
http: HTTPClient,
1511+
) -> None:
1512+
self.session_id: str = payload["session_id"]
1513+
self.broadcaster: PartialUser = PartialUser(
1514+
payload["broadcaster_user_id"], payload["broadcaster_user_login"], http=http
1515+
)
1516+
self.host: PartialUser = PartialUser(
1517+
payload["host_broadcaster_user_id"], payload["host_broadcaster_user_login"], http=http
1518+
)
1519+
1520+
def __repr__(self) -> str:
1521+
return f"<BaseSharedChatSession session_id={self.session_id} broadcaster={self.broadcaster} host={self.host}>"
1522+
1523+
1524+
class SharedChatSessionBegin(BaseSharedChatSession):
1525+
"""
1526+
Represents a shared chat session begin event.
1527+
1528+
Attributes
1529+
----------
1530+
session_id: PartialUser
1531+
The unique identifier for the shared chat session.
1532+
broadcaster: PartialUser
1533+
The user of the channel in the subscription condition which is now active in the shared chat session.
1534+
host: PartialUser
1535+
The user of the host channel.
1536+
participants: str
1537+
List of participants in the session.
1538+
"""
1539+
1540+
subscription_type = "channel.shared_chat.begin"
1541+
1542+
__slots__ = ("participants",)
1543+
1544+
def __init__(self, payload: ChannelSharedChatSessionBeginEvent, *, http: HTTPClient) -> None:
1545+
super().__init__(payload, http=http)
1546+
self.participants: list[PartialUser] = [
1547+
PartialUser(p["broadcaster_user_id"], p["broadcaster_user_login"], http=http) for p in payload["participants"]
1548+
]
1549+
1550+
def __repr__(self) -> str:
1551+
return f"<BaseSharedChatSession session_id={self.session_id} broadcaster={self.broadcaster} host={self.host}>"
1552+
1553+
1554+
class SharedChatSessionUpdate(BaseSharedChatSession):
1555+
"""
1556+
Represents a shared chat session begin event.
1557+
1558+
Attributes
1559+
----------
1560+
session_id: PartialUser
1561+
The unique identifier for the shared chat session.
1562+
broadcaster: PartialUser
1563+
The user of the channel in the subscription condition which is now active in the shared chat session.
1564+
host: PartialUser
1565+
The user of the host channel.
1566+
participants: str
1567+
List of participants in the session.
1568+
"""
1569+
1570+
subscription_type = "channel.shared_chat.update"
1571+
1572+
__slots__ = ("participants",)
1573+
1574+
def __init__(self, payload: ChannelSharedChatSessionUpdateEvent, *, http: HTTPClient) -> None:
1575+
super().__init__(payload, http=http)
1576+
self.participants: list[PartialUser] = [
1577+
PartialUser(p["broadcaster_user_id"], p["broadcaster_user_login"], http=http) for p in payload["participants"]
1578+
]
1579+
1580+
def __repr__(self) -> str:
1581+
return f"<SharedChatSessionUpdate session_id={self.session_id} broadcaster={self.broadcaster} host={self.host}>"
1582+
1583+
1584+
class SharedChatSessionEnd(BaseSharedChatSession):
1585+
"""
1586+
Represents a shared chat session end event.
1587+
1588+
Attributes
1589+
----------
1590+
session_id: PartialUser
1591+
The unique identifier for the shared chat session.
1592+
broadcaster: PartialUser
1593+
The user of the channel in the subscription condition which is no longer active in the shared chat session.
1594+
host: PartialUser
1595+
The user of the host channel.
1596+
"""
1597+
1598+
subscription_type = "channel.shared_chat.end"
1599+
1600+
def __init__(self, payload: ChannelSharedChatSessionUpdateEvent, *, http: HTTPClient) -> None:
1601+
super().__init__(payload, http=http)
1602+
1603+
def __repr__(self) -> str:
1604+
return f"<SharedChatSessionEnd session_id={self.session_id} broadcaster={self.broadcaster} host={self.host}>"
1605+
1606+
14991607
class ChannelSubscribe(BaseEvent):
15001608
"""
15011609
Represents a channel subscribe event.

twitchio/types_/eventsub.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
"HypeTrainProgressEvent",
127127
"HypeTrainEndEvent",
128128
"HypeTrainContributionData",
129+
"ChannelSharedChatSessionBeginEvent",
130+
"ChannelSharedChatSessionUpdateEvent",
131+
"ChannelSharedChatSessionEndEvent",
129132
"ShieldModeBeginEvent",
130133
"ShieldModeEndEvent",
131134
"ShoutoutCreateEvent",
@@ -566,6 +569,24 @@ class ChatUserMessageUpdateEvent(ChatUserMessageHoldEvent):
566569
status: Literal["approved", "denied", "invalid"]
567570

568571

572+
class BaseSharedChatSessionData(BaseBroadcasterEvent):
573+
session_id: str
574+
host_broadcaster_user_id: str
575+
host_broadcaster_user_login: str
576+
host_broadcaster_user_name: str
577+
578+
579+
class ChannelSharedChatSessionBeginEvent(BaseSharedChatSessionData):
580+
participants: list[BaseBroadcasterEvent]
581+
582+
583+
class ChannelSharedChatSessionUpdateEvent(BaseSharedChatSessionData):
584+
participants: list[BaseBroadcasterEvent]
585+
586+
587+
class ChannelSharedChatSessionEndEvent(BaseSharedChatSessionData): ...
588+
589+
569590
class ChannelSubscribeEvent(BroadcasterUserEvent):
570591
tier: Literal["1000", "2000", "3000"]
571592
is_gift: bool

0 commit comments

Comments
 (0)