mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-22 08:44:10 +00:00
Fix ui.Select.values in modals
This commit is contained in:
parent
584c22f642
commit
9c38cf3aef
@ -174,9 +174,11 @@ class Modal(View):
|
||||
continue
|
||||
item._refresh_state(component) # type: ignore
|
||||
|
||||
async def _scheduled_task(self, interaction: Interaction):
|
||||
async def _scheduled_task(self, interaction: Interaction, components: List[ModalSubmitComponentInteractionDataPayload]):
|
||||
try:
|
||||
self._refresh_timeout()
|
||||
self._refresh(components)
|
||||
|
||||
allow = await self.interaction_check(interaction)
|
||||
if not allow:
|
||||
return
|
||||
@ -189,8 +191,10 @@ class Modal(View):
|
||||
# In the future, maybe this will require checking if we set an error response.
|
||||
self.stop()
|
||||
|
||||
def _dispatch_submit(self, interaction: Interaction) -> None:
|
||||
asyncio.create_task(self._scheduled_task(interaction), name=f'discord-ui-modal-dispatch-{self.id}')
|
||||
def _dispatch_submit(
|
||||
self, interaction: Interaction, components: List[ModalSubmitComponentInteractionDataPayload]
|
||||
) -> None:
|
||||
asyncio.create_task(self._scheduled_task(interaction, components), name=f'discord-ui-modal-dispatch-{self.id}')
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
payload = {
|
||||
|
@ -23,7 +23,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import List, Literal, Optional, TYPE_CHECKING, Tuple, TypeVar, Callable, Union
|
||||
from typing import List, Literal, Optional, TYPE_CHECKING, Tuple, TypeVar, Callable, Union, Dict
|
||||
from contextvars import ContextVar
|
||||
import inspect
|
||||
import os
|
||||
@ -54,7 +54,7 @@ if TYPE_CHECKING:
|
||||
|
||||
V = TypeVar('V', bound='View', covariant=True)
|
||||
|
||||
selected_values: ContextVar[Optional[List[str]]] = ContextVar('selected_values', default=None)
|
||||
selected_values: ContextVar[Dict[str, List[str]]] = ContextVar('selected_values')
|
||||
|
||||
|
||||
class Select(Item[V]):
|
||||
@ -126,6 +126,7 @@ class Select(Item[V]):
|
||||
disabled=disabled,
|
||||
)
|
||||
self.row = row
|
||||
self._values: List[str] = []
|
||||
|
||||
@property
|
||||
def custom_id(self) -> str:
|
||||
@ -262,8 +263,8 @@ class Select(Item[V]):
|
||||
@property
|
||||
def values(self) -> List[str]:
|
||||
"""List[:class:`str`]: A list of values that have been selected by the user."""
|
||||
values = selected_values.get()
|
||||
return values if values is not None else []
|
||||
values = selected_values.get(None)
|
||||
return self._values if values is None else values.get(self.custom_id, [])
|
||||
|
||||
@property
|
||||
def width(self) -> int:
|
||||
@ -276,7 +277,9 @@ class Select(Item[V]):
|
||||
self._underlying = component
|
||||
|
||||
def _refresh_state(self, data: MessageComponentInteractionData) -> None:
|
||||
selected_values.set(data.get('values', []))
|
||||
values = selected_values.get({})
|
||||
self._values = values[self.custom_id] = data.get('values', [])
|
||||
selected_values.set(values)
|
||||
|
||||
@classmethod
|
||||
def from_component(cls, component: SelectMenu) -> Self:
|
||||
|
@ -416,6 +416,8 @@ class View:
|
||||
if self.timeout:
|
||||
self.__timeout_expiry = time.monotonic() + self.timeout
|
||||
|
||||
item._refresh_state(interaction.data) # type: ignore
|
||||
|
||||
allow = await self.interaction_check(interaction)
|
||||
if not allow:
|
||||
return
|
||||
@ -615,7 +617,6 @@ class ViewStore:
|
||||
if item is None:
|
||||
return
|
||||
|
||||
item._refresh_state(interaction.data) # type: ignore
|
||||
# Note, at this point the View is *not* None
|
||||
item.view._dispatch_item(item, interaction) # type: ignore
|
||||
|
||||
@ -630,8 +631,7 @@ class ViewStore:
|
||||
_log.debug("Modal interaction referencing unknown custom_id %s. Discarding", custom_id)
|
||||
return
|
||||
|
||||
modal._refresh(components)
|
||||
modal._dispatch_submit(interaction)
|
||||
modal._dispatch_submit(interaction, components)
|
||||
|
||||
def remove_interaction_mapping(self, interaction_id: int) -> None:
|
||||
# This is called before re-adding the view
|
||||
|
Loading…
x
Reference in New Issue
Block a user