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

ext.bridge improvements #1496

Merged
merged 35 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3358f81
Initial ext.bridge redesign
Middledot Jul 12, 2022
d70c2a0
Merge branch 'Pycord-Development:master' into ext-bridge-rewrite
Middledot Jul 12, 2022
6464bf7
Doc changes
Middledot Jul 12, 2022
c2e7105
Make `map_to` a decorator instead of a parameter
Middledot Jul 12, 2022
fb5cee0
Merge branch 'ext-bridge-rewrite' of https://github.com/Middledot/pyc…
Middledot Jul 12, 2022
978a90d
Implement attachment converters
Middledot Jul 12, 2022
74d89c5
Code Cleanup
Middledot Jul 12, 2022
e2a083a
Correct is_app for prefix commands
Middledot Jul 12, 2022
28e3c78
Add proxy localization attrs & document ...
Middledot Jul 12, 2022
dc39280
Merge branch 'master' into ext-bridge-rewrite
Lulalaby Jul 12, 2022
b3fd83f
Apply code suggestions
Middledot Jul 13, 2022
7778f09
Merge branch 'master' into ext-bridge-rewrite
Lulalaby Jul 13, 2022
002e506
Merge branch 'master' into ext-bridge-rewrite
Middledot Jul 21, 2022
d4d8b2d
Merge branch 'master' into ext-bridge-rewrite
Middledot Jul 24, 2022
d9d0adf
Apply code suggestions
Middledot Jul 26, 2022
b266d4e
Merge branch 'master' into ext-bridge-rewrite
Lulalaby Jul 27, 2022
d325e6e
fix: bridge groups
Middledot Jul 30, 2022
5a789e6
feat: add BridgeSlashGroup
Middledot Jul 30, 2022
0e71041
fix: apply code suggestions
Middledot Jul 31, 2022
cebd8a2
revert: fix SlashCommandGroups without...
Middledot Jul 31, 2022
2731bb6
revert: fix SlashCommandGroups without...
Middledot Jul 31, 2022
8790685
fix: remove BaseBridgeCommand docs
Middledot Jul 31, 2022
6cdd464
fix: incorrect subclass + typehint
Middledot Jul 31, 2022
3395177
Merge branch 'master' into ext-bridge-rewrite
Middledot Aug 1, 2022
a3dc6c5
fix: import error
Middledot Aug 1, 2022
9509c98
Merge branch 'master' into ext-bridge-rewrite
Dorukyum Aug 2, 2022
6c43b56
fix: error
Middledot Aug 2, 2022
2833336
fix: other error
Middledot Aug 2, 2022
1f3fa12
feat: example
Middledot Aug 2, 2022
4e77a36
Merge branch 'master' into ext-bridge-rewrite
Middledot Aug 9, 2022
51c1094
Update discord/ext/bridge/core.py
Lulalaby Aug 12, 2022
b17ccfb
Merge branch 'ext-bridge-rewrite' of https://github.com/Middledot/pyc…
Middledot Aug 12, 2022
e936a7e
Merge branch 'master' into ext-bridge-rewrite
BobDotCom Aug 12, 2022
7bf3631
Merge branch 'ext-bridge-rewrite' of https://github.com/Middledot/pyc…
Middledot Aug 12, 2022
00dce54
remove __future__ import
Middledot Aug 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion discord/ext/bridge/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ..commands import AutoShardedBot as ExtAutoShardedBot
from ..commands import Bot as ExtBot
from .context import BridgeApplicationContext, BridgeExtContext
from .core import BridgeCommand, bridge_command
from .core import BridgeCommand, BridgeCommandGroup, bridge_command, bridge_group

__all__ = ("Bot", "AutoShardedBot")

Expand Down Expand Up @@ -75,6 +75,22 @@ def decorator(func) -> BridgeCommand:

return decorator

def bridge_group(self, **kwargs):
"""A decorator that is used to wrap a function as a bridge command group.

Parameters
----------
kwargs: Optional[Dict[:class:`str`, Any]]
Keyword arguments that are directly passed to the respective command constructors. (:class:`.SlashCommandGroup` and :class:`.ext.commands.Group`)
"""

def decorator(func) -> BridgeCommandGroup:
result = bridge_group(**kwargs)(func)
self.add_bridge_command(result)
return result

return decorator


class Bot(BotBase, ExtBot):
"""Represents a discord bot, with support for cross-compatibility between command types.
Expand Down
11 changes: 8 additions & 3 deletions discord/ext/bridge/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class BridgeContext(ABC):

@bot.bridge_command()
async def example(ctx: BridgeContext):
if isinstance(ctx, BridgeExtContext):
command_type = "Traditional (prefix-based) command"
elif isinstance(ctx, BridgeApplicationContext):
if ctx.is_app:
command_type = "Application command"
else:
command_type = "Traditional (prefix-based) command"
await ctx.send(f"This command was invoked with a(n) {command_type}.")

.. versionadded:: 2.0
Expand Down Expand Up @@ -118,6 +118,11 @@ async def edit(self, *args, **kwargs) -> Union[InteractionMessage, Message]:
def _get_super(self, attr: str) -> Any:
return getattr(super(), attr)

@property
def is_app(self) -> bool:
"""bool: Whether the context is an :class:`BridgeApplicationContext` or not."""
return isinstance(self, BridgeApplicationContext)


class BridgeApplicationContext(BridgeContext, ApplicationContext):
"""
Expand Down
Loading