Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Fix duplicate bridge cmds in default help cmd #2656

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ These changes are available on the `master` branch, but have not yet been releas
apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650))
- Fixed type annotations of cached properties.
([#2635](https://github.com/Pycord-Development/pycord/issues/2635))
- 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why tuple instead of set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unpack not possible with sets

):
"""|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
Loading