Skip to content

Commit a8f076a

Browse files
authored
feat!: Add converters to components (#981)
* refactor!: Add converters to components * ci: run pre-commit * doc: add missed docstring * oop
1 parent 1ec46aa commit a8f076a

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

interactions/api/gateway/client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,9 @@ def _dispatch_event(self, event: str, data: dict) -> None:
372372
elif data["type"] == InteractionType.MODAL_SUBMIT:
373373
_name = f"modal_{_context.data.custom_id}"
374374

375-
if _context.data._json.get("components"):
375+
if _context.data.components:
376376
for component in _context.data.components:
377-
if component.get("components"):
378-
__args.append(
379-
[_value["value"] for _value in component["components"]][0]
380-
)
381-
else:
377+
if component.components:
382378
__args.append([_value.value for _value in component.components][0])
383379

384380
self._dispatch.dispatch("on_modal", _context)

interactions/api/models/message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enum import IntEnum
44
from typing import TYPE_CHECKING, List, Optional, Union
55

6+
from ...client.models.component import ActionRow, Button, SelectMenu
67
from ..error import LibraryException
78
from .attrs_utils import (
89
MISSING,
@@ -22,7 +23,6 @@
2223
from .user import User
2324

2425
if TYPE_CHECKING:
25-
from ...client.models.component import ActionRow, Button, Component, SelectMenu
2626
from ..http import HTTPClient
2727

2828
__all__ = (
@@ -731,7 +731,7 @@ class Message(ClientSerializerMixin, IDMixin):
731731
:ivar int flags: Message flags
732732
:ivar Optional[MessageInteraction] interaction?: Message interaction object, if the message is sent by an interaction.
733733
:ivar Optional[Channel] thread?: The thread that started from this message, if any, with a thread member object embedded.
734-
:ivar Optional[Union[Component, List[Component]]] components?: Components associated with this message, if any.
734+
:ivar Optional[List[ActionRow]] components?: Array of Action Rows associated with this message, if any.
735735
:ivar Optional[List[PartialSticker]] sticker_items?: An array of message sticker item objects, if sent with them.
736736
:ivar Optional[List[Sticker]] stickers?: Array of sticker objects sent with the message if any. Deprecated.
737737
:ivar Optional[int] position?: The approximate position of the message in a thread.
@@ -775,7 +775,7 @@ class Message(ClientSerializerMixin, IDMixin):
775775
)
776776
thread: Optional[Channel] = field(converter=Channel, default=None, add_client=True)
777777

778-
components: Optional[Union["Component", List["Component"]]] = field(default=None)
778+
components: Optional[List["ActionRow"]] = field(converter=convert_list(ActionRow), default=None)
779779
sticker_items: Optional[List[PartialSticker]] = field(
780780
converter=convert_list(PartialSticker), default=None
781781
)

interactions/client/models/misc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional
1+
from typing import Dict, List, Optional
22

33
from ...api.models.attrs_utils import DictSerializerMixin, convert_dict, convert_list, define, field
44
from ...api.models.channel import Channel
@@ -9,6 +9,7 @@
99
from ...api.models.user import User
1010
from ..enums import ApplicationCommandType, ComponentType, InteractionType, PermissionType
1111
from ..models.command import Option
12+
from .component import ActionRow
1213

1314
__all__ = ("InteractionResolvedData", "InteractionData", "Interaction")
1415

@@ -55,6 +56,7 @@ class InteractionData(DictSerializerMixin):
5556
:ivar Optional[ComponentType] component_type?: The type of component from the interaction.
5657
:ivar Optional[List[str]] values?: The values of the selected options in the interaction.
5758
:ivar Optional[str] target_id?: The targeted ID of the interaction.
59+
:ivar Optional[List[ActionRow]] components?: Array of Action Rows in modal.
5860
"""
5961

6062
id: Snowflake = field(converter=Snowflake, default=None)
@@ -68,7 +70,7 @@ class InteractionData(DictSerializerMixin):
6870
component_type: Optional[ComponentType] = field(converter=ComponentType, default=None)
6971
values: Optional[List[str]] = field(default=None)
7072
target_id: Optional[Snowflake] = field(converter=Snowflake, default=None)
71-
components: Any = field(default=None) # todo check this type
73+
components: Optional[List[ActionRow]] = field(converter=convert_list(ActionRow), default=None)
7274

7375

7476
@define()

0 commit comments

Comments
 (0)