Skip to content

Commit 4260533

Browse files
authored
Add support for type and user_id queries on get_subscriptions (#381)
* Add support for type and user_id on get_subscriptions * Add changelog entry. * Fix changelog formatting. * Address review
1 parent 3ec209f commit 4260533

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Master
3535
- :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_channel_shoutout_create`
3636
- :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_channel_shoutout_receive`
3737
- Added :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_channel_follows_v2`
38+
- Added support for ``type`` and ``user_id`` queries on :func:`~twitchio.ext.eventsub.EventSubClient.get_subscriptions`
3839

3940
- Deprecations
4041
- :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_channel_follows`, use :func:`~twitchio.ext.eventsub.EventSubClient.subscribe_channel_follows_v2`

twitchio/ext/eventsub/http.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@ async def delete_subscription(self, subscription: Union[str, Subscription]):
3636
Route("DELETE", "eventsub/subscriptions", query=[("id", subscription)]), paginate=False
3737
)
3838

39-
async def get_subscriptions(self, status: str = None):
39+
async def get_subscriptions(
40+
self, status: Optional[str] = None, sub_type: Optional[str] = None, user_id: Optional[int] = None
41+
):
4042
qs = []
4143
if status:
4244
qs.append(("status", status))
45+
if sub_type:
46+
qs.append(("type", sub_type))
47+
if user_id:
48+
qs.append(("user_id", str(user_id)))
49+
if len(qs) > 1:
50+
raise ValueError("You cannot specify more than one filter.")
4351

4452
return [
4553
models.Subscription(d)

twitchio/ext/eventsub/server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ async def delete_all_active_subscriptions(self):
5353
for subscription_id in active_subscriptions:
5454
await self.delete_subscription(subscription_id)
5555

56-
async def get_subscriptions(self, status: str = None):
56+
async def get_subscriptions(
57+
self, status: Optional[str] = None, sub_type: Optional[str] = None, user_id: Optional[int] = None
58+
):
5759
# All possible statuses are:
5860
#
5961
# enabled: designates that the subscription is in an operable state and is valid.
@@ -62,7 +64,7 @@ async def get_subscriptions(self, status: str = None):
6264
# notification_failures_exceeded: notification delivery failure rate was too high.
6365
# authorization_revoked: authorization for user(s) in the condition was revoked.
6466
# user_removed: a user in the condition of the subscription was removed.
65-
return await self._http.get_subscriptions(status)
67+
return await self._http.get_subscriptions(status, sub_type, user_id)
6668

6769
async def subscribe_user_updated(self, user: Union[PartialUser, str, int]):
6870
if isinstance(user, PartialUser):

0 commit comments

Comments
 (0)