-
Notifications
You must be signed in to change notification settings - Fork 138
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
refactor app command sync and other fixes #666
Closed
onerandomusername
wants to merge
19
commits into
DisnakeDev:master
from
onerandomusername:refactor/app-commands
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ed76909
feat: add ID attributes to ApplicationCommand classes
onerandomusername 8e6cc3c
feat: make InvokableCommands also subclasses of ApplicationCommand cl…
onerandomusername a62168a
feat: support providing ids to sync commands
onerandomusername 8595828
fix: if a user-provided command ID is invalid ignore it
onerandomusername 237ac58
feat: move command sync config to flags
onerandomusername a625e20
feat: add never_delete and global or guild command syncing options
onerandomusername a1356e8
chore: invert never_delete to allow deletion
onerandomusername 8fca143
feat: containerize each slash command type
onerandomusername 9230d8e
"fix" pyright issues
onerandomusername fe9d277
fix: sync command ids when bulk updating guild slash commands
onerandomusername ec79472
chore: add parents properties
onerandomusername e5c619b
feat: add slash command mentions
onerandomusername 7cec79e
fix some bugs
onerandomusername 6468099
chore: remove reassigning imported attributes
onerandomusername 9695975
remove removed parameter documentation
onerandomusername 7eda7e4
chore: resolve lint and typing issues
onerandomusername e824ed8
Revert "feat: move command sync config to flags"
onerandomusername 7115195
chore: remove other parts of command sync
onerandomusername 911f124
Merge branch 'master' into refactor/app-commands
onerandomusername File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ | |
from __future__ import annotations | ||
|
||
import asyncio | ||
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Sequence, Tuple, Union | ||
from typing import TYPE_CHECKING, Any, Callable, Dict, Literal, Optional, Sequence, Tuple, Union | ||
|
||
from disnake.app_commands import MessageCommand, UserCommand | ||
from disnake.enums import ApplicationCommandType | ||
from disnake.i18n import Localized | ||
from disnake.permissions import Permissions | ||
|
||
|
@@ -16,7 +17,7 @@ | |
if TYPE_CHECKING: | ||
from typing_extensions import ParamSpec | ||
|
||
from disnake.i18n import LocalizedOptional | ||
from disnake.i18n import LocalizationValue, LocalizedOptional | ||
from disnake.interactions import ( | ||
ApplicationCommandInteraction, | ||
MessageCommandInteraction, | ||
|
@@ -30,7 +31,7 @@ | |
__all__ = ("InvokableUserCommand", "InvokableMessageCommand", "user_command", "message_command") | ||
|
||
|
||
class InvokableUserCommand(InvokableApplicationCommand): | ||
class InvokableUserCommand(InvokableApplicationCommand, UserCommand): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point of subclassing |
||
"""A class that implements the protocol for a bot user command (context menu). | ||
|
||
These are not created manually, instead they are created via the | ||
|
@@ -77,6 +78,7 @@ def __init__( | |
default_member_permissions: Optional[Union[Permissions, int]] = None, | ||
guild_ids: Optional[Sequence[int]] = None, | ||
auto_sync: Optional[bool] = None, | ||
id: Optional[int] = None, | ||
**kwargs, | ||
): | ||
name_loc = Localized._cast(name, False) | ||
|
@@ -101,8 +103,23 @@ def __init__( | |
name=name_loc._upgrade(self.name), | ||
dm_permission=dm_permission and not self._guild_only, | ||
default_member_permissions=default_member_permissions, | ||
id=id, | ||
) | ||
|
||
self._name_localised = name_loc | ||
|
||
@property | ||
def type(self) -> Literal[ApplicationCommandType.user]: | ||
return ApplicationCommandType.user | ||
|
||
@property | ||
def qualified_name(self) -> str: | ||
return self.name | ||
|
||
@property | ||
def name_localizations(self) -> LocalizationValue: | ||
return self._name_localised.localizations | ||
|
||
async def _call_external_error_handlers( | ||
self, inter: ApplicationCommandInteraction, error: CommandError | ||
) -> None: | ||
|
@@ -130,7 +147,7 @@ async def __call__( | |
await safe_call(self.callback, interaction, *args, **kwargs) | ||
|
||
|
||
class InvokableMessageCommand(InvokableApplicationCommand): | ||
class InvokableMessageCommand(InvokableApplicationCommand, MessageCommand): | ||
"""A class that implements the protocol for a bot message command (context menu). | ||
|
||
These are not created manually, instead they are created via the | ||
|
@@ -177,6 +194,7 @@ def __init__( | |
default_member_permissions: Optional[Union[Permissions, int]] = None, | ||
guild_ids: Optional[Sequence[int]] = None, | ||
auto_sync: Optional[bool] = None, | ||
id: Optional[int] = None, | ||
**kwargs, | ||
): | ||
name_loc = Localized._cast(name, False) | ||
|
@@ -195,7 +213,21 @@ def __init__( | |
name=name_loc._upgrade(self.name), | ||
dm_permission=dm_permission and not self._guild_only, | ||
default_member_permissions=default_member_permissions, | ||
id=id, | ||
) | ||
self._name_localised = name_loc | ||
|
||
@property | ||
def type(self) -> Literal[ApplicationCommandType.message]: | ||
return ApplicationCommandType.message | ||
|
||
@property | ||
def qualified_name(self) -> str: | ||
return self.name | ||
|
||
@property | ||
def name_localizations(self) -> LocalizationValue: | ||
return self._name_localised.localizations | ||
|
||
async def _call_external_error_handlers( | ||
self, inter: ApplicationCommandInteraction, error: CommandError | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to have 2 app commands of different types (or guilds) with identical names, so this should be modified