From 40fbdbfaf7d8952bebdeb1a5c735d853680921aa Mon Sep 17 00:00:00 2001 From: Middledot <78228142+Middledot@users.noreply.github.com> Date: Sun, 20 Nov 2022 02:01:55 -0500 Subject: [PATCH] feat(ext.bridge): add bridge_commands attribute (#1787) * feat(ext.bridge): add bridge_commands attribute * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore(changelog): add changelog entry * chore(changelog): clarify Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com> --- CHANGELOG.md | 2 ++ discord/ext/bridge/bot.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92c85d7f97..5b61e6a663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/discord/ext/bridge/bot.py b/discord/ext/bridge/bot.py index 3db78d5f42..42b3ff2540 100644 --- a/discord/ext/bridge/bot.py +++ b/discord/ext/bridge/bot.py @@ -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 @@ -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: @@ -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