Skip to content

Commit 20a2b89

Browse files
committed
fix: strip mention prefixes - show valid commands before apply.
This aswell automatically skips invalid provided commands.
1 parent 5723b54 commit 20a2b89

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

cogs/utility.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,12 +1469,17 @@ async def _bulk_override_flow(self, ctx):
14691469
# Filter empty strings from split
14701470
raw_commands = [c for c in raw_commands if c.strip()]
14711471

1472+
# Strip prefix from commands if present
1473+
prefixes = [self.bot.prefix, f"<@{self.bot.user.id}>", f"<@!{self.bot.user.id}>"]
14721474
if self.bot.prefix:
1473-
# Strip prefix from commands if present
1474-
# Note: This does not account for mention prefixes.
1475-
raw_commands = [
1476-
c[len(self.bot.prefix) :] if c.startswith(self.bot.prefix) else c for c in raw_commands
1477-
]
1475+
for i, cmd in enumerate(raw_commands):
1476+
for p in prefixes:
1477+
if cmd.startswith(p):
1478+
raw_commands[i] = cmd[len(p) :]
1479+
break
1480+
1481+
# Filter empty strings again after stripping prefixes
1482+
raw_commands = [c for c in raw_commands if c.strip()]
14781483

14791484
found_commands = []
14801485
invalid_commands = []
@@ -1487,10 +1492,17 @@ async def _bulk_override_flow(self, ctx):
14871492
invalid_commands.append(cmd_name)
14881493

14891494
if invalid_commands:
1495+
description = f"The following commands were not found:\n`{', '.join(invalid_commands)}`\n\n"
1496+
if found_commands:
1497+
found_list = ", ".join(c.qualified_name for c in found_commands)
1498+
found_list = utils.return_or_truncate(found_list, 1000)
1499+
description += f"The following commands **were** found:\n`{found_list}`\n\n"
1500+
1501+
description += "Do you want to continue with the valid commands?"
1502+
14901503
embed = discord.Embed(
14911504
title="Invalid Commands Found",
1492-
description=f"The following commands were not found:\n`{', '.join(invalid_commands)}`\n\n"
1493-
"Do you want to continue with the valid commands?",
1505+
description=description,
14941506
color=self.bot.error_color,
14951507
)
14961508
view = discord.ui.View()

0 commit comments

Comments
 (0)