Skip to content

Commit 9be3c4b

Browse files
lorenzo132sebkuip
authored andcommitted
resolve review.
1 parent df15ad8 commit 9be3c4b

1 file changed

Lines changed: 65 additions & 68 deletions

File tree

cogs/utility.py

Lines changed: 65 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,12 +1467,13 @@ async def permissions_override(self, ctx, command_name: str.lower, *, level_name
14671467
return await ctx.send(embed=embed)
14681468

14691469
async def _bulk_override_flow(self, ctx):
1470+
message = None
14701471
embed = discord.Embed(
14711472
title="Bulk Override",
14721473
description=(
14731474
"Please list the commands you want to override. "
14741475
"You can list multiple commands separated by spaces or newlines.\n"
1475-
"Example: `reply, block, unblock`."
1476+
"Example: `reply, block, unblock`.\n"
14761477
),
14771478
color=self.bot.main_color,
14781479
)
@@ -1496,6 +1497,7 @@ async def _bulk_override_flow(self, ctx):
14961497

14971498
if self.bot.prefix:
14981499
# Strip prefix from commands if present
1500+
# Note: This does not account for mention prefixes.
14991501
raw_commands = [
15001502
c[len(self.bot.prefix) :] if c.startswith(self.bot.prefix) else c for c in raw_commands
15011503
]
@@ -1514,27 +1516,24 @@ async def _bulk_override_flow(self, ctx):
15141516
embed = discord.Embed(
15151517
title="Invalid Commands Found",
15161518
description=f"The following commands were not found:\n`{', '.join(invalid_commands)}`\n\n"
1517-
"Do you want to continue with the valid commands? (y/n)",
1519+
"Do you want to continue with the valid commands?",
15181520
color=self.bot.error_color,
15191521
)
1520-
await ctx.send(embed=embed)
1521-
try:
1522-
msg = await self.bot.wait_for(
1523-
"message",
1524-
check=lambda m: m.author == ctx.author and m.channel == ctx.channel,
1525-
timeout=60.0,
1526-
)
1527-
if msg.content.lower() not in ("y", "yes"):
1528-
return await ctx.send(
1529-
embed=discord.Embed(
1530-
title="Operation Aborted",
1531-
description="No changes have been applied.",
1532-
color=self.bot.error_color,
1533-
)
1534-
)
1535-
except asyncio.TimeoutError:
1536-
return await ctx.send(
1537-
embed=discord.Embed(title="Error", description="Timed out.", color=self.bot.error_color)
1522+
view = discord.ui.View()
1523+
view.add_item(utils.AcceptButton(custom_id="continue", emoji="✅"))
1524+
view.add_item(utils.DenyButton(custom_id="abort", emoji="❌"))
1525+
1526+
message = await ctx.send(embed=embed, view=view)
1527+
await view.wait()
1528+
1529+
if not view.value:
1530+
return await message.edit(
1531+
embed=discord.Embed(
1532+
title="Operation Aborted",
1533+
description="No changes have been applied.",
1534+
color=self.bot.error_color,
1535+
),
1536+
view=None,
15381537
)
15391538

15401539
if not found_commands:
@@ -1562,90 +1561,88 @@ def add_command_recursive(cmd):
15621561
title="Select Permission Level",
15631562
description=(
15641563
f"Found {len(final_commands)} commands (including subcommands).\n"
1565-
"What permission level should these commands be set to? (e.g. `Owner`, `Admin`, `Moderator`, `Supporter`, `User`)"
1564+
"What permission level should these commands be set to?"
15661565
),
15671566
color=self.bot.main_color,
15681567
)
1569-
await ctx.send(embed=embed)
15701568

1571-
try:
1572-
msg = await self.bot.wait_for(
1573-
"message",
1574-
check=lambda m: m.author == ctx.author and m.channel == ctx.channel,
1575-
timeout=60.0,
1576-
)
1569+
class LevelSelect(discord.ui.Select):
1570+
def __init__(self):
1571+
options = [
1572+
discord.SelectOption(label="Owner", value="OWNER"),
1573+
discord.SelectOption(label="Administrator", value="ADMINISTRATOR"),
1574+
discord.SelectOption(label="Moderator", value="MODERATOR"),
1575+
discord.SelectOption(label="Supporter", value="SUPPORTER"),
1576+
discord.SelectOption(label="Regular", value="REGULAR"),
1577+
]
1578+
super().__init__(placeholder="Select permission level...", options=options)
1579+
1580+
async def callback(self, interaction: discord.Interaction):
1581+
self.view.value = self.values[0]
1582+
self.view.stop()
1583+
await interaction.response.defer()
1584+
1585+
view = discord.ui.View()
1586+
view.add_item(LevelSelect())
1587+
1588+
if message:
1589+
await message.edit(embed=embed, view=view)
1590+
else:
1591+
message = await ctx.send(embed=embed, view=view)
1592+
await view.wait()
15771593

1578-
except asyncio.TimeoutError:
1579-
return await ctx.send(
1580-
embed=discord.Embed(title="Error", description="Timed out.", color=self.bot.error_color)
1594+
if view.value is None:
1595+
return await message.edit(
1596+
embed=discord.Embed(title="Error", description="Timed out.", color=self.bot.error_color),
1597+
view=None,
15811598
)
15821599

1583-
level_name = msg.content
1600+
level_name = view.value
15841601
level = self._parse_level(level_name)
1585-
if level == PermissionLevel.INVALID:
1586-
return await ctx.send(
1587-
embed=discord.Embed(
1588-
title="Error",
1589-
description=f"Invalid permission level: `{level_name}`. Aborting.",
1590-
color=self.bot.error_color,
1591-
)
1592-
)
15931602

15941603
# Confirmation
15951604
command_list_str = ", ".join(
15961605
f"`{c.qualified_name}`" for c in sorted(final_commands, key=lambda x: x.qualified_name)
15971606
)
15981607

1599-
# Truncate if too long for embed description
1600-
if len(command_list_str) > 2000:
1601-
command_list_str = command_list_str[:1997] + "..."
1608+
command_list_str = utils.return_or_truncate(command_list_str, 2048)
16021609

16031610
embed = discord.Embed(
16041611
title="Confirm Bulk Override",
1605-
description=f"**Level:** {level.name}\n\n**Commands:**\n{command_list_str}\n\n"
1606-
"Type `confirm` to apply these changes or `cancel` to abort.",
1612+
description=f"**Level:** {level.name}\n\n**Commands:**\n{command_list_str}",
16071613
color=self.bot.main_color,
16081614
)
1609-
await ctx.send(embed=embed)
16101615

1611-
try:
1612-
msg = await self.bot.wait_for(
1613-
"message",
1614-
check=lambda m: m.author == ctx.author
1615-
and m.channel == ctx.channel
1616-
and m.content.lower() in ("confirm", "cancel"),
1617-
timeout=30.0,
1618-
)
1619-
except asyncio.TimeoutError:
1620-
return await ctx.send(
1621-
embed=discord.Embed(
1622-
title="Error", description="Timed out. No changes applied.", color=self.bot.error_color
1623-
)
1624-
)
1616+
view = discord.ui.View()
1617+
view.add_item(utils.AcceptButton(custom_id="confirm", emoji="✅"))
1618+
view.add_item(utils.DenyButton(custom_id="cancel", emoji="❌"))
16251619

1626-
if msg.content.lower() == "cancel":
1627-
return await ctx.send(
1620+
await message.edit(embed=embed, view=view)
1621+
await view.wait()
1622+
1623+
if not view.value:
1624+
return await message.edit(
16281625
embed=discord.Embed(
16291626
title="Operation Aborted",
16301627
description="No changes have been applied.",
16311628
color=self.bot.error_color,
1632-
)
1629+
),
1630+
view=None,
16331631
)
16341632

16351633
# Apply changes
1636-
count = 0
16371634
for cmd in final_commands:
16381635
self.bot.config["override_command_level"][cmd.qualified_name] = level.name
1639-
count += 1
16401636

16411637
await self.bot.config.update()
16421638

1643-
await ctx.send(
1639+
await message.edit(
16441640
embed=discord.Embed(
16451641
title="Success",
1646-
description=f"Successfully updated permissions for {count} commands.",
1642+
description=f"Successfully updated permissions for {len(final_commands)} commands.",
16471643
color=self.bot.main_color,
1648-
)
1644+
),
1645+
view=None,
16491646
)
16501647

16511648
@permissions.command(name="add", usage="[command/level] [name] [user/role]")

0 commit comments

Comments
 (0)