Skip to content

Commit

Permalink
Update migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
hypergonial committed Jan 18, 2024
1 parent 8fad2fc commit b21614b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
2 changes: 2 additions & 0 deletions docs/guides/menus.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ To set up a menu for the screens we designed above, see this snippet below:
client.start_view(my_menu)
```

!!! tip
If you want to send a menu in response to a `miru` item being interacted with, you may use [`Context.respond_with_builder()`][miru.abc.context.Context.respond_with_builder].

!!! note
Menus do not support persistence.
71 changes: 49 additions & 22 deletions docs/guides/migrating_from_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Since in v4 everything is tied to the [`Client`][miru.client.Client], views need

## Sending modals, navigators

`Modal.send()`, `NavigatorView.send()` have been removed.
`Modal.send()` has been removed.

Due to the changes required to support REST bots, it is no longer possible to put modals & navigator views in control of sending, due to the many ways these objects can be sent as a response.
Due to the changes required to support REST bots, it is no longer possible to put modals themselves in control of sending, due to the many ways they can now be sent as a response.

Therefore, this responsibility is now in the hands of the user. This *does* add some extra complexity, however it also allows for much greater control over how these objects are sent, and thus better compatibility with other libraries.

Expand All @@ -101,35 +101,62 @@ Therefore, this responsibility is now in the hands of the user. This *does* add
await modal.send(interaction)
```

For more information on how to use these builders with each of the major command handler frameworks, please see the updated [modal](./modals.md) and [navigator](./navigators.md) guides.
For more information on how to use these builders with each of the major command handler frameworks, please see the updated [modal](./modals.md) guide.

## Sending menus
## Sending navigators & menus

`Menu.send()` has been removed.
`NavigatorView.send()`, `Menu.send()` have been removed.

Similarly to modals & navigators, menus are also now turned into builders. However, since menu payloads are built asynchronously, you need to use [`Menu.build_response_async()`][miru.ext.menu.menu.Menu.build_response_async] instead. If you're handling an interaction, you may also need to defer beforehand if building your initial screen takes a long time.
Similarly to modals, menus & navigators are also now turned into builders. However, since the payloads are built asynchronously, you need to use [`Menu.build_response_async()`][miru.ext.menu.menu.Menu.build_response_async] and [`NavigatorView.build_response_async()`][miru.ext.nav.NavigatorView.build_response_async] respectively, instead. If you're handling an interaction, you may also need to defer beforehand if building your initial screen takes a long time.

=== "v4"

```py
menu = menu.Menu(...)
# This returns a custom InteractionMessageBuilder
# It can be returned in REST callbacks
builder = await menu.build_response_async()
=== "NavigatorView"

# Or you can use some of the custom methods it has
await builder.create_initial_response(interaction)
# Or
await builder.send_to_channel(channel_id)
```py
navigator = nav.NavigatorView(...)
# This returns a custom InteractionMessageBuilder
# It can be returned in REST callbacks
builder = await navigator.build_response_async()

client.start_view(menu)
```
# Or you can use some of the custom methods it has
await builder.create_initial_response(interaction)
# Or
await builder.send_to_channel(channel_id)

client.start_view(navigator)
```

=== "Menu"

```py
my_menu = menu.Menu(...)
# This returns a custom InteractionMessageBuilder
# It can be returned in REST callbacks
builder = await my_menu.build_response_async()

# Or you can use some of the custom methods it has
await builder.create_initial_response(interaction)
# Or
await builder.send_to_channel(channel_id)

client.start_view(my_menu)
```

=== "v3"

```py
modal = menu.Menu(...)
await menu.send(channel_id | interaction)
```
=== "NavigatorView"

```py
navigator = nav.NavigatorView(...)
await navigator.send(channel_id | interaction)
```

=== "Menu"

```py
my_menu = menu.Menu(...)
await my_menu.send(channel_id | interaction)
```

For more information on how to use these builders with each of the major command handler frameworks, please see the updated [menu](./menus.md) guide.
For more information on how to use these builders with each of the major command handler frameworks, please see the updated [menu](./menus.md) and [navigator](./navigators.md) guides.
3 changes: 3 additions & 0 deletions docs/guides/navigators.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ turning it into a builder, and sending it to a channel or interaction.
bot.run()
```

!!! tip
If you want to send a navigator in response to a `miru` item being interacted with, you may use [`Context.respond_with_builder()`][miru.abc.context.Context.respond_with_builder].

## Customizing Navigation Buttons

If you would like to customize the items used by the navigator, you can pass buttons & selects via the `items=` keyword-only
Expand Down
19 changes: 16 additions & 3 deletions miru/context/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,26 @@ def message(self) -> hikari.Message:
return self._interaction.message

async def respond_with_modal(self, modal: Modal) -> None:
"""Respond to this interaction with a modal."""
"""Respond to this interaction with a modal.
This is effectively the same as:
```py
builder = modal.build_response(client)
await ctx.respond_with_builder(builder)
client.start_modal(modal)
```
Parameters
----------
modal : Modal
The modal to respond with.
"""
if self._issued_response:
raise RuntimeError("Interaction was already responded to.")

async with self._response_lock:
builder = modal.build_response(self.client)
builder = modal.build_response(self.client)

async with self._response_lock:
if self.client.is_rest:
self._resp_builder.set_result(builder)
else:
Expand Down

0 comments on commit b21614b

Please sign in to comment.