From 5568ca9e6566d302b2c3ae9d4ec68f91777ffce4 Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Wed, 19 Oct 2022 22:44:50 -0400 Subject: [PATCH 01/10] feat: add the ability to limit the length of the cache --- interactions/api/cache.py | 24 ++++++++----- interactions/api/gateway/client.py | 7 ++-- interactions/api/http/channel.py | 8 +++-- interactions/api/http/client.py | 25 ++++---------- interactions/api/http/emoji.py | 9 ++--- interactions/api/http/guild.py | 9 ++--- interactions/api/http/interaction.py | 9 ++--- interactions/api/http/invite.py | 8 +++-- interactions/api/http/member.py | 9 ++--- interactions/api/http/message.py | 8 +++-- interactions/api/http/reaction.py | 9 ++--- interactions/api/http/scheduledEvent.py | 9 ++--- interactions/api/http/sticker.py | 9 ++--- interactions/api/http/thread.py | 8 +++-- interactions/client/bot.py | 34 +++++++++++++------ interactions/utils/__init__.py | 1 + interactions/utils/dict_caches.py | 45 +++++++++++++++++++++++++ 17 files changed, 153 insertions(+), 78 deletions(-) create mode 100644 interactions/utils/dict_caches.py diff --git a/interactions/api/cache.py b/interactions/api/cache.py index c4218fbd2..42ab5a615 100644 --- a/interactions/api/cache.py +++ b/interactions/api/cache.py @@ -12,6 +12,8 @@ overload, ) +import interactions + if TYPE_CHECKING: from .models import Snowflake @@ -38,8 +40,13 @@ class Storage(Generic[_T]): def __repr__(self) -> str: return f"<{self.__class__.__name__} object containing {len(self.values)} items.>" - def __init__(self) -> None: - self.values: Dict["Key", _T] = {} + def __init__(self, limit: Optional[int] = float("inf")) -> None: + """ + + :param limit: The maximum number of items to store + :type limit: Optional[int] + """ + self.values: interactions.LRUDict["Key", _T] = interactions.LRUDict(max_items=limit) def merge(self, item: _T, id: Optional["Key"] = None) -> None: """ @@ -158,13 +165,14 @@ class Cache: :ivar defaultdict[Type, Storage] storages: A dictionary denoting the Type and the objects that correspond to the Type. """ - __slots__ = "storages" + __slots__ = ("storages", "config") - def __init__(self) -> None: - self.storages: defaultdict[Type[_T], Storage[_T]] = defaultdict(Storage) + def __init__(self, config: Dict[Type[_T], int] = None) -> None: + self.storages: Dict[Type[_T], Storage[_T]] = defaultdict(Storage) + + if config is not None: + for type_, limit in config.items(): + self.storages[type_] = Storage(limit) def __getitem__(self, item: Type[_T]) -> Storage[_T]: return self.storages[item] - - -ref_cache = Cache() # noqa diff --git a/interactions/api/gateway/client.py b/interactions/api/gateway/client.py index e4a6eb84f..30e7c2c1a 100644 --- a/interactions/api/gateway/client.py +++ b/interactions/api/gateway/client.py @@ -44,7 +44,7 @@ if TYPE_CHECKING: from ...client.context import _Context - from ..cache import Storage + from ..cache import Cache, Storage from ..models.gw import GuildMembers log = get_logger("gateway") @@ -93,6 +93,7 @@ class WebSocketClient: "_ratelimiter", "_http", "_client", + "_cache", "__closed", # placeholder to work with variables atm. its event variant of "_closed" "_options", "_intents", @@ -120,6 +121,7 @@ def __init__( self, token: str, intents: Intents, + cache: "Cache", session_id: Optional[str] = MISSING, sequence: Optional[int] = MISSING, shards: Optional[List[Tuple[int]]] = MISSING, @@ -152,6 +154,7 @@ def __init__( loop=self._loop if version_info < (3, 10) else None ) self._http: HTTPClient = token + self._cache: "Cache" = cache self._client: Optional["ClientWebSocketResponse"] = None @@ -243,7 +246,7 @@ async def run(self) -> None: """ if isinstance(self._http, str): - self._http = HTTPClient(self._http) + self._http = HTTPClient(self._http, self._cache) url = await self._http.get_gateway() self.ws_url = url diff --git a/interactions/api/http/channel.py b/interactions/api/http/channel.py index 7335be2f9..015914e54 100644 --- a/interactions/api/http/channel.py +++ b/interactions/api/http/channel.py @@ -1,6 +1,5 @@ -from typing import Dict, List, Optional, Union +from typing import TYPE_CHECKING, Dict, List, Optional, Union -from ...api.cache import Cache from ..error import LibraryException from ..models.channel import Channel from ..models.message import Message @@ -8,12 +7,15 @@ from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("ChannelRequest",) class ChannelRequest: _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/client.py b/interactions/api/http/client.py index 557968876..6b4cd3406 100644 --- a/interactions/api/http/client.py +++ b/interactions/api/http/client.py @@ -1,6 +1,5 @@ -from typing import Any, Optional, Tuple +from typing import TYPE_CHECKING, Any, Optional, Tuple -from ...api.cache import Cache, ref_cache from .channel import ChannelRequest from .emoji import EmojiRequest from .guild import GuildRequest @@ -17,6 +16,9 @@ from .user import UserRequest from .webhook import WebhookRequest +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("HTTPClient",) @@ -51,25 +53,12 @@ class HTTPClient( token: str _req: _Request - cache: Cache + cache: "Cache" - def __init__(self, token: str): + def __init__(self, token: str, cache: "Cache"): # noqa skip the no super imports self.token = token self._req = _Request(self.token) - self.cache = ref_cache - UserRequest.__init__(self) - MessageRequest.__init__(self) - GuildRequest.__init__(self) - ChannelRequest.__init__(self) - InviteRequest.__init__(self) - ThreadRequest.__init__(self) - ReactionRequest.__init__(self) - StickerRequest.__init__(self) - InteractionRequest.__init__(self) - WebhookRequest.__init__(self) - ScheduledEventRequest.__init__(self) - EmojiRequest.__init__(self) - MemberRequest.__init__(self) + self.cache = cache # An ideology is that this client does every single HTTP call, which reduces multiple ClientSessions in theory # because of how they are constructed/closed. This includes Gateway diff --git a/interactions/api/http/emoji.py b/interactions/api/http/emoji.py index 89cb41274..c6db1a575 100644 --- a/interactions/api/http/emoji.py +++ b/interactions/api/http/emoji.py @@ -1,19 +1,20 @@ -from typing import List, Optional +from typing import TYPE_CHECKING, List, Optional -from ...api.cache import Cache from ..models.emoji import Emoji from ..models.guild import Guild from ..models.misc import Snowflake from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("EmojiRequest",) class EmojiRequest: - _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/guild.py b/interactions/api/http/guild.py index a288bd367..73ccc8151 100644 --- a/interactions/api/http/guild.py +++ b/interactions/api/http/guild.py @@ -1,20 +1,21 @@ -from typing import Any, Dict, List, Optional +from typing import TYPE_CHECKING, Any, Dict, List, Optional from urllib.parse import quote -from ...api.cache import Cache from ..models.channel import Channel from ..models.guild import Guild from ..models.role import Role from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("GuildRequest",) class GuildRequest: - _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/interaction.py b/interactions/api/http/interaction.py index a005a5d89..56c1905a0 100644 --- a/interactions/api/http/interaction.py +++ b/interactions/api/http/interaction.py @@ -1,17 +1,18 @@ -from typing import List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union -from ...api.cache import Cache from ..models import Snowflake from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("InteractionRequest",) class InteractionRequest: - _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/invite.py b/interactions/api/http/invite.py index f2800f64d..99c4de606 100644 --- a/interactions/api/http/invite.py +++ b/interactions/api/http/invite.py @@ -1,15 +1,17 @@ -from typing import Optional +from typing import TYPE_CHECKING, Optional -from ...api.cache import Cache from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("InviteRequest",) class InviteRequest: _req = _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/member.py b/interactions/api/http/member.py index 49ed9026e..2cc14b5f4 100644 --- a/interactions/api/http/member.py +++ b/interactions/api/http/member.py @@ -1,19 +1,20 @@ -from typing import List, Optional +from typing import TYPE_CHECKING, List, Optional -from ...api.cache import Cache from ..models.guild import Guild from ..models.member import Member from ..models.misc import Snowflake from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("MemberRequest",) class MemberRequest: - _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/message.py b/interactions/api/http/message.py index 30f4abaae..a86e3ce11 100644 --- a/interactions/api/http/message.py +++ b/interactions/api/http/message.py @@ -1,20 +1,22 @@ -from typing import List, Optional, Union +from typing import TYPE_CHECKING, List, Optional, Union from aiohttp import MultipartWriter -from ...api.cache import Cache from ...utils.missing import MISSING from ..models.message import Embed, Message, Sticker from ..models.misc import AllowedMentions, File, Snowflake from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("MessageRequest",) class MessageRequest: _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/reaction.py b/interactions/api/http/reaction.py index cd68e2b09..92acfc70c 100644 --- a/interactions/api/http/reaction.py +++ b/interactions/api/http/reaction.py @@ -1,16 +1,17 @@ -from typing import List +from typing import TYPE_CHECKING, List -from ...api.cache import Cache from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("ReactionRequest",) class ReactionRequest: - _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/scheduledEvent.py b/interactions/api/http/scheduledEvent.py index 2258474ba..537d732ad 100644 --- a/interactions/api/http/scheduledEvent.py +++ b/interactions/api/http/scheduledEvent.py @@ -1,16 +1,17 @@ -from typing import List +from typing import TYPE_CHECKING, List -from ...api.cache import Cache from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("ScheduledEventRequest",) class ScheduledEventRequest: - _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/sticker.py b/interactions/api/http/sticker.py index c1c013fc9..c16a6afb3 100644 --- a/interactions/api/http/sticker.py +++ b/interactions/api/http/sticker.py @@ -1,19 +1,20 @@ -from typing import List, Optional +from typing import TYPE_CHECKING, List, Optional from aiohttp import FormData -from ...api.cache import Cache from ..models.misc import File from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("StickerRequest",) class StickerRequest: - _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/api/http/thread.py b/interactions/api/http/thread.py index 42cbadfbf..6ae7e8cc9 100644 --- a/interactions/api/http/thread.py +++ b/interactions/api/http/thread.py @@ -1,20 +1,22 @@ -from typing import Dict, List, Optional +from typing import TYPE_CHECKING, Dict, List, Optional from aiohttp import MultipartWriter -from ...api.cache import Cache from ...utils.missing import MISSING from ..models.channel import Channel from ..models.misc import File from .request import _Request from .route import Route +if TYPE_CHECKING: + from ...api.cache import Cache + __all__ = ("ThreadRequest",) class ThreadRequest: _req: _Request - cache: Cache + cache: "Cache" def __init__(self) -> None: pass diff --git a/interactions/client/bot.py b/interactions/client/bot.py index 480ba068e..27962b685 100644 --- a/interactions/client/bot.py +++ b/interactions/client/bot.py @@ -11,6 +11,7 @@ from typing import Any, Callable, Coroutine, Dict, List, Optional, Tuple, Union from ..api import WebSocketClient as WSClient +from ..api.cache import Cache from ..api.error import LibraryException from ..api.http.client import HTTPClient from ..api.models.flags import Intents, Permissions @@ -75,21 +76,33 @@ class Client: def __init__( self, token: str, + cache_limits: Optional[Dict[type, int]] = None, + intents: Intents = Intents.DEFAULT, + shards: Optional[List[Tuple[int]]] = None, + default_scope=None, # todo typehint + presence: Optional[ClientPresence] = None, + _logging: Union[bool, int] = None, + disable_sync: bool = False, **kwargs, ) -> None: self._loop: AbstractEventLoop = get_event_loop() - self._http: HTTPClient = token - self._intents: Intents = kwargs.get("intents", Intents.DEFAULT) - self._shards: List[Tuple[int]] = kwargs.get("shards", []) + self._http: HTTPClient = token # noqa + self._cache: Cache = Cache(cache_limits) + self._intents: Intents = intents + self._shards: List[Tuple[int]] = shards or [] self._commands: List[Command] = [] - self._default_scope = kwargs.get("default_scope") - self._presence = kwargs.get("presence") + self._default_scope = default_scope + self._presence = presence self._websocket: WSClient = WSClient( - token=token, intents=self._intents, shards=self._shards, presence=self._presence + token=token, + cache=self._cache, + intents=self._intents, + shards=self._shards, + presence=self._presence, ) self._token = token self._extensions = {} - self._scopes = set([]) + self._scopes = set() self.__command_coroutines = [] self.__global_commands = {} self.__guild_commands = {} @@ -106,7 +119,8 @@ def __init__( ] self._default_scope = convert_list(int)(self._default_scope) - if _logging := kwargs.get("logging"): + _logging = kwargs.get("logging", _logging) + if _logging: # thx i0 for posting this on the retux Discord @@ -121,7 +135,7 @@ def __init__( logging.basicConfig(format=_format, level=_logging) - if kwargs.get("disable_sync"): + if disable_sync: self._automate_sync = False log.warning( "Automatic synchronization has been disabled. Interactions may need to be manually synchronized." @@ -372,7 +386,7 @@ async def _ready(self) -> None: ready: bool = False if isinstance(self._http, str): - self._http = HTTPClient(self._http) + self._http = HTTPClient(self._http, self._cache) data = await self._http.get_current_bot_information() self.me = Application(**data, _client=self._http) diff --git a/interactions/utils/__init__.py b/interactions/utils/__init__.py index 6c2e0f853..0a8e6fd49 100644 --- a/interactions/utils/__init__.py +++ b/interactions/utils/__init__.py @@ -1,4 +1,5 @@ from .attrs_utils import * # noqa: F401 F403 +from .dict_caches import * # noqa: F401 F403 from .get import * # noqa: F401 F403 from .missing import * # noqa: F401 F403 from .utils import * # noqa: F401 F403 diff --git a/interactions/utils/dict_caches.py b/interactions/utils/dict_caches.py new file mode 100644 index 000000000..ca0f9471e --- /dev/null +++ b/interactions/utils/dict_caches.py @@ -0,0 +1,45 @@ +from collections import OrderedDict +from typing import Generic, TypeVar + +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + + +class FIFODict(OrderedDict, Generic[_KT, _VT]): + """A dictionary that removes the old keys if over the item limit""" + + def __init__(self, *args, max_items: int = float("inf"), **kwargs): + if max_items < 0: + raise RuntimeError("You cannot set max_items to negative numbers.") + + super().__init__(*args, **kwargs) + self._max_items = max_items + + def __setitem__(self, key: _KT, value: _VT): + super().__setitem__(key, value) + + # Prevent buildup over time + while len(self) > self._max_items: + del self[next(iter(self))] + + +class LRUDict(OrderedDict, Generic[_KT, _VT]): + """A dictionary that removes the value that was the least recently used if over the item limit""" + + def __init__(self, *args, max_items: int = float("inf"), **kwargs): + if max_items < 0: + raise RuntimeError("You cannot set max_items to negative numbers.") + + super().__init__(*args, **kwargs) + self._max_items = max_items + + def __getitem__(self, key: _KT) -> _VT: + self.move_to_end(key) + return super().__getitem__(key) + + def __setitem__(self, key: _KT, value: _VT): + super().__setitem__(key, value) + + # Prevent buildup over time + while len(self) > self._max_items: + del self[next(iter(self))] From b4b7556a2ab2d471b9450c07aa257615f1aa7073 Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Thu, 20 Oct 2022 21:54:11 -0400 Subject: [PATCH 02/10] refactor: add `__all__` to `dict_caches.py` --- interactions/utils/dict_caches.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interactions/utils/dict_caches.py b/interactions/utils/dict_caches.py index ca0f9471e..a88662c52 100644 --- a/interactions/utils/dict_caches.py +++ b/interactions/utils/dict_caches.py @@ -1,6 +1,8 @@ from collections import OrderedDict from typing import Generic, TypeVar +__all__ = ("FIFODict", "LRUDict") + _KT = TypeVar("_KT") _VT = TypeVar("_VT") From 6b1c42597b3bdce77ff751b9e330071b8656ce46 Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Thu, 27 Oct 2022 23:23:27 -0400 Subject: [PATCH 03/10] refactor: add a default limit to cached messages --- interactions/client/bot.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/interactions/client/bot.py b/interactions/client/bot.py index 27962b685..8e37d0567 100644 --- a/interactions/client/bot.py +++ b/interactions/client/bot.py @@ -16,6 +16,7 @@ from ..api.http.client import HTTPClient from ..api.models.flags import Intents, Permissions from ..api.models.guild import Guild +from ..api.models.message import Message from ..api.models.misc import Image, Snowflake from ..api.models.presence import ClientPresence from ..api.models.team import Application @@ -87,19 +88,11 @@ def __init__( ) -> None: self._loop: AbstractEventLoop = get_event_loop() self._http: HTTPClient = token # noqa - self._cache: Cache = Cache(cache_limits) self._intents: Intents = intents self._shards: List[Tuple[int]] = shards or [] self._commands: List[Command] = [] self._default_scope = default_scope self._presence = presence - self._websocket: WSClient = WSClient( - token=token, - cache=self._cache, - intents=self._intents, - shards=self._shards, - presence=self._presence, - ) self._token = token self._extensions = {} self._scopes = set() @@ -119,6 +112,21 @@ def __init__( ] self._default_scope = convert_list(int)(self._default_scope) + if cache_limits is None: + # Messages have the most explosive growth, but more limits can be added as needed + cache_limits = { + Message: 1000, # Most users won't need to cache many messages + } + + self._cache: Cache = Cache(cache_limits) + self._websocket: WSClient = WSClient( + token=token, + cache=self._cache, + intents=self._intents, + shards=self._shards, + presence=self._presence, + ) + _logging = kwargs.get("logging", _logging) if _logging: From 039f1202e1435015d8e6cbb8bd64131a59a31652 Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Thu, 27 Oct 2022 23:54:22 -0400 Subject: [PATCH 04/10] docs(typehints): clarify `default_scope` Co-authored-by: Toricane <73972068+Toricane@users.noreply.github.com> --- interactions/client/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/client/bot.py b/interactions/client/bot.py index 8e37d0567..38f964b4c 100644 --- a/interactions/client/bot.py +++ b/interactions/client/bot.py @@ -80,7 +80,7 @@ def __init__( cache_limits: Optional[Dict[type, int]] = None, intents: Intents = Intents.DEFAULT, shards: Optional[List[Tuple[int]]] = None, - default_scope=None, # todo typehint + default_scope: Union[int, Snowflake, List[int, Snowflake]] = None, presence: Optional[ClientPresence] = None, _logging: Union[bool, int] = None, disable_sync: bool = False, From e95ebfdbedaa69f6ec6aafb98814afca98747012 Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Fri, 28 Oct 2022 11:30:36 -0400 Subject: [PATCH 05/10] Update interactions/client/bot.py Co-authored-by: Toricane <73972068+Toricane@users.noreply.github.com> --- interactions/client/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/client/bot.py b/interactions/client/bot.py index 38f964b4c..9ab1339b3 100644 --- a/interactions/client/bot.py +++ b/interactions/client/bot.py @@ -80,7 +80,7 @@ def __init__( cache_limits: Optional[Dict[type, int]] = None, intents: Intents = Intents.DEFAULT, shards: Optional[List[Tuple[int]]] = None, - default_scope: Union[int, Snowflake, List[int, Snowflake]] = None, + default_scope: Union[int, Snowflake, List[Union[int, Snowflake]]] = None, presence: Optional[ClientPresence] = None, _logging: Union[bool, int] = None, disable_sync: bool = False, From b92f78d6826cca76a3bcb1106233c88bf91f206b Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:15:48 -0400 Subject: [PATCH 06/10] docs(docstrings): switch to the newer docstring style Co-authored-by: Max --- interactions/api/cache.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interactions/api/cache.py b/interactions/api/cache.py index 42ab5a615..ac6ad0793 100644 --- a/interactions/api/cache.py +++ b/interactions/api/cache.py @@ -43,8 +43,7 @@ def __repr__(self) -> str: def __init__(self, limit: Optional[int] = float("inf")) -> None: """ - :param limit: The maximum number of items to store - :type limit: Optional[int] + :param Optional[int] limit: The maximum number of items to store """ self.values: interactions.LRUDict["Key", _T] = interactions.LRUDict(max_items=limit) From eb61cf69c57a3f9fb87a2e2029d1d538067e3ebc Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:18:51 -0400 Subject: [PATCH 07/10] docs(docstrings/typehints): Update the _http's type --- interactions/client/bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interactions/client/bot.py b/interactions/client/bot.py index 9ab1339b3..2e6bed99f 100644 --- a/interactions/client/bot.py +++ b/interactions/client/bot.py @@ -64,7 +64,7 @@ class Client: :type logging?: Optional[Union[bool, logging.DEBUG, logging.INFO, logging.NOTSET, logging.WARNING, logging.ERROR, logging.CRITICAL]] :ivar AbstractEventLoop _loop: The asynchronous event loop of the client. - :ivar HTTPClient _http: The user-facing HTTP connection to the Web API, as its own separate client. + :ivar Union[str, HTTPClient] _http: The user-facing HTTP connection to the Web API, as its own separate client. :ivar WebSocketClient _websocket: An object-orientation of a websocket server connection to the Gateway. :ivar Intents _intents: The Gateway intents of the application. Defaults to ``Intents.DEFAULT``. :ivar Optional[List[Tuple[int]]] _shard: The list of bucketed shards for the application's connection. @@ -87,7 +87,7 @@ def __init__( **kwargs, ) -> None: self._loop: AbstractEventLoop = get_event_loop() - self._http: HTTPClient = token # noqa + self._http: Union[str, HTTPClient] = token self._intents: Intents = intents self._shards: List[Tuple[int]] = shards or [] self._commands: List[Command] = [] From bda4444b20cc4e04904b1b5cc06d7f047829a4c5 Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Tue, 1 Nov 2022 08:12:49 -0400 Subject: [PATCH 08/10] Update interactions/client/bot.py Co-authored-by: Toricane <73972068+Toricane@users.noreply.github.com> --- interactions/client/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/client/bot.py b/interactions/client/bot.py index 2e6bed99f..93a3fcf6c 100644 --- a/interactions/client/bot.py +++ b/interactions/client/bot.py @@ -80,7 +80,7 @@ def __init__( cache_limits: Optional[Dict[type, int]] = None, intents: Intents = Intents.DEFAULT, shards: Optional[List[Tuple[int]]] = None, - default_scope: Union[int, Snowflake, List[Union[int, Snowflake]]] = None, + default_scope: Optional[Union[int, Snowflake, List[Union[int, Snowflake]]]] = None, presence: Optional[ClientPresence] = None, _logging: Union[bool, int] = None, disable_sync: bool = False, From b113b540f441b59e5101c25425b8c37f982232a9 Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Tue, 1 Nov 2022 21:51:03 -0400 Subject: [PATCH 09/10] docs(docstrings): remove the line for toricane --- interactions/api/cache.py | 1 - 1 file changed, 1 deletion(-) diff --git a/interactions/api/cache.py b/interactions/api/cache.py index ac6ad0793..64cf1aeb1 100644 --- a/interactions/api/cache.py +++ b/interactions/api/cache.py @@ -42,7 +42,6 @@ def __repr__(self) -> str: def __init__(self, limit: Optional[int] = float("inf")) -> None: """ - :param Optional[int] limit: The maximum number of items to store """ self.values: interactions.LRUDict["Key", _T] = interactions.LRUDict(max_items=limit) From d4dbcad914933d9d88c71b58f1e934d44d193dc2 Mon Sep 17 00:00:00 2001 From: Catalyst4 <84055084+Catalyst4222@users.noreply.github.com> Date: Tue, 1 Nov 2022 22:04:17 -0400 Subject: [PATCH 10/10] Update interactions/api/cache.py Co-authored-by: Toricane <73972068+Toricane@users.noreply.github.com> --- interactions/api/cache.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interactions/api/cache.py b/interactions/api/cache.py index 64cf1aeb1..9de25a9f6 100644 --- a/interactions/api/cache.py +++ b/interactions/api/cache.py @@ -40,10 +40,12 @@ class Storage(Generic[_T]): def __repr__(self) -> str: return f"<{self.__class__.__name__} object containing {len(self.values)} items.>" - def __init__(self, limit: Optional[int] = float("inf")) -> None: + def __init__(self, limit: Optional[int] = None) -> None: """ :param Optional[int] limit: The maximum number of items to store """ + if not limit: + limit = float("inf") self.values: interactions.LRUDict["Key", _T] = interactions.LRUDict(max_items=limit) def merge(self, item: _T, id: Optional["Key"] = None) -> None: