@@ -1441,12 +1441,13 @@ async def permissions_override(self, ctx, command_name: str.lower, *, level_name
14411441 return await ctx .send (embed = embed )
14421442
14431443 async def _bulk_override_flow (self , ctx ):
1444+ message = None
14441445 embed = discord .Embed (
14451446 title = "Bulk Override" ,
14461447 description = (
14471448 "Please list the commands you want to override. "
14481449 "You can list multiple commands separated by spaces or newlines.\n "
1449- "Example: `reply, block, unblock`."
1450+ "Example: `reply, block, unblock`.\n "
14501451 ),
14511452 color = self .bot .main_color ,
14521453 )
@@ -1470,6 +1471,7 @@ async def _bulk_override_flow(self, ctx):
14701471
14711472 if self .bot .prefix :
14721473 # Strip prefix from commands if present
1474+ # Note: This does not account for mention prefixes.
14731475 raw_commands = [
14741476 c [len (self .bot .prefix ) :] if c .startswith (self .bot .prefix ) else c for c in raw_commands
14751477 ]
@@ -1488,27 +1490,24 @@ async def _bulk_override_flow(self, ctx):
14881490 embed = discord .Embed (
14891491 title = "Invalid Commands Found" ,
14901492 description = f"The following commands were not found:\n `{ ', ' .join (invalid_commands )} `\n \n "
1491- "Do you want to continue with the valid commands? (y/n) " ,
1493+ "Do you want to continue with the valid commands?" ,
14921494 color = self .bot .error_color ,
14931495 )
1494- await ctx .send (embed = embed )
1495- try :
1496- msg = await self .bot .wait_for (
1497- "message" ,
1498- check = lambda m : m .author == ctx .author and m .channel == ctx .channel ,
1499- timeout = 60.0 ,
1500- )
1501- if msg .content .lower () not in ("y" , "yes" ):
1502- return await ctx .send (
1503- embed = discord .Embed (
1504- title = "Operation Aborted" ,
1505- description = "No changes have been applied." ,
1506- color = self .bot .error_color ,
1507- )
1508- )
1509- except asyncio .TimeoutError :
1510- return await ctx .send (
1511- embed = discord .Embed (title = "Error" , description = "Timed out." , color = self .bot .error_color )
1496+ view = discord .ui .View ()
1497+ view .add_item (utils .AcceptButton (custom_id = "continue" , emoji = "✅" ))
1498+ view .add_item (utils .DenyButton (custom_id = "abort" , emoji = "❌" ))
1499+
1500+ message = await ctx .send (embed = embed , view = view )
1501+ await view .wait ()
1502+
1503+ if not view .value :
1504+ return await message .edit (
1505+ embed = discord .Embed (
1506+ title = "Operation Aborted" ,
1507+ description = "No changes have been applied." ,
1508+ color = self .bot .error_color ,
1509+ ),
1510+ view = None ,
15121511 )
15131512
15141513 if not found_commands :
@@ -1536,90 +1535,88 @@ def add_command_recursive(cmd):
15361535 title = "Select Permission Level" ,
15371536 description = (
15381537 f"Found { len (final_commands )} commands (including subcommands).\n "
1539- "What permission level should these commands be set to? (e.g. `Owner`, `Admin`, `Moderator`, `Supporter`, `User`) "
1538+ "What permission level should these commands be set to?"
15401539 ),
15411540 color = self .bot .main_color ,
15421541 )
1543- await ctx .send (embed = embed )
15441542
1545- try :
1546- msg = await self .bot .wait_for (
1547- "message" ,
1548- check = lambda m : m .author == ctx .author and m .channel == ctx .channel ,
1549- timeout = 60.0 ,
1550- )
1543+ class LevelSelect (discord .ui .Select ):
1544+ def __init__ (self ):
1545+ options = [
1546+ discord .SelectOption (label = "Owner" , value = "OWNER" ),
1547+ discord .SelectOption (label = "Administrator" , value = "ADMINISTRATOR" ),
1548+ discord .SelectOption (label = "Moderator" , value = "MODERATOR" ),
1549+ discord .SelectOption (label = "Supporter" , value = "SUPPORTER" ),
1550+ discord .SelectOption (label = "Regular" , value = "REGULAR" ),
1551+ ]
1552+ super ().__init__ (placeholder = "Select permission level..." , options = options )
1553+
1554+ async def callback (self , interaction : discord .Interaction ):
1555+ self .view .value = self .values [0 ]
1556+ self .view .stop ()
1557+ await interaction .response .defer ()
1558+
1559+ view = discord .ui .View ()
1560+ view .add_item (LevelSelect ())
1561+
1562+ if message :
1563+ await message .edit (embed = embed , view = view )
1564+ else :
1565+ message = await ctx .send (embed = embed , view = view )
1566+ await view .wait ()
15511567
1552- except asyncio .TimeoutError :
1553- return await ctx .send (
1554- embed = discord .Embed (title = "Error" , description = "Timed out." , color = self .bot .error_color )
1568+ if view .value is None :
1569+ return await message .edit (
1570+ embed = discord .Embed (title = "Error" , description = "Timed out." , color = self .bot .error_color ),
1571+ view = None ,
15551572 )
15561573
1557- level_name = msg . content
1574+ level_name = view . value
15581575 level = self ._parse_level (level_name )
1559- if level == PermissionLevel .INVALID :
1560- return await ctx .send (
1561- embed = discord .Embed (
1562- title = "Error" ,
1563- description = f"Invalid permission level: `{ level_name } `. Aborting." ,
1564- color = self .bot .error_color ,
1565- )
1566- )
15671576
15681577 # Confirmation
15691578 command_list_str = ", " .join (
15701579 f"`{ c .qualified_name } `" for c in sorted (final_commands , key = lambda x : x .qualified_name )
15711580 )
15721581
1573- # Truncate if too long for embed description
1574- if len (command_list_str ) > 2000 :
1575- command_list_str = command_list_str [:1997 ] + "..."
1582+ command_list_str = utils .return_or_truncate (command_list_str , 2048 )
15761583
15771584 embed = discord .Embed (
15781585 title = "Confirm Bulk Override" ,
1579- description = f"**Level:** { level .name } \n \n **Commands:**\n { command_list_str } \n \n "
1580- "Type `confirm` to apply these changes or `cancel` to abort." ,
1586+ description = f"**Level:** { level .name } \n \n **Commands:**\n { command_list_str } " ,
15811587 color = self .bot .main_color ,
15821588 )
1583- await ctx .send (embed = embed )
15841589
1585- try :
1586- msg = await self .bot .wait_for (
1587- "message" ,
1588- check = lambda m : m .author == ctx .author
1589- and m .channel == ctx .channel
1590- and m .content .lower () in ("confirm" , "cancel" ),
1591- timeout = 30.0 ,
1592- )
1593- except asyncio .TimeoutError :
1594- return await ctx .send (
1595- embed = discord .Embed (
1596- title = "Error" , description = "Timed out. No changes applied." , color = self .bot .error_color
1597- )
1598- )
1590+ view = discord .ui .View ()
1591+ view .add_item (utils .AcceptButton (custom_id = "confirm" , emoji = "✅" ))
1592+ view .add_item (utils .DenyButton (custom_id = "cancel" , emoji = "❌" ))
15991593
1600- if msg .content .lower () == "cancel" :
1601- return await ctx .send (
1594+ await message .edit (embed = embed , view = view )
1595+ await view .wait ()
1596+
1597+ if not view .value :
1598+ return await message .edit (
16021599 embed = discord .Embed (
16031600 title = "Operation Aborted" ,
16041601 description = "No changes have been applied." ,
16051602 color = self .bot .error_color ,
1606- )
1603+ ),
1604+ view = None ,
16071605 )
16081606
16091607 # Apply changes
1610- count = 0
16111608 for cmd in final_commands :
16121609 self .bot .config ["override_command_level" ][cmd .qualified_name ] = level .name
1613- count += 1
16141610
16151611 await self .bot .config .update ()
16161612
1617- await ctx . send (
1613+ await message . edit (
16181614 embed = discord .Embed (
16191615 title = "Success" ,
1620- description = f"Successfully updated permissions for { count } commands." ,
1616+ description = f"Successfully updated permissions for { len ( final_commands ) } commands." ,
16211617 color = self .bot .main_color ,
1622- )
1618+ ),
1619+ view = None ,
16231620 )
16241621
16251622 @permissions .command (name = "add" , usage = "[command/level] [name] [user/role]" )
0 commit comments