3232class Heartbeat (Thread ):
3333 """
3434 A class representing a consistent heartbeat connection with the gateway.
35-
3635 :ivar WebSocket ws: The WebSocket class to infer on.
3736 :ivar Union[int, float] interval: The heartbeat interval determined by the gateway.
3837 :ivar Event event: The multi-threading event.
@@ -79,7 +78,6 @@ def stop(self) -> None:
7978class WebSocket :
8079 """
8180 A class representing a websocket connection with the gateway.
82-
8381 :ivar Intents intents: An instance of :class:`interactions.api.models.Intents`.
8482 :ivar AbstractEventLoop loop: The coroutine event loop established on.
8583 :ivar Request req: An instance of :class:`interactions.api.http.Request`.
@@ -151,7 +149,6 @@ async def connect(
151149 ) -> None :
152150 """
153151 Establishes a connection to the gateway.
154-
155152 :param token: The token to use for identifying.
156153 :type token: str
157154 :param shard?: The shard ID to identify under.
@@ -181,7 +178,6 @@ async def handle_connection(
181178 ) -> None :
182179 """
183180 Handles the connection to the gateway.
184-
185181 :param stream: The data stream from the gateway.
186182 :type stream: dict
187183 :param shard?: The shard ID to identify under.
@@ -243,7 +239,6 @@ async def handle_connection(
243239 def handle_dispatch (self , event : str , data : dict ) -> None :
244240 """
245241 Handles the dispatched event data from a gateway event.
246-
247242 :param event: The name of the event.
248243 :type event: str
249244 :param data: The data of the event.
@@ -277,37 +272,25 @@ def handle_dispatch(self, event: str, data: dict) -> None:
277272 context = self .contextualize (data )
278273 _name : str
279274 _args : list = [context ]
275+ _kwargs : dict = dict ()
280276 if data ["type" ] == InteractionType .APPLICATION_COMMAND :
281277 _name = context .data .name
282278 if hasattr (context .data , "options" ):
283279 if context .data .options :
284280 for option in context .data .options :
285- if option ["type" ] in (
286- OptionType .SUB_COMMAND ,
287- OptionType .SUB_COMMAND_GROUP ,
288- ):
289- if option .get ("options" ):
290- for sub_option in option ["options" ]:
291- _args .append (sub_option )
292- else :
293- pass
294- else :
295- _args .append (option ["value" ])
281+ _kwargs .update (self .check_sub_command (option ))
296282 elif data ["type" ] == InteractionType .MESSAGE_COMPONENT :
297283 _name = context .data .custom_id
298284 elif data ["type" ] == InteractionType .APPLICATION_COMMAND_AUTOCOMPLETE :
299285 _name = "autocomplete_"
300286 if hasattr (context .data , "options" ):
301287 if context .data .options :
302288 for option in context .data .options :
303- if option ["type" ] in (
304- OptionType .SUB_COMMAND ,
305- OptionType .SUB_COMMAND_GROUP ,
306- ):
307- if option .get ("options" ):
308- for sub_option in option ["options" ]:
309- if sub_option .get ("focused" ):
310- _name += sub_option ["name" ]
289+ add_name , add_args = self .check_sub_auto (option )
290+ if add_name :
291+ _name += add_name
292+ if add_args :
293+ _args .append (add_args )
311294 elif data ["type" ] == InteractionType .MODAL_SUBMIT :
312295 _name = f"modal_{ context .data .custom_id } "
313296 if hasattr (context .data , "components" ):
@@ -316,15 +299,48 @@ def handle_dispatch(self, event: str, data: dict) -> None:
316299 for _value in component .components :
317300 _args .append (_value ["value" ])
318301
319- self .dispatch .dispatch (_name , * _args )
302+ self .dispatch .dispatch (_name , * _args , ** _kwargs )
320303
321304 self .dispatch .dispatch ("raw_socket_create" , data )
322305
306+ def check_sub_command (self , option ) -> dict :
307+ _kwargs = dict ()
308+ if "options" in option :
309+ if option ["type" ] == OptionType .SUB_COMMAND_GROUP :
310+ _kwargs ["sub_command_group" ] = option ["name" ]
311+ for group_option in option ["options" ]:
312+ _kwargs ["sub_command" ] = group_option ["name" ]
313+ if "options" in group_option :
314+ for sub_option in group_option ["options" ]:
315+ _kwargs [sub_option ["name" ]] = sub_option ["value" ]
316+ elif option ["type" ] == OptionType .SUB_COMMAND :
317+ _kwargs ["sub_command" ] = option ["name" ]
318+ for sub_option in option ["options" ]:
319+ _kwargs [sub_option ["name" ]] = sub_option ["value" ]
320+ else :
321+ _kwargs [option ["name" ]] = option ["value" ]
322+
323+ return _kwargs
324+
325+ def check_sub_auto (self , option ) -> tuple :
326+ if "options" in option :
327+ if option ["type" ] == OptionType .SUB_COMMAND_GROUP :
328+ for group_option in option ["options" ]:
329+ if "options" in group_option :
330+ for sub_option in option ["options" ]:
331+ if sub_option .get ("focused" ):
332+ return sub_option ["name" ], sub_option ["value" ]
333+ elif option ["type" ] == OptionType .SUB_COMMAND :
334+ for sub_option in option ["options" ]:
335+ if sub_option .get ("focused" ):
336+ return sub_option ["name" ], sub_option ["value" ]
337+ elif option .get ("focused" ):
338+ return option ["name" ], option ["value" ]
339+
323340 def contextualize (self , data : dict ) -> object :
324341 """
325342 Takes raw data given back from the gateway
326343 and gives "context" based off of what it is.
327-
328344 :param data: The data from the gateway.
329345 :type data: dict
330346 :return: The context object.
@@ -358,7 +374,6 @@ async def identify(
358374 ) -> None :
359375 """
360376 Sends an ``IDENTIFY`` packet to the gateway.
361-
362377 :param shard?: The shard ID to identify under.
363378 :type shard: Optional[int]
364379 :param presence?: The presence to change the bot to on identify.
0 commit comments