Skip to content

Commit

Permalink
Add force kwarg to Client.delete_websocket_subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Feb 20, 2025
1 parent 9e3f8d7 commit 54e32c7
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions twitchio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,7 @@ def websocket_subscriptions(self) -> dict[str, WebsocketSubscriptionData]:

return ret

async def delete_websocket_subscription(self, id: str) -> WebsocketSubscriptionData:
async def delete_websocket_subscription(self, id: str, *, force: bool = False) -> WebsocketSubscriptionData:
"""|coro|
Delete an EventSub subsctiption with a Websocket Transport.
Expand All @@ -2441,6 +2441,12 @@ async def delete_websocket_subscription(self, id: str) -> WebsocketSubscriptionD
----------
id: str
The Eventsub subscription ID. You can view currently active subscriptions via :meth:`.websocket_subscriptions`.
force: bool
When set to ``True``, the subscription will be forcefully removed from the Client,
regardless of any HTTPException's raised during the call to Twitch.
When set to ``False``, if an exception is raised, the subscription will remain on the Client websocket.
Defaults to ``False``.
Returns
-------
Expand All @@ -2461,10 +2467,15 @@ async def delete_websocket_subscription(self, id: str) -> WebsocketSubscriptionD
if not sub:
continue

await self._http.delete_eventsub_subscription(id, token_for=token_for)
socket._subscriptions.pop(id, None)
try:
await self._http.delete_eventsub_subscription(id, token_for=token_for)
except HTTPException as e:
if not force:
raise e

socket._subscriptions.pop(id, None)
data = WebsocketSubscriptionData(sub)

if not socket._subscriptions and not socket._closing and not socket._closed:
logger.info("Closing websocket '%s' due to no remaining subscriptions.", socket)
await socket.close()
Expand Down

0 comments on commit 54e32c7

Please sign in to comment.