Skip to content

Commit ef8a5c2

Browse files
lorenzo132sebkuip
authored andcommitted
fix: strip mention prefixes - show valid commands before apply.
This aswell automatically skips invalid provided commands.
1 parent 9be3c4b commit ef8a5c2

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

cogs/utility.py

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

1498+
# Strip prefix from commands if present
1499+
prefixes = [self.bot.prefix, f"<@{self.bot.user.id}>", f"<@!{self.bot.user.id}>"]
14981500
if self.bot.prefix:
1499-
# Strip prefix from commands if present
1500-
# Note: This does not account for mention prefixes.
1501-
raw_commands = [
1502-
c[len(self.bot.prefix) :] if c.startswith(self.bot.prefix) else c for c in raw_commands
1503-
]
1501+
for i, cmd in enumerate(raw_commands):
1502+
for p in prefixes:
1503+
if cmd.startswith(p):
1504+
raw_commands[i] = cmd[len(p) :]
1505+
break
1506+
1507+
# Filter empty strings again after stripping prefixes
1508+
raw_commands = [c for c in raw_commands if c.strip()]
15041509

15051510
found_commands = []
15061511
invalid_commands = []
@@ -1513,10 +1518,17 @@ async def _bulk_override_flow(self, ctx):
15131518
invalid_commands.append(cmd_name)
15141519

15151520
if invalid_commands:
1521+
description = f"The following commands were not found:\n`{', '.join(invalid_commands)}`\n\n"
1522+
if found_commands:
1523+
found_list = ", ".join(c.qualified_name for c in found_commands)
1524+
found_list = utils.return_or_truncate(found_list, 1000)
1525+
description += f"The following commands **were** found:\n`{found_list}`\n\n"
1526+
1527+
description += "Do you want to continue with the valid commands?"
1528+
15161529
embed = discord.Embed(
15171530
title="Invalid Commands Found",
1518-
description=f"The following commands were not found:\n`{', '.join(invalid_commands)}`\n\n"
1519-
"Do you want to continue with the valid commands?",
1531+
description=description,
15201532
color=self.bot.error_color,
15211533
)
15221534
view = discord.ui.View()

0 commit comments

Comments
 (0)