Add Interaction.client property

This commit is contained in:
Rapptz
2022-03-01 08:03:12 -05:00
parent 6110fe5b1c
commit f435d160dd
5 changed files with 43 additions and 14 deletions

View File

@@ -30,7 +30,21 @@ import copy
import datetime
import itertools
import logging
from typing import Dict, Optional, TYPE_CHECKING, Union, Callable, Any, List, TypeVar, Coroutine, Sequence, Tuple, Deque
from typing import (
Dict,
Generic,
Optional,
TYPE_CHECKING,
Union,
Callable,
Any,
List,
TypeVar,
Coroutine,
Sequence,
Tuple,
Deque,
)
import weakref
import inspect
@@ -84,6 +98,8 @@ if TYPE_CHECKING:
T = TypeVar('T')
Channel = Union[GuildChannel, VocalGuildChannel, PrivateChannel, PartialMessageable]
ClientT = TypeVar('ClientT', bound='Client')
class ChunkRequest:
def __init__(
@@ -143,10 +159,10 @@ async def logging_coroutine(coroutine: Coroutine[Any, Any, T], *, info: str) ->
_log.exception('Exception occurred during %s', info)
class ConnectionState:
class ConnectionState(Generic[ClientT]):
if TYPE_CHECKING:
_get_websocket: Callable[..., DiscordWebSocket]
_get_client: Callable[..., Client]
_get_client: Callable[..., ClientT]
_parsers: Dict[str, Callable[[Dict[str, Any]], None]]
def __init__(
@@ -1471,7 +1487,7 @@ class ConnectionState:
return Message(state=self, channel=channel, data=data)
class AutoShardedConnectionState(ConnectionState):
class AutoShardedConnectionState(ConnectionState[ClientT]):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.shard_ids: Union[List[int], range] = []