@@ -1394,15 +1394,24 @@ async def on_socket_response(self, msg):
1394
1394
1395
1395
to_use = msg ["d" ]
1396
1396
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 ):
1398
1401
await self ._on_slash (to_use )
1399
1402
await self ._on_context_menu (to_use )
1403
+ elif interaction_type == 3 :
1400
1404
try :
1401
1405
await self ._on_component (to_use ) # noqa
1402
1406
except KeyError :
1403
1407
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
1404
1414
return
1405
- # raise NotImplementedError
1406
1415
1407
1416
async def _on_component (self , to_use ):
1408
1417
ctx = context .ComponentContext (self .req , to_use , self ._discord , self .logger )
@@ -1415,7 +1424,7 @@ async def _on_component(self, to_use):
1415
1424
self ._discord .dispatch ("component_callback" , ctx , callback )
1416
1425
await self .invoke_component_callback (callback , ctx )
1417
1426
1418
- async def _on_slash (self , to_use ):
1427
+ async def _on_slash (self , to_use ): # slash commands only.
1419
1428
if to_use ["data" ]["name" ] in self .commands :
1420
1429
1421
1430
ctx = context .SlashContext (self .req , to_use , self ._discord , self .logger )
@@ -1426,6 +1435,9 @@ async def _on_slash(self, to_use):
1426
1435
1427
1436
selected_cmd = self .commands [to_use ["data" ]["name" ]]
1428
1437
1438
+ if selected_cmd ._type != 1 :
1439
+ return # If its a menu, ignore.
1440
+
1429
1441
if (
1430
1442
selected_cmd .allowed_guild_ids
1431
1443
and ctx .guild_id not in selected_cmd .allowed_guild_ids
@@ -1462,6 +1474,12 @@ async def _on_slash(self, to_use):
1462
1474
await self .invoke_command (selected_cmd , ctx , args )
1463
1475
1464
1476
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
+
1465
1483
if to_use ["data" ]["name" ] in self .commands ["context" ]:
1466
1484
ctx = context .MenuContext (self .req , to_use , self ._discord , self .logger )
1467
1485
cmd_name = to_use ["data" ]["name" ]
@@ -1489,6 +1507,39 @@ async def _on_context_menu(self, to_use):
1489
1507
1490
1508
await self .invoke_command (selected_cmd , ctx , args = {})
1491
1509
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
+
1492
1543
async def handle_subcommand (self , ctx : context .SlashContext , data : dict ):
1493
1544
"""
1494
1545
Coroutine for handling subcommand.
0 commit comments