@@ -244,18 +244,53 @@ def handle_dispatch(self, event: str, data: dict) -> None:
244244 :param data: The data of the event.
245245 :type data: dict
246246 """
247+
248+ def check_sub_command (self , option ) -> dict :
249+ _kwargs = dict ()
250+ if "options" in option :
251+ if option ["type" ] == OptionType .SUB_COMMAND_GROUP :
252+ _kwargs ["sub_command_group" ] = option ["name" ]
253+ for group_option in option ["options" ]:
254+ _kwargs ["sub_command" ] = group_option ["name" ]
255+ if "options" in group_option :
256+ for sub_option in group_option ["options" ]:
257+ _kwargs [sub_option ["name" ]] = sub_option ["value" ]
258+ elif option ["type" ] == OptionType .SUB_COMMAND :
259+ _kwargs ["sub_command" ] = option ["name" ]
260+ for sub_option in option ["options" ]:
261+ _kwargs [sub_option ["name" ]] = sub_option ["value" ]
262+ else :
263+ _kwargs [option ["name" ]] = option ["value" ]
264+
265+ return _kwargs
266+
267+ def check_sub_auto (self , option ) -> tuple :
268+ if "options" in option :
269+ if option ["type" ] == OptionType .SUB_COMMAND_GROUP :
270+ for group_option in option ["options" ]:
271+ if "options" in group_option :
272+ for sub_option in option ["options" ]:
273+ if sub_option .get ("focused" ):
274+ return sub_option ["name" ], sub_option ["value" ]
275+ elif option ["type" ] == OptionType .SUB_COMMAND :
276+ for sub_option in option ["options" ]:
277+ if sub_option .get ("focused" ):
278+ return sub_option ["name" ], sub_option ["value" ]
279+ elif option .get ("focused" ):
280+ return option ["name" ], option ["value" ]
281+
247282 if event != "TYPING_START" :
248283 name : str = event .lower ()
249284 path : str = "interactions"
250285 path += ".models" if event == "INTERACTION_CREATE" else ".api.models"
251286
252287 if event != "INTERACTION_CREATE" :
253288 try :
254- lst_names : list = [piece for piece in name .split ("_" )]
289+ lst_names : list = [piece . capitalize () for piece in name .split ("_" )]
255290 _name : str = (
256- lst_names [0 ]. capitalize ()
291+ lst_names [0 ]
257292 if len (lst_names ) < 3
258- else "" .join (piece . capitalize () for piece in lst_names [:- 1 ])
293+ else "" .join (piece for piece in lst_names [:- 1 ])
259294 )
260295 log .debug (f"Dispatching object { _name } from event { name } " )
261296 obj : object = getattr (
@@ -278,15 +313,15 @@ def handle_dispatch(self, event: str, data: dict) -> None:
278313 if hasattr (context .data , "options" ):
279314 if context .data .options :
280315 for option in context .data .options :
281- _kwargs .update (self . check_sub_command (option ))
316+ _kwargs .update (check_sub_command (option ))
282317 elif data ["type" ] == InteractionType .MESSAGE_COMPONENT :
283318 _name = context .data .custom_id
284319 elif data ["type" ] == InteractionType .APPLICATION_COMMAND_AUTOCOMPLETE :
285320 _name = "autocomplete_"
286321 if hasattr (context .data , "options" ):
287322 if context .data .options :
288323 for option in context .data .options :
289- add_name , add_args = self . check_sub_auto (option )
324+ add_name , add_args = check_sub_auto (option )
290325 if add_name :
291326 _name += add_name
292327 if add_args :
@@ -303,40 +338,6 @@ def handle_dispatch(self, event: str, data: dict) -> None:
303338
304339 self .dispatch .dispatch ("raw_socket_create" , data )
305340
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-
340341 def contextualize (self , data : dict ) -> object :
341342 """
342343 Takes raw data given back from the gateway
0 commit comments