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 11 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
2 changes: 0 additions & 2 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,6 @@ async def sync_commands(
guild_commands, guild_id=guild_id, method=method, force=force, delete_existing=delete_existing
)

global_permissions: List = []

for i in registered_commands:
cmd = get(
self.pending_application_commands,
Expand Down
10 changes: 5 additions & 5 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def __new__(cls, *args, **kwargs) -> SlashCommand:
self.__original_kwargs__ = kwargs.copy()
return self

def __init__(self, func: Callable, *args, **kwargs) -> None:
def __init__(self, func: Callable, **kwargs) -> None:
super().__init__(func, **kwargs)
if not asyncio.iscoroutinefunction(func):
raise TypeError("Callback must be a coroutine.")
Expand Down Expand Up @@ -1010,10 +1010,10 @@ def __init__(
parent: Optional[SlashCommandGroup] = None,
**kwargs,
) -> None:
validate_chat_input_name(name)
validate_chat_input_description(description)
self.name = str(name)
self.description = description
self.name = name
self.description = description or "No description provided"
validate_chat_input_name(self.name)
validate_chat_input_description(self.description)
Middledot marked this conversation as resolved.
Show resolved Hide resolved
Middledot marked this conversation as resolved.
Show resolved Hide resolved
self.input_type = SlashCommandOptionType.sub_command_group
self.subcommands: List[Union[SlashCommand, SlashCommandGroup]] = self.__initial_commands__
self.guild_ids = guild_ids
Expand Down
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
16 changes: 12 additions & 4 deletions discord/ext/bridge/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
DEALINGS IN THE SOFTWARE.
"""
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any, Optional, Union
from typing import Any, Optional, Union

from discord.commands import ApplicationContext
from discord.interactions import Interaction, InteractionMessage
Expand All @@ -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 @@ -140,6 +140,10 @@ async def _defer(self, *args, **kwargs) -> None:
async def _edit(self, *args, **kwargs) -> InteractionMessage:
return await self._get_super("edit")(*args, **kwargs)

@property
def is_app(self) -> bool:
return True
Middledot marked this conversation as resolved.
Show resolved Hide resolved


class BridgeExtContext(BridgeContext, Context):
"""
Expand Down Expand Up @@ -184,3 +188,7 @@ async def delete(
"""
if self._original_response_message:
await self._original_response_message.delete(delay=delay, reason=reason)

@property
def is_app(self) -> bool:
return False
Middledot marked this conversation as resolved.
Show resolved Hide resolved
Loading