Skip to content

Commit

Permalink
fix: 🐛 Fix duplicate bridge cmds in default help cmd (#2656)
Browse files Browse the repository at this point in the history

Signed-off-by: Paillat <me@paillat.dev>
Signed-off-by: Lala Sabathil <lala@pycord.dev>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
  • Loading branch information
Paillat-dev and Lulalaby authored Jan 28, 2025
1 parent 8c3a621 commit aa13d82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2679](https://github.com/Pycord-Development/pycord/pull/2679))
- Fixed unexpected backoff behavior in the handling of task failures
([#2700](https://github.com/Pycord-Development/pycord/pull/2700)).
- Fixed `BridgeCommand` duplicate in default help command.
([#2656](https://github.com/Pycord-Development/pycord/pull/2656))

### Changed

Expand Down
28 changes: 20 additions & 8 deletions discord/ext/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
import functools
import itertools
import re
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any

import discord.utils
from discord.ext import bridge

from .core import Command, Group
from .errors import CommandError
Expand Down Expand Up @@ -550,7 +551,9 @@ def subcommand_not_found(self, command, string):
)
return f'Command "{command.qualified_name}" has no subcommands.'

async def filter_commands(self, commands, *, sort=False, key=None):
async def filter_commands(
self, commands, *, sort=False, key=None, exclude: tuple[Any] | None = None
):
"""|coro|
Returns a filtered list of commands and optionally sorts them.
Expand All @@ -568,6 +571,8 @@ async def filter_commands(self, commands, *, sort=False, key=None):
An optional key function to pass to :func:`py:sorted` that
takes a :class:`Command` as its sole parameter. If ``sort`` is
passed as ``True`` then this will default as the command name.
exclude: Optional[Tuple[Any, ...]]
A tuple of command types to exclude from the filter.
Returns
-------
Expand All @@ -579,15 +584,18 @@ async def filter_commands(self, commands, *, sort=False, key=None):
key = lambda c: c.name

# Ignore Application Commands because they don't have hidden/docs
prefix_commands = [
new_commands = [
command
for command in commands
if not isinstance(command, discord.commands.ApplicationCommand)
if not isinstance(
command,
(discord.commands.ApplicationCommand, *(exclude if exclude else ())),
)
]
iterator = (
prefix_commands
new_commands
if self.show_hidden
else filter(lambda c: not c.hidden, prefix_commands)
else filter(lambda c: not c.hidden, new_commands)
)

if self.verify_checks is False:
Expand Down Expand Up @@ -1107,7 +1115,9 @@ async def send_cog_help(self, cog):
self.paginator.add_line(cog.description, empty=True)

filtered = await self.filter_commands(
cog.get_commands(), sort=self.sort_commands
cog.get_commands(),
sort=self.sort_commands,
exclude=(bridge.BridgeExtCommand,),
)
self.add_indented_commands(filtered, heading=self.commands_heading)

Expand Down Expand Up @@ -1357,7 +1367,9 @@ async def send_cog_help(self, cog):
self.paginator.add_line(cog.description, empty=True)

filtered = await self.filter_commands(
cog.get_commands(), sort=self.sort_commands
cog.get_commands(),
sort=self.sort_commands,
exclude=(bridge.BridgeExtCommand,),
)
if filtered:
self.paginator.add_line(f"**{cog.qualified_name} {self.commands_heading}**")
Expand Down

0 comments on commit aa13d82

Please sign in to comment.