99from aiohttp import FormData
1010
1111from interactions .client import const
12- from interactions .client .const import get_logger , MISSING
12+ from interactions .client .const import get_logger , MISSING , ClientT
1313from interactions .models .discord .components import BaseComponent
1414from interactions .models .discord .file import UPLOADABLE_TYPE
1515from interactions .models .discord .poll import Poll
@@ -149,17 +149,14 @@ def from_dict(cls, client: "interactions.Client", data: dict, guild_id: None | S
149149 return instance
150150
151151
152- class BaseContext (metaclass = abc .ABCMeta ):
152+ class BaseContext (typing . Generic [ ClientT ], metaclass = abc .ABCMeta ):
153153 """
154154 Base context class for all contexts.
155155
156156 Define your own context class by inheriting from this class. For compatibility with the library, you must define a `from_dict` classmethod that takes a dict and returns an instance of your context class.
157157
158158 """
159159
160- client : "interactions.Client"
161- """The client that created this context."""
162-
163160 command : BaseCommand
164161 """The command this context invokes."""
165162
@@ -173,8 +170,10 @@ class BaseContext(metaclass=abc.ABCMeta):
173170 guild_id : typing .Optional [Snowflake ]
174171 """The id of the guild this context was invoked in, if any."""
175172
176- def __init__ (self , client : "interactions.Client" ) -> None :
177- self .client = client
173+ def __init__ (self , client : ClientT ) -> None :
174+ self .client : ClientT = client
175+ """The client that created this context."""
176+
178177 self .author_id = MISSING
179178 self .channel_id = MISSING
180179 self .message_id = MISSING
@@ -218,12 +217,12 @@ def voice_state(self) -> typing.Optional["interactions.VoiceState"]:
218217 return self .client .cache .get_bot_voice_state (self .guild_id )
219218
220219 @property
221- def bot (self ) -> "interactions.Client " :
220+ def bot (self ) -> "ClientT " :
222221 return self .client
223222
224223 @classmethod
225224 @abc .abstractmethod
226- def from_dict (cls , client : "interactions.Client " , payload : dict ) -> Self :
225+ def from_dict (cls , client : "ClientT " , payload : dict ) -> Self :
227226 """
228227 Create a context instance from a dict.
229228
@@ -238,7 +237,7 @@ def from_dict(cls, client: "interactions.Client", payload: dict) -> Self:
238237 raise NotImplementedError
239238
240239
241- class BaseInteractionContext (BaseContext ):
240+ class BaseInteractionContext (BaseContext [ ClientT ] ):
242241 token : str
243242 """The interaction token."""
244243 id : Snowflake
@@ -281,14 +280,14 @@ class BaseInteractionContext(BaseContext):
281280 kwargs : dict [str , typing .Any ]
282281 """The keyword arguments passed to the interaction."""
283282
284- def __init__ (self , client : "interactions.Client " ) -> None :
283+ def __init__ (self , client : "ClientT " ) -> None :
285284 super ().__init__ (client )
286285 self .deferred = False
287286 self .responded = False
288287 self .ephemeral = False
289288
290289 @classmethod
291- def from_dict (cls , client : "interactions.Client " , payload : dict ) -> Self :
290+ def from_dict (cls , client : "ClientT " , payload : dict ) -> Self :
292291 instance = cls (client = client )
293292 instance .token = payload ["token" ]
294293 instance .id = Snowflake (payload ["id" ])
@@ -418,7 +417,7 @@ def gather_options(_options: list[dict[str, typing.Any]]) -> dict[str, typing.An
418417 self .args = list (self .kwargs .values ())
419418
420419
421- class InteractionContext (BaseInteractionContext , SendMixin ):
420+ class InteractionContext (BaseInteractionContext [ ClientT ] , SendMixin ):
422421 async def defer (self , * , ephemeral : bool = False , suppress_error : bool = False ) -> None :
423422 """
424423 Defer the interaction.
@@ -657,26 +656,26 @@ async def edit(
657656 return self .client .cache .place_message_data (message_data )
658657
659658
660- class SlashContext (InteractionContext , ModalMixin ):
659+ class SlashContext (InteractionContext [ ClientT ] , ModalMixin ):
661660 @classmethod
662- def from_dict (cls , client : "interactions.Client " , payload : dict ) -> Self :
661+ def from_dict (cls , client : "ClientT " , payload : dict ) -> Self :
663662 return super ().from_dict (client , payload )
664663
665664
666- class ContextMenuContext (InteractionContext , ModalMixin ):
665+ class ContextMenuContext (InteractionContext [ ClientT ] , ModalMixin ):
667666 target_id : Snowflake
668667 """The id of the target of the context menu."""
669668 editing_origin : bool
670669 """Whether you have deferred the interaction and are editing the original response."""
671670 target_type : None | CommandType
672671 """The type of the target of the context menu."""
673672
674- def __init__ (self , client : "interactions.Client " ) -> None :
673+ def __init__ (self , client : "ClientT " ) -> None :
675674 super ().__init__ (client )
676675 self .editing_origin = False
677676
678677 @classmethod
679- def from_dict (cls , client : "interactions.Client " , payload : dict ) -> Self :
678+ def from_dict (cls , client : "ClientT " , payload : dict ) -> Self :
680679 instance = super ().from_dict (client , payload )
681680 instance .target_id = Snowflake (payload ["data" ]["target_id" ])
682681 instance .target_type = CommandType (payload ["data" ]["type" ])
@@ -739,7 +738,7 @@ def target(self) -> None | Message | User | Member:
739738 return self .resolved .get (self .target_id )
740739
741740
742- class ComponentContext (InteractionContext , ModalMixin ):
741+ class ComponentContext (InteractionContext [ ClientT ] , ModalMixin ):
743742 values : list [str ]
744743 """The values of the SelectMenu component, if any."""
745744 custom_id : str
@@ -750,7 +749,7 @@ class ComponentContext(InteractionContext, ModalMixin):
750749 """Whether you have deferred the interaction and are editing the original response."""
751750
752751 @classmethod
753- def from_dict (cls , client : "interactions.Client " , payload : dict ) -> Self :
752+ def from_dict (cls , client : "ClientT " , payload : dict ) -> Self :
754753 instance = super ().from_dict (client , payload )
755754 instance .values = payload ["data" ].get ("values" , [])
756755 instance .custom_id = payload ["data" ]["custom_id" ]
@@ -920,7 +919,7 @@ def component(self) -> typing.Optional[BaseComponent]:
920919 return component
921920
922921
923- class ModalContext (InteractionContext ):
922+ class ModalContext (InteractionContext [ ClientT ] ):
924923 responses : dict [str , str ]
925924 """The responses of the modal. The key is the `custom_id` of the component."""
926925 custom_id : str
@@ -929,7 +928,7 @@ class ModalContext(InteractionContext):
929928 """Whether to edit the original message instead of sending a new one."""
930929
931930 @classmethod
932- def from_dict (cls , client : "interactions.Client " , payload : dict ) -> Self :
931+ def from_dict (cls , client : "ClientT " , payload : dict ) -> Self :
933932 instance = super ().from_dict (client , payload )
934933 instance .responses = {
935934 comp ["components" ][0 ]["custom_id" ]: comp ["components" ][0 ]["value" ] for comp in payload ["data" ]["components" ]
@@ -990,12 +989,12 @@ async def _defer(self, *, ephemeral: bool = False, edit_origin: bool = False) ->
990989 self .ephemeral = ephemeral
991990
992991
993- class AutocompleteContext (BaseInteractionContext ):
992+ class AutocompleteContext (BaseInteractionContext [ ClientT ] ):
994993 focussed_option : SlashCommandOption # todo: option parsing
995994 """The option the user is currently filling in."""
996995
997996 @classmethod
998- def from_dict (cls , client : "interactions.Client " , payload : dict ) -> Self :
997+ def from_dict (cls , client : "ClientT " , payload : dict ) -> Self :
999998 return super ().from_dict (client , payload )
1000999
10011000 @property
0 commit comments