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 modals #1002

Merged
merged 51 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5b7d524
Partial modal implementation
thesadru Feb 3, 2022
0f5933c
Add abstract methods and documentation
thesadru Feb 4, 2022
3514b90
Add modal response builders
thesadru Feb 4, 2022
626168c
Test entity factory modal methods
thesadru Feb 4, 2022
b2364aa
Export modal_interactions
thesadru Feb 9, 2022
6726e9a
implement responding with rest bot
thesadru Feb 9, 2022
04318d4
Add helper methods to ModalInteraction
thesadru Feb 12, 2022
76a685d
Clean up documentation
thesadru Feb 14, 2022
f19749e
Test TextInput and ModalInteraction
thesadru Feb 22, 2022
cf0faa3
Test rest modal response
thesadru Feb 22, 2022
cb69929
Give style a default value
thesadru Feb 25, 2022
6e3add7
Resolve some suggestions
thesadru Mar 5, 2022
5416fb9
merge master
thesadru Mar 13, 2022
8c9e335
Export modal interactions
thesadru Mar 13, 2022
e51c1f8
Separate modals to another mixin
thesadru Mar 25, 2022
fedbdb7
Temporarily freeze jinja2 to 3.0.3 (#1098)
davfsa Mar 25, 2022
80171cc
Remove useless import
thesadru Mar 25, 2022
42c1d5f
Improve naming
thesadru Mar 25, 2022
ea870b9
increase test coverage
thesadru Mar 25, 2022
a7e9b04
Get rid of ModalInteractionActionRow
thesadru Apr 1, 2022
c0f419c
Switch to using tuples for __all__ (merge)
thesadru Apr 1, 2022
37d4ac5
Remove redundant property docstrings
thesadru Apr 5, 2022
934b0b1
Remove parent_message in interactions
thesadru Apr 5, 2022
983dda8
Make the towncrier changelog entry somewhat sensible
thesadru Apr 5, 2022
b5339a6
Fix inconsistent wording in property docstrings
thesadru Apr 5, 2022
2fe7006
Do recommended changes
thesadru Apr 6, 2022
55300a6
Merge branch 'master' into feat/modal
davfsa Jul 6, 2022
4a13002
Fix typing
hypergonial Jul 6, 2022
194a24d
Adjust docstrings
hypergonial Jul 6, 2022
dd88abd
Add app_permissions
hypergonial Jul 6, 2022
8b98246
drop ActionRowComponent in annotation
thesadru Aug 22, 2022
c80b0f0
format
thesadru Aug 22, 2022
844cc98
Fix create_modal_response docstring
thesadru Aug 22, 2022
ec79d79
Typo in docstring
thesadru Aug 22, 2022
325de78
Merge branch 'master' into feat/modal
thesadru Aug 22, 2022
52e7948
Migrate to separate modal components
thesadru Aug 22, 2022
85e142a
Merge branch 'master' into feat/modal
thesadru Aug 27, 2022
bf5ace5
Merge branch 'master' into feat/modal
davfsa Sep 22, 2022
a1d6a8e
Merge branch 'master' into feat/modal
davfsa Sep 23, 2022
3338f58
Fix issues with rebase
davfsa Sep 23, 2022
3e1b40e
Merge branch 'master' into feat/modal
davfsa Oct 28, 2022
04a6922
Finish modals off
davfsa Oct 29, 2022
86efe0a
Merge branch 'master' into feat/modal
davfsa Nov 12, 2022
ccbe041
Generalize modals
davfsa Nov 20, 2022
baf9070
Fix tests
davfsa Nov 20, 2022
c810e41
Documentation and exposing typehints
davfsa Nov 20, 2022
a118854
Remove duplicate slot
davfsa Nov 20, 2022
08ff5fc
Switch message action row types to class specializations
davfsa Dec 4, 2022
f94c138
Merge branch 'master' into feat/modal
davfsa Dec 4, 2022
03f3f72
Add missing test cases
davfsa Dec 4, 2022
5c9053a
Fix flake8 issue
davfsa Dec 4, 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
1 change: 1 addition & 0 deletions changes/1002.deprecation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate `RESTClientImpl.build_action_row` in favour of `RESTClientImpl.build_message_action_row`.
2 changes: 2 additions & 0 deletions changes/1002.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Implement modal interactions.
- Additionally, it is now guaranteed (typing-wise) that top level components will be an action row
2 changes: 2 additions & 0 deletions hikari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from hikari.colors import *
from hikari.colours import *
from hikari.commands import *
from hikari.components import *
from hikari.embeds import *
from hikari.emojis import *
from hikari.errors import *
Expand Down Expand Up @@ -105,6 +106,7 @@
from hikari.interactions.base_interactions import *
from hikari.interactions.command_interactions import *
from hikari.interactions.component_interactions import *
from hikari.interactions.modal_interactions import *
from hikari.invites import *
from hikari.iterators import *
from hikari.locales import *
Expand Down
2 changes: 2 additions & 0 deletions hikari/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ from hikari.channels import *
from hikari.colors import *
from hikari.colours import *
from hikari.commands import *
from hikari.components import *
from hikari.embeds import *
from hikari.emojis import *
from hikari.errors import *
Expand Down Expand Up @@ -78,6 +79,7 @@ from hikari.intents import *
from hikari.interactions.base_interactions import *
from hikari.interactions.command_interactions import *
from hikari.interactions.component_interactions import *
from hikari.interactions.modal_interactions import *
from hikari.invites import *
from hikari.iterators import *
from hikari.locales import *
Expand Down
16 changes: 16 additions & 0 deletions hikari/api/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from hikari.interactions import base_interactions
from hikari.interactions import command_interactions
from hikari.interactions import component_interactions
from hikari.interactions import modal_interactions
from hikari.internal import data_binding


Expand Down Expand Up @@ -1298,6 +1299,21 @@ def deserialize_command_interaction(
The deserialized command interaction object.
"""

@abc.abstractmethod
def deserialize_modal_interaction(self, payload: data_binding.JSONObject) -> modal_interactions.ModalInteraction:
"""Parse a raw payload from Discord into a modal interaction object.
Parameters
----------
payload : hikari.internal.data_binding.JSONObject
The JSON payload to deserialize.
Returns
-------
hikari.interactions.modal_interactions.ModalInteraction
The deserialized modal interaction object.
"""

@abc.abstractmethod
def deserialize_interaction(self, payload: data_binding.JSONObject) -> base_interactions.PartialInteraction:
"""Parse a raw payload from Discord into a interaction object.
Expand Down
34 changes: 30 additions & 4 deletions hikari/api/interaction_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
from hikari.interactions import base_interactions
from hikari.interactions import command_interactions
from hikari.interactions import component_interactions
from hikari.interactions import modal_interactions

_InteractionT_co = typing.TypeVar("_InteractionT_co", bound=base_interactions.PartialInteraction, covariant=True)
_ResponseT_co = typing.TypeVar("_ResponseT_co", bound=special_endpoints.InteractionResponseBuilder, covariant=True)
_MessageResponseBuilderT = typing.Union[
special_endpoints.InteractionDeferredBuilder,
special_endpoints.InteractionMessageBuilder,
]
_ModalOrMessageResponseBuilder = typing.Union[
_MessageResponseBuilderT,
special_endpoints.InteractionModalBuilder,
]


ListenerT = typing.Callable[["_InteractionT_co"], typing.Awaitable["_ResponseT_co"]]
Expand Down Expand Up @@ -142,14 +147,14 @@ async def on_interaction(self, body: bytes, signature: bytes, timestamp: bytes)
@abc.abstractmethod
def get_listener(
self, interaction_type: typing.Type[command_interactions.CommandInteraction], /
) -> typing.Optional[ListenerT[command_interactions.CommandInteraction, _MessageResponseBuilderT]]:
) -> typing.Optional[ListenerT[command_interactions.CommandInteraction, _ModalOrMessageResponseBuilder]]:
...

@typing.overload
@abc.abstractmethod
def get_listener(
self, interaction_type: typing.Type[component_interactions.ComponentInteraction], /
) -> typing.Optional[ListenerT[component_interactions.ComponentInteraction, _MessageResponseBuilderT]]:
) -> typing.Optional[ListenerT[component_interactions.ComponentInteraction, _ModalOrMessageResponseBuilder]]:
...

