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

feat(ext.bridge): add bridge_commands attribute #1787

Merged
merged 8 commits into from
Nov 20, 2022
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ These changes are available on the `master` branch, but have not yet been releas
order. ([#1636](https://github.com/Pycord-Development/pycord/pull/1636))
- Support for new thread attributes `total_message_sent` and `is_pinned`.
([#1636](https://github.com/Pycord-Development/pycord/pull/1636))
- Added `bridge_commands` attribute to `ext.bridge.Bot` for access to bridge command
objects. ([#1787](https://github.com/Pycord-Development/pycord/pull/1787))

### Fixed

Expand Down
18 changes: 18 additions & 0 deletions discord/ext/bridge/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations

from abc import ABC

from discord.interactions import Interaction
Expand All @@ -36,6 +38,21 @@


class BotBase(ABC):
_bridge_commands: list[BridgeCommand | BridgeCommandGroup]

@property
def bridge_commands(self) -> list[BridgeCommand | BridgeCommandGroup]:
"""Returns all of the bot's bridge commands."""

if cmds := getattr(self, "_bridge_commands", []):
self._bridge_commands = cmds = []

return cmds

@bridge_commands.setter
def bridge_commands(self, cmds):
self._bridge_commands = cmds

async def get_application_context(
self, interaction: Interaction, cls=None
) -> BridgeApplicationContext:
Expand All @@ -56,6 +73,7 @@ def add_bridge_command(self, command: BridgeCommand):
"""
# Ignore the type hinting error here. All subclasses of BotBase pass the type checks.
command.add_to(self) # type: ignore
self._bridge_commands.append(command)

def bridge_command(self, **kwargs):
"""A shortcut decorator that invokes :func:`bridge_command` and adds it to
Expand Down