Skip to content

Commit 62f03ad

Browse files
committed
Merge branch 'master' of https://github.com/TwitchIO/TwitchIO
2 parents dc634c1 + c23f726 commit 62f03ad

File tree

5 files changed

+87
-9
lines changed

5 files changed

+87
-9
lines changed

docs/changelog.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Master
3131
- ext.commands
3232
- Bug fixes
3333
- Make sure double-quotes are properly tokenized for bot commands
34-
34+
3535
- ext.pubsub
3636
- Additions
3737
- Websocket automatically handles "RECONNECT" requests by Twitch
38-
- Bug fixes
38+
- Bug fixes
3939
- Unsubscribing from Pubsubevents works again
4040
- Fix a forgotten nonce in :func:`~twitchio.ext.pubsub.websocket._send_topics`
4141
- :class:`~twitchio.ext.pubsub.PubSubModerationActionChannelTerms` now uses the correct type data
@@ -53,10 +53,25 @@ 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
59-
Correct typo in :class:`~twitchio.ext.eventsub.HypeTrainBeginProgressData` attribute :attr:`~twitchio.ext.eventsub.HypeTrainBeginProgressData.expires`
66+
- Correct typo in :class:`~twitchio.ext.eventsub.HypeTrainBeginProgressData` attribute :attr:`~twitchio.ext.eventsub.HypeTrainBeginProgressData.expires`
67+
- Correct typo "revokation" to "revocation" in server _message_types.
68+
69+
- ext.pubsub
70+
- Bug fixes
71+
- "type" of :class:`~twitchio.ext.pubsub.PubSubModerationActionChannelTerms` now uses the correct type data
72+
73+
- Correct typo in :class:`~twitchio.ext.eventsub.HypeTrainBeginProgressData` attribute :attr:`~twitchio.ext.eventsub.HypeTrainBeginProgressData.expires`
74+
6075

6176
2.4.0
6277
======

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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
_message_types = {
2323
"webhook_callback_verification": models.ChallengeEvent,
2424
"notification": models.NotificationEvent,
25-
"revokation": models.RevokationEvent,
25+
"revocation": models.RevokationEvent,
2626
}
2727

2828

@@ -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}
@@ -234,7 +242,7 @@ async def _callback(self, request: web.Request) -> web.Response:
234242
self.client.run_event(
235243
f"eventsub_notification_{models.SubscriptionTypes._name_map[event.subscription.type]}", event
236244
)
237-
elif typ == "revokation":
245+
elif typ == "revocation":
238246
self.client.run_event("eventsub_revokation", event)
239247

240248
return response

twitchio/websocket.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ async def _connect(self):
142142

143143
await asyncio.sleep(retry)
144144
return asyncio.create_task(self._connect())
145-
if time.time() > self._last_ping + 240 or self._reconnect_requested:
146-
# Re-authenticate as we have surpassed a PING request or Twitch issued a RECONNECT.
147-
await self.authenticate(self._initial_channels)
148-
self._reconnect_requested = False
145+
146+
await self.authenticate(self._initial_channels)
147+
149148
self._keeper = asyncio.create_task(self._keep_alive()) # Create our keep alive.
150149
self._ws_ready_event.set()
151150

0 commit comments

Comments
 (0)