Skip to content

Commit f877219

Browse files
authored
Merge pull request #343 from jbot-the-dev/events
Added missing events
2 parents ffa8346 + e00c403 commit f877219

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ Master
5353
- :func:`~twitchio.ext.eventsub.event_eventsub_notification_channel_goal_begin`
5454
- :func:`~twitchio.ext.eventsub.event_eventsub_notification_channel_goal_progress`
5555
- :func:`~twitchio.ext.eventsub.event_eventsub_notification_channel_goal_end`
56+
57+
- Channel subscription end
58+
- :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_channel_subscription_end`
59+
- User authorization grant
60+
- :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_user_authorization_granted`
61+
5662
- HypeTrainBeginProgressData now has the :attr:`~twitchio.ext.eventsub.HypeTrainBeginProgressData.level`
5763

64+
5865
- Bug fixes
5966
Correct typo in :class:`~twitchio.ext.eventsub.HypeTrainBeginProgressData` attribute :attr:`~twitchio.ext.eventsub.HypeTrainBeginProgressData.expires`
6067

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
@@ -1145,6 +1170,25 @@ def __init__(self, client: EventSubClient, data: dict):
11451170
self.broadcaster = _transform_user(client, data, "broadcaster_user")
11461171

11471172

1173+
class UserAuthorizationGrantedData(EventData):
1174+
"""
1175+
An Authorization Granted event
1176+
1177+
Attributes
1178+
-----------
1179+
user: :class:`twitchio.PartialUser`
1180+
The user that has granted authorization for your app
1181+
client_id: :class:`str`
1182+
The client id of the app that had its authorization granted
1183+
"""
1184+
1185+
__slots__ = "client_id", "user"
1186+
1187+
def __init__(self, client: EventSubClient, data: dict):
1188+
self.user = _transform_user(client, data, "user")
1189+
self.client_id: str = data["client_id"]
1190+
1191+
11481192
class UserAuthorizationRevokedData(EventData):
11491193
"""
11501194
An Authorization Revokation event
@@ -1274,6 +1318,7 @@ def __init__(self, client: EventSubClient, data: dict):
12741318
ChannelBanData,
12751319
ChannelUnbanData,
12761320
ChannelSubscribeData,
1321+
ChannelSubscriptionEndData,
12771322
ChannelSubscriptionGiftData,
12781323
ChannelSubscriptionMessageData,
12791324
ChannelCheerData,
@@ -1294,6 +1339,7 @@ def __init__(self, client: EventSubClient, data: dict):
12941339
PredictionEndData,
12951340
StreamOnlineData,
12961341
StreamOfflineData,
1342+
UserAuthorizationGrantedData,
12971343
UserAuthorizationRevokedData,
12981344
UserUpdateData,
12991345
]
@@ -1312,6 +1358,7 @@ class _SubscriptionTypes(metaclass=_SubTypesMeta):
13121358

13131359
follow = "channel.follow", 1, ChannelFollowData
13141360
subscription = "channel.subscribe", 1, ChannelSubscribeData
1361+
subscription_end = "channel.subscription.end", 1, ChannelSubscriptionEndData
13151362
subscription_gift = "channel.subscription.gift", 1, ChannelSubscriptionGiftData
13161363
subscription_message = "channel.subscription.message", 1, ChannelSubscriptionMessageData
13171364
cheer = "channel.cheer", 1, ChannelCheerData
@@ -1356,6 +1403,7 @@ class _SubscriptionTypes(metaclass=_SubTypesMeta):
13561403
stream_start = "stream.online", 1, StreamOnlineData
13571404
stream_end = "stream.offline", 1, StreamOfflineData
13581405

1406+
user_authorization_grant = "user.authorization.grant", 1, UserAuthorizationGrantedData
13591407
user_authorization_revoke = "user.authorization.revoke", 1, UserAuthorizationRevokedData
13601408

13611409
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)