@@ -1496,142 +1496,143 @@ async def on_guild_remove(guild: discord.Guild):
1496
1496
@client .event
1497
1497
async def on_socket_response (msg : Dict ):
1498
1498
# This is not a publically listed event, but we can intercept it to catch interactions
1499
- if msg ["op" ] == 0 and msg ["t" ] = = "INTERACTION_CREATE" :
1500
- # This means it's an interaction.
1501
- # https://discord.com/developers/docs/interactions/slash-commands# interaction
1502
- interaction : Dict [ str , Any ] = msg [ "d" ]
1503
- # Verify this is for us
1504
- if int ( interaction [ "application_id" ]) != ( await client . application_info ()). id or interaction [ "type" ] != 2 :
1505
- # Not sure if this'll ever happen, but we're recieving an interaction not for us.
1506
- return
1507
- commandname : str = interaction [ "data" ][ "name" ]
1508
- responseurl = f"https://discord.com/api/v8/interactions/ { interaction ['id' ] } / { interaction [ 'token' ] } /callback"
1509
-
1510
- async def respond ( content : str , hidden : bool = False ):
1511
- responsejson = {
1512
- "type" : 4 ,
1513
- "data " : {
1514
- "content " : content ,
1515
- "flags " : 64
1516
- }
1499
+ if msg ["op" ] != 0 or msg ["t" ] ! = "INTERACTION_CREATE" :
1500
+ return
1501
+ # This means it's an interaction.
1502
+ # https://discord.com/developers/docs/interactions/slash-commands#interaction
1503
+ interaction : Dict [ str , Any ] = msg [ "d" ]
1504
+ # Verify this is for us
1505
+ if int ( interaction [ "application_id" ]) != ( await client . application_info ()). id or interaction [ "type" ] != 2 :
1506
+ # Not sure if this'll ever happen, but we're recieving an interaction not for us.
1507
+ return
1508
+ commandname : str = interaction ["data" ][ "name" ]
1509
+ responseurl = f"https://discord.com/api/v8/interactions/ { interaction [ 'id' ] } / { interaction [ 'token' ] } /callback"
1510
+
1511
+ async def respond ( content : str , hidden : bool = False ):
1512
+ responsejson = {
1513
+ "type " : 4 ,
1514
+ "data " : {
1515
+ "content " : content ,
1516
+ "flags" : 64
1517
1517
}
1518
- if hidden :
1519
- responsejson ["data" ]["flags" ] = 64
1520
- await session .post (responseurl , json = responsejson )
1521
-
1522
- async def guildRequired ():
1523
- await respond ("You must be in a guild to use this command." , True )
1524
-
1525
- async def permissionDenied ():
1526
- await respond ("You do not have permission to use this command." , True )
1527
-
1528
- authorid : int = int (interaction ["member" ]["user" ]["id" ]
1529
- if "member" in interaction else interaction ["user" ]["id" ])
1530
- guild : discord .Guild = None
1531
- if "guild_id" in interaction :
1532
- guild = await dLib .findGuild (interaction ["guild_id" ])
1533
-
1534
- if commandname .lower () == "reservations" :
1535
- if guild is None :
1536
- await guildRequired ()
1518
+ }
1519
+ if hidden :
1520
+ responsejson ["data" ]["flags" ] = 64
1521
+ await session .post (responseurl , json = responsejson )
1522
+
1523
+ async def guildRequired ():
1524
+ await respond ("You must be in a guild to use this command." , True )
1525
+
1526
+ async def permissionDenied ():
1527
+ await respond ("You do not have permission to use this command." , True )
1528
+
1529
+ authorid : int = int (interaction ["member" ]["user" ]["id" ]
1530
+ if "member" in interaction else interaction ["user" ]["id" ])
1531
+ guild : discord .Guild = None
1532
+ if "guild_id" in interaction :
1533
+ guild = await dLib .findGuild (interaction ["guild_id" ])
1534
+
1535
+ if commandname .lower () == "reservations" :
1536
+ if guild is None :
1537
+ await guildRequired ()
1538
+ return
1539
+ elif not await checkResAdmin (guild , authorid ):
1540
+ await permissionDenied ()
1541
+ return
1542
+ for channel in controlledChannels :
1543
+ if channel .interactChannel .id == int (interaction ["channel_id" ]):
1544
+ await respond ("This channel already contains a controlled channel." , True )
1537
1545
return
1538
- elif not await checkResAdmin (guild , authorid ):
1539
- await permissionDenied ()
1546
+ await respond ("Loading Reservation Channel..." )
1547
+ c = ReserveChannel (None , await dLib .findChannel (interaction ["channel_id" ]))
1548
+ await c .updateText ()
1549
+ await c .updateImg ()
1550
+ controlledChannels .append (c )
1551
+ await session .delete (f"https://discord.com/api/v8/webhooks/{ interaction ['application_id' ]} /{ interaction ['token' ]} /messages/@original" )
1552
+ elif commandname .lower () == "asireservations" :
1553
+ if guild is None :
1554
+ await guildRequired ()
1555
+ return
1556
+ elif not await checkResAdmin (guild , authorid ):
1557
+ await permissionDenied ()
1558
+ return
1559
+ for channel in controlledChannels :
1560
+ if channel .interactChannel .id == int (interaction ["channel_id" ]):
1561
+ await respond ("This channel already contains a controlled channel." , True )
1540
1562
return
1541
- for channel in controlledChannels :
1542
- if channel .interactChannel .id == int (interaction ["channel_id" ]):
1543
- await respond ("This channel already contains a controlled channel." , True )
1544
- return
1545
- await respond ("Loading Reservation Channel..." )
1546
- c = ReserveChannel (None , await dLib .findChannel (interaction ["channel_id" ]))
1547
- await c .updateText ()
1548
- await c .updateImg ()
1549
- controlledChannels .append (c )
1550
- await session .delete (f"https://discord.com/api/v8/webhooks/{ interaction ['application_id' ]} /{ interaction ['token' ]} /messages/@original" )
1551
- elif commandname .lower () == "asireservations" :
1552
- if guild is None :
1553
- await guildRequired ()
1563
+ await respond ("Loading ASI Reservation Channel..." )
1564
+ c = asiresChannel (None , await dLib .findChannel (interaction ["channel_id" ]))
1565
+ await c .updateText ()
1566
+ controlledChannels .append (c )
1567
+ await session .delete (f"https://discord.com/api/v8/webhooks/{ interaction ['application_id' ]} /{ interaction ['token' ]} /messages/@original" )
1568
+ elif commandname .lower () == "stats" :
1569
+ for channel in controlledChannels :
1570
+ if channel .interactChannel .id == int (interaction ["channel_id" ]):
1571
+ await respond ("This channel already contains a controlled channel." , True )
1554
1572
return
1555
- elif not await checkResAdmin (guild , authorid ):
1573
+ await respond ("Sent stats creation details to your DMs!" , True )
1574
+ c = await statsChannel (await dLib .findUser (authorid ), await dLib .findChannel (interaction ["channel_id" ])).asyncInit ()
1575
+ if "options" in interaction ["data" ]:
1576
+ for option in interaction ["data" ]["options" ]:
1577
+ if option ["name" ] == "skanderbeg" :
1578
+ c .skanderbeg = option ["value" ]
1579
+ else :
1580
+ # Default if not specified
1581
+ c .skanderbeg = False
1582
+ controlledChannels .append (c )
1583
+ elif commandname .lower () == "defaultban" :
1584
+ if guild is None :
1585
+ await guildRequired ()
1586
+ return
1587
+ subcommand : Dict [str , Any ] = interaction ["data" ]["options" ]
1588
+ string = "Something went wrong."
1589
+ if subcommand [0 ]["name" ] == "add" :
1590
+ if not await checkResAdmin (guild , authorid ):
1556
1591
await permissionDenied ()
1557
1592
return
1558
- for channel in controlledChannels :
1559
- if channel .interactChannel .id == int (interaction ["channel_id" ]):
1560
- await respond ("This channel already contains a controlled channel." , True )
1561
- return
1562
- await respond ("Loading ASI Reservation Channel..." )
1563
- c = asiresChannel (None , await dLib .findChannel (interaction ["channel_id" ]))
1564
- await c .updateText ()
1565
- controlledChannels .append (c )
1566
- await session .delete (f"https://discord.com/api/v8/webhooks/{ interaction ['application_id' ]} /{ interaction ['token' ]} /messages/@original" )
1567
- elif commandname .lower () == "stats" :
1568
- for channel in controlledChannels :
1569
- if channel .interactChannel .id == int (interaction ["channel_id" ]):
1570
- await respond ("This channel already contains a controlled channel." , True )
1571
- return
1572
- await respond ("Sent stats creation details to your DMs!" , True )
1573
- c = await statsChannel (await dLib .findUser (authorid ), await dLib .findChannel (interaction ["channel_id" ])).asyncInit ()
1574
- if "options" in interaction ["data" ]:
1575
- for option in interaction ["data" ]["options" ]:
1576
- if option ["name" ] == "skanderbeg" :
1577
- c .skanderbeg = option ["value" ]
1593
+ tag : str = EU4Lib .country (subcommand [0 ]["options" ][0 ]["value" ])
1594
+ if tag is None :
1595
+ string = f"Could not find country named { subcommand [0 ]['options' ][0 ]['value' ]} ."
1578
1596
else :
1579
- # Default if not specified
1580
- c .skanderbeg = False
1581
- controlledChannels .append (c )
1582
- elif commandname .lower () == "defaultban" :
1583
- if guild is None :
1584
- await guildRequired ()
1585
- return
1586
- subcommand : Dict [str , Any ] = interaction ["data" ]["options" ]
1587
- string = "Something went wrong."
1588
- if subcommand [0 ]["name" ] == "add" :
1589
- if not await checkResAdmin (guild , authorid ):
1590
- await permissionDenied ()
1591
- return
1592
- tag : str = EU4Lib .country (subcommand [0 ]["options" ][0 ]["value" ])
1593
- if tag is None :
1594
- string = f"Could not find country named { subcommand [0 ]['options' ][0 ]['value' ]} ."
1595
- else :
1596
- GuildManager .addBan (guild , tag )
1597
- string = f"Adding { EU4Lib .tagToName (tag )} to default ban list."
1598
- string += "\n New default ban list: "
1599
- banlist = GuildManager .getBan (guild )
1600
- for listtag in banlist :
1601
- string += f"{ EU4Lib .tagToName (listtag )} { '' if listtag is banlist [- 1 ] else ', ' } "
1602
- elif subcommand [0 ]["name" ] == "del" :
1603
- if not await checkResAdmin (guild , authorid ):
1604
- await permissionDenied ()
1605
- return
1606
- tag : str = EU4Lib .country (subcommand [0 ]["options" ][0 ]["value" ])
1607
- if tag is None :
1608
- string = f"Could not find country named { subcommand [0 ]['options' ][0 ]['value' ]} ."
1609
- if tag is not None :
1610
- GuildManager .removeBan (guild , tag )
1611
- string = f"Removing { EU4Lib .tagToName (tag )} from default ban list."
1612
- string += "\n New default ban list: "
1613
- banlist = GuildManager .getBan (guild )
1614
- for listtag in banlist :
1615
- string += f"{ EU4Lib .tagToName (listtag )} { '' if listtag is banlist [- 1 ] else ', ' } "
1616
- elif subcommand [0 ]["name" ] == "list" :
1617
- string = "Default ban list: "
1597
+ GuildManager .addBan (guild , tag )
1598
+ string = f"Adding { EU4Lib .tagToName (tag )} to default ban list."
1599
+ string += "\n New default ban list: "
1618
1600
banlist = GuildManager .getBan (guild )
1619
- for tag in banlist :
1620
- string += EU4Lib .tagToName (tag ) + \
1621
- ("" if tag is banlist [- 1 ] else ", " )
1622
- await respond (string , True )
1623
- elif commandname .lower () == "adminrank" :
1624
- if guild is None :
1625
- await guildRequired ()
1626
- return
1627
- elif not await checkResAdmin (guild , authorid ):
1601
+ for listtag in banlist :
1602
+ string += f"{ EU4Lib .tagToName (listtag )} { '' if listtag is banlist [- 1 ] else ', ' } "
1603
+ elif subcommand [0 ]["name" ] == "del" :
1604
+ if not await checkResAdmin (guild , authorid ):
1628
1605
await permissionDenied ()
1629
1606
return
1630
- newRankID : int = int (interaction ["data" ]["options" ][0 ]["value" ])
1631
- GuildManager .setAdmin (guild , newRankID )
1632
- await respond (f"Admin rank set to <@&{ newRankID } >." , True )
1633
- else :
1634
- await respond ("The bot was unable to process this command. Please report with details to the developer." , True )
1607
+ tag : str = EU4Lib .country (subcommand [0 ]["options" ][0 ]["value" ])
1608
+ if tag is None :
1609
+ string = f"Could not find country named { subcommand [0 ]['options' ][0 ]['value' ]} ."
1610
+ if tag is not None :
1611
+ GuildManager .removeBan (guild , tag )
1612
+ string = f"Removing { EU4Lib .tagToName (tag )} from default ban list."
1613
+ string += "\n New default ban list: "
1614
+ banlist = GuildManager .getBan (guild )
1615
+ for listtag in banlist :
1616
+ string += f"{ EU4Lib .tagToName (listtag )} { '' if listtag is banlist [- 1 ] else ', ' } "
1617
+ elif subcommand [0 ]["name" ] == "list" :
1618
+ string = "Default ban list: "
1619
+ banlist = GuildManager .getBan (guild )
1620
+ for tag in banlist :
1621
+ string += EU4Lib .tagToName (tag ) + \
1622
+ ("" if tag is banlist [- 1 ] else ", " )
1623
+ await respond (string , True )
1624
+ elif commandname .lower () == "adminrank" :
1625
+ if guild is None :
1626
+ await guildRequired ()
1627
+ return
1628
+ elif not await checkResAdmin (guild , authorid ):
1629
+ await permissionDenied ()
1630
+ return
1631
+ newRankID : int = int (interaction ["data" ]["options" ][0 ]["value" ])
1632
+ GuildManager .setAdmin (guild , newRankID )
1633
+ await respond (f"Admin rank set to <@&{ newRankID } >." , True )
1634
+ else :
1635
+ await respond ("The bot was unable to process this command. Please report with details to the developer." , True )
1635
1636
1636
1637
1637
1638
client .run (token )
0 commit comments