Skip to content

Commit b46ba8d

Browse files
committed
Added missing events
Added channel subscription end and user authorization grant event types.
1 parent 307202c commit b46ba8d

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ Master
5151
- :func:`~twitchio.ext.eventsub.event_eventsub_notification_channel_goal_begin`
5252
- :func:`~twitchio.ext.eventsub.event_eventsub_notification_channel_goal_progress`
5353
- :func:`~twitchio.ext.eventsub.event_eventsub_notification_channel_goal_end`
54+
- Channel subscription end
55+
- :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_channel_subscription_end`
56+
- User authorization grant
57+
- :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_user_authorization_granted`
5458

5559
- Bug fixes
5660
Correct typo in :class:`~twitchio.ext.eventsub.HypeTrainBeginProgressData` attribute :attr:`~twitchio.ext.eventsub.HypeTrainBeginProgressData.expires`

docs/exts/eventsub.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Event Reference
8989
----------------
9090
This is a list of events dispatched by the eventsub ext.
9191

92+
.. function:: event_eventsub_notification_user_authorization_grant(event: UserAuthorizationGrantedData)
93+
94+
Called when your app has had access granted on a channel.
95+
9296
.. function:: event_eventsub_revokation(event: RevokationEvent)
9397

9498
Called when your app has had access revoked on a channel.
@@ -108,6 +112,10 @@ This is a list of events dispatched by the eventsub ext.
108112

109113
Called when someone subscribes to a channel that you've subscribed to.
110114

115+
.. function:: event_eventsub_notification_subscription_end(event: ChannelSubscriptionEndData)
116+
117+
Called when a subscription to a channel that you've subscribed to ends.
118+
111119
.. function:: event_eventsub_notification_subscription_gift(event: ChannelSubscriptionGiftData)
112120

113121
Called when someone gifts a subscription to a channel that you've subscribed to.

twitchio/ext/eventsub/models.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,31 @@ def __init__(self, client: EventSubClient, data: dict):
238238
self.is_gift: bool = data["is_gift"]
239239

240240

241+
class ChannelSubscriptionEndData(EventData):
242+
"""
243+
A Subscription End event
244+
245+
Attributes
246+
-----------
247+
user: :class:`twitchio.PartialUser`
248+
The user who subscribed
249+
broadcaster: :class:`twitchio.PartialUser`
250+
The channel that was subscribed to
251+
tier: :class:`int`
252+
The tier of the subscription
253+
is_gift: :class:`bool`
254+
Whether the subscription was a gift or not
255+
"""
256+
257+
__slots__ = "user", "broadcaster", "tier", "is_gift"
258+
259+
def __init__(self, client: EventSubClient, data: dict):
260+
self.user = _transform_user(client, data, "user")
261+
self.broadcaster = _transform_user(client, data, "broadcaster_user")
262+
self.tier = int(data["tier"])
263+
self.is_gift: bool = data["is_gift"]
264+
265+
241266
class ChannelSubscriptionGiftData(EventData):
242267
"""
243268
A Subscription Gift event
@@ -1141,6 +1166,25 @@ def __init__(self, client: EventSubClient, data: dict):
11411166
self.broadcaster = _transform_user(client, data, "broadcaster_user")
11421167

11431168

1169+
class UserAuthorizationGrantedData(EventData):
1170+
"""
1171+
An Authorization Granted event
1172+
1173+
Attributes
1174+
-----------
1175+
user: :class:`twitchio.PartialUser`
1176+
The user that has granted authorization for your app
1177+
client_id: :class:`str`
1178+
The client id of the app that had its authorization granted
1179+
"""
1180+
1181+
__slots__ = "client_id", "user"
1182+
1183+
def __init__(self, client: EventSubClient, data: dict):
1184+
self.user = _transform_user(client, data, "user")
1185+
self.client_id: str = data["client_id"]
1186+
1187+
11441188
class UserAuthorizationRevokedData(EventData):
11451189
"""
11461190
An Authorization Revokation event
@@ -1270,6 +1314,7 @@ def __init__(self, client: EventSubClient, data: dict):
12701314
ChannelBanData,
12711315
ChannelUnbanData,
12721316
ChannelSubscribeData,
1317+
ChannelSubscriptionEndData,
12731318
ChannelSubscriptionGiftData,
12741319
ChannelSubscriptionMessageData,
12751320
ChannelCheerData,
@@ -1290,6 +1335,7 @@ def __init__(self, client: EventSubClient, data: dict):
12901335
PredictionEndData,
12911336
StreamOnlineData,
12921337
StreamOfflineData,
1338+
UserAuthorizationGrantedData,
12931339
UserAuthorizationRevokedData,
12941340
UserUpdateData,
12951341
]
@@ -1308,6 +1354,7 @@ class _SubscriptionTypes(metaclass=_SubTypesMeta):
13081354

13091355
follow = "channel.follow", 1, ChannelFollowData
13101356
subscription = "channel.subscribe", 1, ChannelSubscribeData
1357+
subscription_end = "channel.subscription.end", 1, ChannelSubscriptionEndData
13111358
subscription_gift = "channel.subscription.gift", 1, ChannelSubscriptionGiftData
13121359
subscription_message = "channel.subscription.message", 1, ChannelSubscriptionMessageData
13131360
cheer = "channel.cheer", 1, ChannelCheerData
@@ -1352,6 +1399,7 @@ class _SubscriptionTypes(metaclass=_SubTypesMeta):
13521399
stream_start = "stream.online", 1, StreamOnlineData
13531400
stream_end = "stream.offline", 1, StreamOfflineData
13541401

1402+
user_authorization_grant = "user.authorization.grant", 1, UserAuthorizationGrantedData
13551403
user_authorization_revoke = "user.authorization.revoke", 1, UserAuthorizationRevokedData
13561404

13571405
user_update = "user.update", 1, UserUpdateData

twitchio/ext/eventsub/server.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def subscribe_channel_unbans(self, broadcaster: Union[PartialUser, str, int]):
120120
def subscribe_channel_subscriptions(self, broadcaster: Union[PartialUser, str, int]):
121121
return self._subscribe_with_broadcaster(models.SubscriptionTypes.subscription, broadcaster)
122122

123+
def subscribe_channel_subscription_end(self, broadcaster: Union[PartialUser, str, int]):
124+
return self._subscribe_with_broadcaster(models.SubscriptionTypes.subscription_end, broadcaster)
125+
123126
def subscribe_channel_subscription_gifts(self, broadcaster: Union[PartialUser, str, int]):
124127
return self._subscribe_with_broadcaster(models.SubscriptionTypes.subscription_gift, broadcaster)
125128

@@ -211,6 +214,11 @@ def subscribe_channel_prediction_lock(self, broadcaster: Union[PartialUser, str,
211214
def subscribe_channel_prediction_end(self, broadcaster: Union[PartialUser, str, int]):
212215
return self._subscribe_with_broadcaster(models.SubscriptionTypes.prediction_end, broadcaster)
213216

217+
async def subscribe_user_authorization_granted(self):
218+
return await self._http.create_subscription(
219+
models.SubscriptionTypes.user_authorization_grant, {"client_id": self.client._http.client_id}
220+
)
221+
214222
async def subscribe_user_authorization_revoked(self):
215223
return await self._http.create_subscription(
216224
models.SubscriptionTypes.user_authorization_revoke, {"client_id": self.client._http.client_id}

0 commit comments

Comments
 (0)