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

Implement user installations #1952

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions changes/1952.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for user install commands
34 changes: 34 additions & 0 deletions hikari/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6684,6 +6684,12 @@ async def create_slash_command(
] = undefined.UNDEFINED,
dm_enabled: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
nsfw: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
integration_types: undefined.UndefinedOr[
typing.Sequence[applications.ApplicationIntegrationType]
] = undefined.UNDEFINED,
contexts: undefined.UndefinedOr[
typing.Sequence[applications.ApplicationInstallationContextType]
] = undefined.UNDEFINED,
) -> commands.SlashCommand:
r"""Create an application slash command.

Expand Down Expand Up @@ -6719,6 +6725,10 @@ async def create_slash_command(
This can only be applied to non-guild commands.
nsfw
Whether this command should be age-restricted.
integration_types
The integration types for this command.
contexts
The contexts for this command.

Returns
-------
Expand Down Expand Up @@ -6758,6 +6768,12 @@ async def create_context_menu_command(
] = undefined.UNDEFINED,
dm_enabled: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
nsfw: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
integration_types: undefined.UndefinedOr[
typing.Sequence[applications.ApplicationIntegrationType]
] = undefined.UNDEFINED,
contexts: undefined.UndefinedOr[
typing.Sequence[applications.ApplicationInstallationContextType]
] = undefined.UNDEFINED,
) -> commands.ContextMenuCommand:
r"""Create an application context menu command.

Expand Down Expand Up @@ -6788,6 +6804,10 @@ async def create_context_menu_command(
This can only be applied to non-guild commands.
nsfw
Whether this command should be age-restricted.
integration_types
The integration types for this command.
contexts
The contexts for this command.

Returns
-------
Expand Down Expand Up @@ -6820,6 +6840,10 @@ async def set_application_commands(
) -> typing.Sequence[commands.PartialCommand]:
"""Set the commands for an application.

!!! note
When creating user commands, make sure to not pass the `guild` argument.
There is no feedback from Discord when this happens and commands will not be created properly

!!! warning
Any existing commands not included in the provided commands array
will be deleted.
Expand Down Expand Up @@ -6872,6 +6896,12 @@ async def edit_application_command(
undefined.UndefinedType, int, permissions_.Permissions
] = undefined.UNDEFINED,
dm_enabled: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
integration_types: undefined.UndefinedOr[
typing.Sequence[applications.ApplicationIntegrationType]
] = undefined.UNDEFINED,
contexts: undefined.UndefinedOr[
typing.Sequence[applications.ApplicationInstallationContextType]
] = undefined.UNDEFINED,
) -> commands.PartialCommand:
"""Edit a registered application command.

Expand Down Expand Up @@ -6903,6 +6933,10 @@ async def edit_application_command(
Whether this command is enabled in DMs with the bot.

This can only be applied to non-guild commands.
integration_types
The integration types for this command.
contexts
The contexts for this command.

Returns
-------
Expand Down
33 changes: 33 additions & 0 deletions hikari/api/special_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

from typing_extensions import Self

from hikari import applications
from hikari import channels
from hikari import colors
from hikari import commands
Expand Down Expand Up @@ -1124,6 +1125,38 @@ def set_name_localizations(
Object of this command builder.
"""

@abc.abstractmethod
def set_integration_types(
self, integration_types: typing.Sequence[applications.ApplicationIntegrationType], /
) -> Self:
"""Set the command integration types.

Parameters
----------
integration_types
Integration types that show where command would be shown up

Returns
-------
CommandBuilder
Object of this command builder for chained calls.
"""

@abc.abstractmethod
def set_contexts(self, contexts: typing.Sequence[applications.ApplicationInstallationContextType], /) -> Self:
"""Set the command contexts.

Parameters
----------
contexts
Where command can be used

Returns
-------
CommandBuilder
Object of this command builder for chained calls.
"""

@abc.abstractmethod
def build(self, entity_factory: entity_factory_.EntityFactory, /) -> typing.MutableMapping[str, typing.Any]:
"""Build a JSON object from this builder.
Expand Down
32 changes: 32 additions & 0 deletions hikari/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"ApplicationRoleConnectionMetadataRecordType",
"ApplicationRoleConnectionMetadataRecord",
"get_token_id",
"ApplicationIntegrationType",
"ApplicationInstallationContextType",
)

import base64
Expand All @@ -71,6 +73,31 @@
from hikari import webhooks


@typing.final
class ApplicationIntegrationType(int, enums.Enum):
"""The known integration types."""

GUILD_INSTALL = 0
"""A guild install command integration type"""

USER_INSTALL = 1
"""A user install command integration type"""


@typing.final
class ApplicationInstallationContextType(int, enums.Enum):
"""The known installation context types."""

GUILD = 0
"""Interaction can be used within server"""

BOT_DM = 1
"""Interaction can be used within DM's"""

PRIVATE_CHANNEL = 2
"""Interaction can be used within group DM's and DM's"""


@typing.final
class ApplicationFlags(enums.Flag):
"""The known application flag bits."""
Expand Down Expand Up @@ -632,6 +659,11 @@ class Application(guilds.PartialApplication):
install_parameters: typing.Optional[ApplicationInstallParameters] = attrs.field(eq=False, hash=False, repr=False)
"""Settings for the application's default in-app authorization link, if enabled."""

integration_types_config: typing.Optional[
typing.Mapping[ApplicationIntegrationType, ApplicationInstallParameters]
] = attrs.field(eq=False, hash=False, repr=False)
"""Default scopes and permissions for each supported installation context."""
davfsa marked this conversation as resolved.
Show resolved Hide resolved

approximate_guild_count: int = attrs.field(eq=False, hash=False, repr=False)
"""The approximate number of guilds this application is part of."""

Expand Down
11 changes: 11 additions & 0 deletions hikari/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from hikari.internal import enums

if typing.TYPE_CHECKING:
from hikari import applications
from hikari import channels
from hikari import guilds
from hikari import locales
Expand Down Expand Up @@ -265,6 +266,16 @@ class PartialCommand(snowflakes.Unique):
)
"""A mapping of name localizations for this command."""

integration_types: typing.Sequence[applications.ApplicationIntegrationType] = attrs.field(
eq=False, hash=False, repr=True
)
"""A sequence of command integration types."""

contexts: typing.Sequence[applications.ApplicationInstallationContextType] = attrs.field(
eq=False, hash=False, repr=True
)
"""A sequence of command contexts."""

async def fetch_self(self) -> PartialCommand:
"""Fetch an up-to-date version of this command object.

Expand Down
Loading
Loading