Skip to content

Commit

Permalink
Cleanup ext.bridge docs (Pycord-Development#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
baronkobama authored Jun 29, 2022
1 parent ecadcc4 commit 5fdbb3f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion discord/ext/bridge/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def add_bridge_command(self, command: BridgeCommand):
command.add_to(self) # type: ignore

def bridge_command(self, **kwargs):
"""A shortcut decorator that invokes :func:`.bridge_command` and adds it to
"""A shortcut decorator that invokes :func:`~.bridge_command` and adds it to
the internal command list via :meth:`~.Bot.add_bridge_command`.
Returns
Expand Down
24 changes: 14 additions & 10 deletions discord/ext/bridge/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@

class BridgeContext(ABC):
"""
The base context class for compatibility commands. This class is an :class:`ABC` (abstract base class), which is
subclassed by :class:`BridgeExtContext` and :class:`BridgeApplicationContext`. The methods in this class are meant
to give parity between the two contexts, while still allowing for all of their functionality.
The base context class for compatibility commands. This class is an :term:`abstract base class` (also known as an
``abc``), which is subclassed by :class:`BridgeExtContext` and :class:`BridgeApplicationContext`. The methods in
this class are meant to give parity between the two contexts, while still allowing for all of their functionality.
When this is passed to a command, it will either be passed as :class:`BridgeExtContext`, or
:class:`BridgeApplicationContext`. Since they are two separate classes, it is quite simple to use :meth:`isinstance`
:class:`BridgeApplicationContext`. Since they are two separate classes, it is quite simple to use :func:`isinstance`
to make different functionality for each context. For example, if you want to respond to a command with the command
type that it was invoked with, you can do the following:
Expand Down Expand Up @@ -79,7 +79,7 @@ async def respond(
"""|coro|
Responds to the command with the respective response type to the current context. In :class:`BridgeExtContext`,
this will be :meth:`~.ExtContext.reply` while in :class:`BridgeApplicationContext`, this will be
this will be :meth:`~.Context.reply` while in :class:`BridgeApplicationContext`, this will be
:meth:`~.ApplicationContext.respond`.
"""
return await self._respond(*args, **kwargs)
Expand All @@ -97,8 +97,8 @@ async def defer(self, *args, **kwargs) -> None:
"""|coro|
Defers the command with the respective approach to the current context. In :class:`BridgeExtContext`, this will
be :meth:`~.ExtContext.trigger_typing` while in :class:`BridgeApplicationContext`, this will be
:meth:`~.ApplicationContext.defer`.
be :meth:`~discord.Messageable.trigger_typing` while in :class:`BridgeApplicationContext`, this will be
:attr:`~.ApplicationContext.defer`.
.. note::
There is no ``trigger_typing`` alias for this method. ``trigger_typing`` will always provide the same
Expand All @@ -111,7 +111,7 @@ async def edit(self, *args, **kwargs) -> Union[InteractionMessage, Message]:
Edits the original response message with the respective approach to the current context. In
:class:`BridgeExtContext`, this will have a custom approach where :meth:`.respond` caches the message to be
edited here. In :class:`BridgeApplicationContext`, this will be :meth:`~.ApplicationContext.edit`.
edited here. In :class:`BridgeApplicationContext`, this will be :attr:`~.ApplicationContext.edit`.
"""
return await self._edit(*args, **kwargs)

Expand All @@ -122,11 +122,15 @@ def _get_super(self, attr: str) -> Any:
class BridgeApplicationContext(BridgeContext, ApplicationContext):
"""
The application context class for compatibility commands. This class is a subclass of :class:`BridgeContext` and
:class:`ApplicationContext`. This class is meant to be used with :class:`BridgeCommand`.
:class:`~.ApplicationContext`. This class is meant to be used with :class:`BridgeCommand`.
.. versionadded:: 2.0
"""

def __init__(self, *args, **kwargs):
# This is needed in order to represent the correct class init signature on the docs
super().__init__(*args, **kwargs)

async def _respond(self, *args, **kwargs) -> Union[Interaction, WebhookMessage]:
return await self._get_super("respond")(*args, **kwargs)

Expand All @@ -140,7 +144,7 @@ async def _edit(self, *args, **kwargs) -> InteractionMessage:
class BridgeExtContext(BridgeContext, Context):
"""
The ext.commands context class for compatibility commands. This class is a subclass of :class:`BridgeContext` and
:class:`Context`. This class is meant to be used with :class:`BridgeCommand`.
:class:`~.Context`. This class is meant to be used with :class:`BridgeCommand`.
.. versionadded:: 2.0
"""
Expand Down
29 changes: 15 additions & 14 deletions discord/ext/bridge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,20 @@ class BridgeExtCommand(Command):


class BridgeCommand:
def __init__(self, callback, **kwargs):
"""
This is the base class for commands that are compatible with both traditional (prefix-based) commands and slash
commands.
"""
This is the base class for commands that are compatible with both traditional (prefix-based) commands and slash
commands.
Parameters
----------
callback: Callable[[BridgeContext, ...], Awaitable[Any]]
The callback to invoke when the command is executed. The first argument will be a :class:`BridgeContext`,
and any additional arguments will be passed to the callback. This callback must be a coroutine.
kwargs: Optional[Dict[str, Any]]
Keyword arguments that are directly passed to the respective command constructors.
"""
Parameters
----------
callback: Callable[[BridgeContext, ...], Awaitable[Any]]
The callback to invoke when the command is executed. The first argument will be a :class:`BridgeContext`,
and any additional arguments will be passed to the callback. This callback must be a coroutine.
kwargs: Optional[Dict[:class:`str`, Any]]
Keyword arguments that are directly passed to the respective command constructors.
"""

def __init__(self, callback, **kwargs):
self.callback = callback
self.kwargs = kwargs

Expand Down Expand Up @@ -107,7 +108,7 @@ def add_to(self, bot: Union[ExtBot, ExtAutoShardedBot]) -> None:
Parameters
----------
bot: Union[:class:`ExtBot`, :class:`ExtAutoShardedBot`]
bot: Union[:class:`.ExtBot`, :class:`.ExtAutoShardedBot`]
The bot to add the command to.
"""

Expand Down Expand Up @@ -206,7 +207,7 @@ def bridge_command(**kwargs):
Parameters
----------
kwargs: Optional[Dict[str, Any]]
kwargs: Optional[Dict[:class:`str`, Any]]
Keyword arguments that are directly passed to the respective command constructors.
"""

Expand Down
15 changes: 5 additions & 10 deletions docs/ext/bridge/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ Example usage:
.. _discord_ext_bridge_api:

API Reference
-------------
===============

Bots
~~~~
-----

.. attributetable:: discord.ext.bridge.Bot

Expand All @@ -62,13 +62,8 @@ Bots
.. autoclass:: discord.ext.bridge.AutoShardedBot
:members:

.. automethod:: Bot.add_bridge_command()

.. automethod:: Bot.bridge_command()
:decorator:

Commands
~~~~~~~~
---------

.. attributetable:: discord.ext.bridge.BridgeCommand

Expand All @@ -85,7 +80,7 @@ Commands
:members:

Context
~~~~~~~
--------

.. attributetable:: discord.ext.bridge.BridgeContext

Expand All @@ -101,4 +96,4 @@ Context
.. attributetable:: discord.ext.bridge.BridgeExtContext

.. autoclass:: discord.ext.bridge.BridgeExtContext
:members:
:members:

0 comments on commit 5fdbb3f

Please sign in to comment.