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
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