From cd5ae6388a430178cdef7ab672eb3a6dc8d4ef72 Mon Sep 17 00:00:00 2001 From: Wolfhound905 Date: Mon, 12 Feb 2024 07:56:09 +0000 Subject: [PATCH 1/2] feat: ability to define which shards connect --- interactions/client/auto_shard_client.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/interactions/client/auto_shard_client.py b/interactions/client/auto_shard_client.py index 935ccaa1f..a7e6af898 100644 --- a/interactions/client/auto_shard_client.py +++ b/interactions/client/auto_shard_client.py @@ -2,7 +2,7 @@ import time from datetime import datetime from collections import defaultdict -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, List import interactions.api.events as events from interactions.api.events import ShardConnect @@ -35,6 +35,8 @@ def __init__(self, *args, **kwargs) -> None: self.auto_sharding = "total_shards" not in kwargs super().__init__(*args, **kwargs) + self.only_shards: Optional[List[int]] = kwargs.get("only_shards", None) + self._connection_state = None self._connection_states: list[ConnectionState] = [] @@ -244,9 +246,13 @@ async def login(self, token: str | None = None) -> None: ) self.logger.debug(f"Starting bot with {self.total_shards} shard{'s' if self.total_shards != 1 else ''}") - self._connection_states: list[ConnectionState] = [ - ConnectionState(self, self.intents, shard_id) for shard_id in range(self.total_shards) - ] + + if self.only_shards: + self._connection_states = [ConnectionState(self, self.intents, shard_id) for shard_id in self.only_shards] + else: + self._connection_states = [ + ConnectionState(self, self.intents, shard_id) for shard_id in range(self.total_shards) + ] async def change_presence( self, From f096c156dd8a1f81fd42fa8fecd34fa9332939e8 Mon Sep 17 00:00:00 2001 From: Wolfhound905 Date: Wed, 21 Feb 2024 05:22:57 +0000 Subject: [PATCH 2/2] refactor: AutoShardedClient's only_shards to shard_ids --- interactions/client/auto_shard_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interactions/client/auto_shard_client.py b/interactions/client/auto_shard_client.py index a7e6af898..8eab52ba5 100644 --- a/interactions/client/auto_shard_client.py +++ b/interactions/client/auto_shard_client.py @@ -35,7 +35,7 @@ def __init__(self, *args, **kwargs) -> None: self.auto_sharding = "total_shards" not in kwargs super().__init__(*args, **kwargs) - self.only_shards: Optional[List[int]] = kwargs.get("only_shards", None) + self.shard_ids: Optional[List[int]] = kwargs.get("shard_ids", None) self._connection_state = None @@ -247,8 +247,8 @@ async def login(self, token: str | None = None) -> None: self.logger.debug(f"Starting bot with {self.total_shards} shard{'s' if self.total_shards != 1 else ''}") - if self.only_shards: - self._connection_states = [ConnectionState(self, self.intents, shard_id) for shard_id in self.only_shards] + if self.shard_ids: + self._connection_states = [ConnectionState(self, self.intents, shard_id) for shard_id in self.shard_ids] else: self._connection_states = [ ConnectionState(self, self.intents, shard_id) for shard_id in range(self.total_shards)