@@ -1394,15 +1394,24 @@ async def on_socket_response(self, msg):
13941394
13951395 to_use = msg ["d" ]
13961396 interaction_type = to_use ["type" ]
1397- if interaction_type in (1 , 2 , 3 ) or msg ["s" ] == 5 :
1397+
1398+ # dis_snek variance seq
1399+
1400+ if interaction_type in (1 , 2 ):
13981401 await self ._on_slash (to_use )
13991402 await self ._on_context_menu (to_use )
1403+ elif interaction_type == 3 :
14001404 try :
14011405 await self ._on_component (to_use ) # noqa
14021406 except KeyError :
14031407 pass # for some reason it complains about custom_id being an optional arg when it's fine?
1408+ finally :
1409+ await self ._on_context_menu (to_use )
1410+ else :
1411+ raise NotImplementedError (
1412+ f"Unknown Interaction Received: { interaction_type } "
1413+ ) # check if discord does a sneaky event change on us
14041414 return
1405- # raise NotImplementedError
14061415
14071416 async def _on_component (self , to_use ):
14081417 ctx = context .ComponentContext (self .req , to_use , self ._discord , self .logger )
@@ -1415,7 +1424,7 @@ async def _on_component(self, to_use):
14151424 self ._discord .dispatch ("component_callback" , ctx , callback )
14161425 await self .invoke_component_callback (callback , ctx )
14171426
1418- async def _on_slash (self , to_use ):
1427+ async def _on_slash (self , to_use ): # slash commands only.
14191428 if to_use ["data" ]["name" ] in self .commands :
14201429
14211430 ctx = context .SlashContext (self .req , to_use , self ._discord , self .logger )
@@ -1426,6 +1435,9 @@ async def _on_slash(self, to_use):
14261435
14271436 selected_cmd = self .commands [to_use ["data" ]["name" ]]
14281437
1438+ if selected_cmd ._type != 1 :
1439+ return # If its a menu, ignore.
1440+
14291441 if (
14301442 selected_cmd .allowed_guild_ids
14311443 and ctx .guild_id not in selected_cmd .allowed_guild_ids
@@ -1462,6 +1474,12 @@ async def _on_slash(self, to_use):
14621474 await self .invoke_command (selected_cmd , ctx , args )
14631475
14641476 async def _on_context_menu (self , to_use ):
1477+ # Slash Command Logic
1478+
1479+ # to prevent any potential keyerrors:
1480+ if "name" not in to_use ["data" ].keys ():
1481+ return
1482+
14651483 if to_use ["data" ]["name" ] in self .commands ["context" ]:
14661484 ctx = context .MenuContext (self .req , to_use , self ._discord , self .logger )
14671485 cmd_name = to_use ["data" ]["name" ]
@@ -1489,6 +1507,39 @@ async def _on_context_menu(self, to_use):
14891507
14901508 await self .invoke_command (selected_cmd , ctx , args = {})
14911509
1510+ # Cog Logic
1511+
1512+ elif to_use ["data" ]["name" ] in self .commands :
1513+ ctx = context .MenuContext (self .req , to_use , self ._discord , self .logger )
1514+ cmd_name = to_use ["data" ]["name" ]
1515+
1516+ if cmd_name not in self .commands and cmd_name in self .subcommands :
1517+ return # menus don't have subcommands you smooth brain
1518+
1519+ selected_cmd = self .commands [cmd_name ]
1520+ if type (selected_cmd ) == dict :
1521+ return # Get rid of any selection thats a dict somehow
1522+ if selected_cmd ._type == 1 : # noqa
1523+ return # Slash command obj.
1524+
1525+ if (
1526+ selected_cmd .allowed_guild_ids
1527+ and ctx .guild_id not in selected_cmd .allowed_guild_ids
1528+ ):
1529+ return
1530+
1531+ if selected_cmd .has_subcommands and not selected_cmd .func :
1532+ return await self .handle_subcommand (ctx , to_use )
1533+
1534+ if "options" in to_use ["data" ]:
1535+ for x in to_use ["data" ]["options" ]:
1536+ if "value" not in x :
1537+ return await self .handle_subcommand (ctx , to_use )
1538+
1539+ self ._discord .dispatch ("context_menu" , ctx )
1540+
1541+ await self .invoke_command (selected_cmd , ctx , args = {})
1542+
14921543 async def handle_subcommand (self , ctx : context .SlashContext , data : dict ):
14931544 """
14941545 Coroutine for handling subcommand.
0 commit comments