Skip to content

Commit

Permalink
feat(ext.bridge): add bridge_commands attribute (#1787)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Nov 20, 2022
1 parent 0ef62b8 commit 40fbdbf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
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

0 comments on commit 40fbdbf

Please sign in to comment.