@typing.overload
Expand All @@ -161,6 +166,13 @@ def get_listener(
]:
...

@typing.overload
@abc.abstractmethod
def get_listener(
self, interaction_type: typing.Type[modal_interactions.ModalInteraction], /
) -> typing.Optional[ListenerT[modal_interactions.ModalInteraction, _MessageResponseBuilderT]]:
...

@typing.overload
@abc.abstractmethod
def get_listener(
Expand Down Expand Up @@ -191,7 +203,7 @@ def get_listener(
def set_listener(
self,
interaction_type: typing.Type[command_interactions.CommandInteraction],
listener: typing.Optional[ListenerT[command_interactions.CommandInteraction, _MessageResponseBuilderT]],
listener: typing.Optional[ListenerT[command_interactions.CommandInteraction, _ModalOrMessageResponseBuilder]],
/,
*,
replace: bool = False,
Expand All @@ -203,7 +215,9 @@ def set_listener(
def set_listener(
self,
interaction_type: typing.Type[component_interactions.ComponentInteraction],
listener: typing.Optional[ListenerT[component_interactions.ComponentInteraction, _MessageResponseBuilderT]],
listener: typing.Optional[
ListenerT[component_interactions.ComponentInteraction, _ModalOrMessageResponseBuilder]
],
/,
*,
replace: bool = False,
Expand All @@ -224,6 +238,18 @@ def set_listener(
) -> None:
...

@typing.overload
@abc.abstractmethod
def set_listener(
self,
interaction_type: typing.Type[modal_interactions.ModalInteraction],
listener: typing.Optional[ListenerT[modal_interactions.ModalInteraction, _MessageResponseBuilderT]],
/,
*,
replace: bool = False,
) -> None:
...

@abc.abstractmethod
def set_listener(
self,
Expand Down
69 changes: 66 additions & 3 deletions hikari/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7977,6 +7977,23 @@ def interaction_message_builder(
The interaction message response builder object.
"""

@abc.abstractmethod
def interaction_modal_builder(self, title: str, custom_id: str) -> special_endpoints.InteractionModalBuilder:
"""Create a builder for a modal interaction response.
Parameters
----------
title : builtins.str
The title that will show up in the modal.
custom_id : builtins.str
Developer set custom ID used for identifying interactions with this modal.
Returns
-------
hikari.api.special_endpoints.InteractionModalBuilder
The interaction modal response builder object.
"""

@abc.abstractmethod
async def fetch_interaction_response(
self, application: snowflakes.SnowflakeishOr[guilds.PartialApplication], token: str
Expand Down Expand Up @@ -8378,13 +8395,59 @@ async def create_autocomplete_response(
If an internal error occurs on Discord while handling the request.
"""

async def create_modal_response(
self,
interaction: snowflakes.SnowflakeishOr[base_interactions.PartialInteraction],
token: str,
*,
title: str,
custom_id: str,
component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED,
components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED,
) -> None:
"""Create a response by sending a modal.
Parameters
----------
interaction : hikari.snowflakes.SnowflakeishOr[hikari.interactions.base_interactions.PartialInteraction]
Object or ID of the interaction this response is for.
token : builtins.str
The command interaction's token.
thesadru marked this conversation as resolved.
Show resolved Hide resolved
title : str
The title that will show up in the modal.
custom_id : str
Developer set custom ID used for identifying interactions with this modal.
Other Parameters
----------------
component : hikari.undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]]
A component builders to send in this modal.
components : hikari.undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]]
A sequence of component builders to send in this modal.
Raises
------
ValueError
If both `component` and `components` are specified or if none are specified.
"""

@abc.abstractmethod
def build_message_action_row(self) -> special_endpoints.MessageActionRowBuilder:
"""Build a message action row message component for use in message create and REST calls.
Returns
-------
hikari.api.special_endpoints.MessageActionRowBuilder
The initialised action row builder.
"""

@abc.abstractmethod
def build_action_row(self) -> special_endpoints.ActionRowBuilder:
"""Build an action row message component for use in message create and REST calls.
def build_modal_action_row(self) -> special_endpoints.ModalActionRowBuilder:
"""Build an action row modal component for use in interactions and REST calls.
Returns
-------
hikari.api.special_endpoints.ActionRowBuilder
hikari.api.special_endpoints.ModalActionRowBuilder
The initialised action row builder.
"""

Expand Down
Loading