Skip to content

Commit a08e5e7

Browse files
committed
Add force_subscribe option to AutoClient/Bot
1 parent 4e8ac79 commit a08e5e7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

twitchio/client.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,12 +3200,16 @@ async def main() -> None:
32003200
simply: ``len(subscriptons) / max_per_shard`` or ``2`` whichever is greater. Note this parameter has no effect when
32013201
``shard_ids`` is explicitly passed.
32023202
subscriptions: list[twitchio.eventsub.SubscriptionPayload]
3203-
A list of any combination of EventSub subscriptions (all of which inherit from
3203+
An optional list of any combination of EventSub subscriptions (all of which inherit from
32043204
:class:`~twitchio.eventsub.SubscriptionPayload`) the Client should attempt to subscribe to when required. The
32053205
:class:`~twitchio.AutoClient` will only attempt to subscribe to these subscriptions when it creates a new Conduit. If
32063206
your Client connects to an existing Conduit either by passing ``conduit_id`` or automatically, this parameter has no
32073207
effect. In cases where you need to update an existing Conduit with new subscriptions see:
3208-
:meth:`~twitchio.AutoClient.multi_subscribe`.
3208+
:meth:`~twitchio.AutoClient.multi_subscribe` or the parameter ``force_subscribe``.
3209+
force_subscribe: bool
3210+
An optional :class:`bool` which when ``True`` will force attempt to subscribe to the subscriptions provided in the
3211+
``subscriptions`` parameter, regardless of whether a new conduit was created or not. Defaults to ``False``.
3212+
32093213
"""
32103214

32113215
# NOTE:
@@ -3225,6 +3229,8 @@ def __init__(
32253229
) -> None:
32263230
self._shard_ids: list[int] = kwargs.pop("shard_ids", [])
32273231
self._conduit_id: str | bool | None = kwargs.pop("conduit_id", MISSING)
3232+
self._force_sub: bool = kwargs.pop("force_subscribe", False)
3233+
self._subbed: bool = False
32283234

32293235
if self._conduit_id is MISSING or self._conduit_id is None:
32303236
logger.warning(
@@ -3353,6 +3359,9 @@ async def _setup(self) -> None:
33533359
raise MissingConduit("No conduit could be found with the provided ID or a new one can not be created.")
33543360

33553361
await self._associate_shards(self._shard_ids)
3362+
if self._force_sub and not self._subbed:
3363+
await self.multi_subscribe(self._initial_subs)
3364+
33563365
await self.setup_hook()
33573366

33583367
self._setup_called = True
@@ -3484,6 +3493,7 @@ async def _generate_new_conduit(self) -> Conduit:
34843493
if self._initial_subs:
34853494
logger.info("Attempting to do an initial subscription on new conduit: %r.", self._conduit_info)
34863495
await self._multi_sub(self._initial_subs, stop_on_error=False)
3496+
self._subbed = True
34873497

34883498
return new
34893499

twitchio/types_/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AutoClientOptions(ClientOptions, total=False):
5252
shard_ids: list[int]
5353
max_per_shard: int
5454
subscriptions: list[SubscriptionPayload]
55+
force_subscribe: bool
5556

5657

5758
WaitPredicateT = Callable[..., Coroutine[Any, Any, bool]]

0 commit comments

Comments
 (0)