|
36 | 36 | from .view import BaseView |
37 | 37 | from .select import BaseSelect |
38 | 38 | from .text_input import TextInput |
| 39 | +from ..interactions import Namespace |
39 | 40 |
|
40 | 41 | if TYPE_CHECKING: |
41 | 42 | from typing_extensions import Self |
42 | 43 |
|
43 | 44 | from ..interactions import Interaction |
44 | | - from ..types.interactions import ModalSubmitComponentInteractionData as ModalSubmitComponentInteractionDataPayload |
| 45 | + from ..types.interactions import ( |
| 46 | + ModalSubmitComponentInteractionData as ModalSubmitComponentInteractionDataPayload, |
| 47 | + ResolvedData as ResolvedDataPayload, |
| 48 | + ) |
| 49 | + from ..app_commands.namespace import ResolveKey |
45 | 50 |
|
46 | 51 |
|
47 | 52 | # fmt: off |
@@ -168,27 +173,41 @@ async def on_error(self, interaction: Interaction[ClientT], error: Exception, /) |
168 | 173 | """ |
169 | 174 | _log.error('Ignoring exception in modal %r:', self, exc_info=error) |
170 | 175 |
|
171 | | - def _refresh(self, interaction: Interaction, components: Sequence[ModalSubmitComponentInteractionDataPayload]) -> None: |
| 176 | + def _refresh( |
| 177 | + self, |
| 178 | + interaction: Interaction, |
| 179 | + components: Sequence[ModalSubmitComponentInteractionDataPayload], |
| 180 | + resolved: Dict[ResolveKey, Any], |
| 181 | + ) -> None: |
172 | 182 | for component in components: |
173 | 183 | if component['type'] == 1: |
174 | | - self._refresh(interaction, component['components']) |
| 184 | + self._refresh(interaction, component['components'], resolved) # type: ignore |
175 | 185 | elif component['type'] == 18: |
176 | | - self._refresh(interaction, [component['component']]) |
| 186 | + self._refresh(interaction, [component['component']], resolved) # type: ignore |
177 | 187 | else: |
178 | 188 | custom_id = component.get('custom_id') |
179 | 189 | if custom_id is None: |
180 | 190 | continue |
181 | 191 |
|
182 | | - item = find(lambda i: getattr(i, 'custom_id', None) == custom_id, self.walk_children()) |
| 192 | + item = find( |
| 193 | + lambda i: getattr(i, 'custom_id', None) == custom_id, |
| 194 | + self.walk_children(), |
| 195 | + ) |
183 | 196 | if item is None: |
184 | 197 | _log.debug('Modal interaction referencing unknown item custom_id %s. Discarding', custom_id) |
185 | 198 | continue |
186 | | - item._refresh_state(interaction, component) # type: ignore |
187 | 199 |
|
188 | | - async def _scheduled_task(self, interaction: Interaction, components: List[ModalSubmitComponentInteractionDataPayload]): |
| 200 | + item._handle_submit(interaction, component, resolved) # type: ignore |
| 201 | + |
| 202 | + async def _scheduled_task( |
| 203 | + self, |
| 204 | + interaction: Interaction, |
| 205 | + components: List[ModalSubmitComponentInteractionDataPayload], |
| 206 | + resolved: Dict[ResolveKey, Any], |
| 207 | + ): |
189 | 208 | try: |
190 | 209 | self._refresh_timeout() |
191 | | - self._refresh(interaction, components) |
| 210 | + self._refresh(interaction, components, resolved) |
192 | 211 |
|
193 | 212 | allow = await self.interaction_check(interaction) |
194 | 213 | if not allow: |
@@ -225,10 +244,18 @@ def key(item: Item) -> int: |
225 | 244 | return components |
226 | 245 |
|
227 | 246 | def _dispatch_submit( |
228 | | - self, interaction: Interaction, components: List[ModalSubmitComponentInteractionDataPayload] |
| 247 | + self, |
| 248 | + interaction: Interaction, |
| 249 | + components: List[ModalSubmitComponentInteractionDataPayload], |
| 250 | + resolved: ResolvedDataPayload, |
229 | 251 | ) -> asyncio.Task[None]: |
| 252 | + try: |
| 253 | + namespace = Namespace._get_resolved_items(interaction, resolved) |
| 254 | + except KeyError: |
| 255 | + namespace = {} |
| 256 | + |
230 | 257 | return asyncio.create_task( |
231 | | - self._scheduled_task(interaction, components), name=f'discord-ui-modal-dispatch-{self.id}' |
| 258 | + self._scheduled_task(interaction, components, namespace), name=f'discord-ui-modal-dispatch-{self.id}' |
232 | 259 | ) |
233 | 260 |
|
234 | 261 | def to_dict(self) -> Dict[str, Any]: |
|
0 commit comments