Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
204 changes: 202 additions & 2 deletions hikari/api/special_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"InteractionModalBuilder",
"InteractionResponseBuilder",
"InteractiveButtonBuilder",
"LabelComponentBuilder",
"LinkButtonBuilder",
"MediaGalleryComponentBuilder",
"MediaGalleryItemBuilder",
Expand Down Expand Up @@ -1857,6 +1858,11 @@
def options(self) -> typing.Sequence[SelectOptionBuilder]:
"""Sequence of the options set for this select menu."""

@property
@abc.abstractmethod
def required(self) -> undefined.UndefinedOr[bool]:
"""Whether the text select requires a selection."""

@abc.abstractmethod
def add_option(
self,
Expand Down Expand Up @@ -2399,8 +2405,7 @@
!!! warning
It is generally better to use
[`hikari.api.special_endpoints.MessageActionRowBuilder.add_interactive_button`][]
and [`hikari.api.special_endpoints.MessageActionRowBuilder.add_select_menu`][]
[`hikari.api.special_endpoints.MessageActionRowBuilder.add_text_input`][]
to add your component to the builder. Those methods utilize this one.
Parameters
Expand Down Expand Up @@ -2870,6 +2875,197 @@
"""


class LabelComponentBuilder(ComponentBuilder, abc.ABC):
"""Builder class for container components."""

__slots__: typing.Sequence[str] = ()

@property
@abc.abstractmethod
@typing_extensions.override
def type(self) -> typing.Literal[components_.ComponentType.LABEL]:
"""Type of component this builder represents."""

@property
@abc.abstractmethod
def label(self) -> str:
"""The label name of the label component."""

@property
@abc.abstractmethod
def description(self) -> str | None:
"""The label name of the label component."""

@property
@abc.abstractmethod
def component(self) -> LabelBuilderComponentsT:
"""The component attached to the label."""

@abc.abstractmethod
def set_component(self, component: ModalActionRowBuilderComponentsT, /) -> Self:
"""Add a component to this action row builder.
!!! warning
It is generally better to use
[`hikari.api.special_endpoints.LabelComponentBuilder.set_text_input`][]
[`hikari.api.special_endpoints.LabelComponentBuilder.set_select_menu`][]
to add your component to the builder. Those methods utilize this one.
Parameters
----------
component
The component builder to set as the component.
Returns
-------
ActionRowBuilder
The builder object to enable chained calls.
"""

@abc.abstractmethod
def set_text_input(
self,
custom_id: str,
label: str,
/,
*,
style: components_.TextInputStyle = components_.TextInputStyle.SHORT,
placeholder: undefined.UndefinedOr[str] = undefined.UNDEFINED,
value: undefined.UndefinedOr[str] = undefined.UNDEFINED,
required: bool = True,
min_length: int = 0,
max_length: int = 4000,
) -> Self:
"""Set the component to a text input component.
Parameters
----------
custom_id
Developer set custom ID used for identifying this text input.
label
Label above this text input.
style
The text input's style.
placeholder
Placeholder text to display when the text input is empty.
value
Default text to pre-fill the field with.
required
Whether text must be supplied for this text input.
min_length
Minimum length the input text can be.
This can be greater than or equal to 0 and less than or equal to 4000.
max_length
Maximum length the input text can be.
This can be greater than or equal to 1 and less than or equal to 4000.
Returns
-------
LabelComponentBuilder
The label component builder to enable call chaining.
"""

@abc.abstractmethod
def set_select_menu(
self,
type_: components_.ComponentType | int,
custom_id: str,
/,
*,
placeholder: undefined.UndefinedOr[str] = undefined.UNDEFINED,
min_values: int = 0,
max_values: int = 1,
is_disabled: bool = False,
id: undefined.UndefinedOr[int] = undefined.UNDEFINED,
) -> Self:
"""Add a select menu component to this action row builder.
For channel select menus and text select menus see
[`hikari.api.special_endpoints.MessageActionRowBuilder.add_channel_menu`][]
and [`hikari.api.special_endpoints.MessageActionRowBuilder.add_text_menu`][].
Parameters
----------
type_
The type for the select menu.
custom_id
A developer-defined custom identifier used to identify which menu
triggered component interactions.
placeholder
Placeholder text to show when no entries have been selected.
min_values
The minimum amount of entries which need to be selected.
max_values
The maximum amount of entries which can be selected.
is_disabled
Whether this select menu should be marked as disabled.
id
The ID to give to the menu.
If not provided, auto populated through increment.
Returns
-------
LabelComponentBuilder
The label component builder to enable call chaining.
Raises
------
ValueError
If an invalid select menu type is passed.
"""

@abc.abstractmethod
def set_text_menu(
self,
custom_id: str,
/,
*,
placeholder: undefined.UndefinedOr[str] = undefined.UNDEFINED,
min_values: int = 0,
max_values: int = 1,
is_disabled: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling them is no longer possible

id: undefined.UndefinedOr[int] = undefined.UNDEFINED,
) -> TextSelectMenuBuilder[Self]:
"""Add a select menu component to this action row builder.
Parameters
----------
custom_id
A developer-defined custom identifier used to identify which menu
triggered component interactions.
placeholder
Placeholder text to show when no entries have been selected.
min_values
The minimum amount of entries which need to be selected.
max_values
The maximum amount of entries which can be selected.
is_disabled
Whether this select menu should be marked as disabled.
id
The ID to give to the menu.
If not provided, auto populated through increment.
Returns
-------
TextSelectMenuBuilder
The text select menu builder.
[`hikari.api.special_endpoints.TextSelectMenuBuilder.add_option`][] should be called to add
options to the returned builder then
[`hikari.api.special_endpoints.TextSelectMenuBuilder.parent`][] can be used to return to this
action row while chaining calls.
Raises
------
ValueError
If an invalid select menu type is passed.
"""


class PollBuilder(abc.ABC):
"""Builder class for polls."""

Expand Down Expand Up @@ -2976,6 +3172,10 @@
SectionBuilderAccessoriesT = typing.Union[ButtonBuilder, ThumbnailComponentBuilder]
SectionBuilderComponentsT = typing.Union[TextDisplayComponentBuilder]

LabelBuilderComponentsT = typing.Union[
SelectMenuBuilder, TextInputBuilder
] # FIXME: This is really wrong, as it does not support all select menu types.

Check failure on line 3177 in hikari/api/special_endpoints.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (FIX001)

hikari/api/special_endpoints.py:3177:10: FIX001 Line contains FIXME, consider resolving the issue

Check failure on line 3177 in hikari/api/special_endpoints.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (TD001)

hikari/api/special_endpoints.py:3177:10: TD001 Invalid TODO tag: `FIXME`


class AutoModActionBuilder(abc.ABC):
"""Builder class for auto mod actions."""
Expand Down
47 changes: 45 additions & 2 deletions hikari/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,41 @@

from __future__ import annotations

__all__: typing.Sequence[str] = (
"ActionRowComponent",
"ButtonComponent",
"ButtonStyle",
"ChannelSelectMenuComponent",
"ComponentType",
"ContainerComponent",
"ContainerTypesT",
"FileComponent",
"InteractiveButtonTypes",
"InteractiveButtonTypesT",
"LabelComponent",
"LabelTypesT",
"MediaGalleryComponent",
"MediaGalleryItem",
"MediaLoadingType",
"MediaResource",
"MessageActionRowComponent",
"MessageComponentTypesT",
"ModalActionRowComponent",
"ModalComponentTypesT",
"ModalActionRowComponentTypesT",
"PartialComponent",
"SectionComponent",
"SelectMenuComponent",
"SelectMenuOption",
"SeparatorComponent",
"SpacingType",
"TextDisplayComponent",
"TextInputComponent",
"TextInputStyle",
"TextSelectMenuComponent",
"ThumbnailComponent",
"TopLevelComponentTypesT",
)

Check failure on line 59 in hikari/components.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (RUF022)

hikari/components.py:25:33: RUF022 `__all__` is not sorted

import typing

Expand Down Expand Up @@ -106,6 +109,7 @@

!!! note
This component may only be used inside a modal container.
FIXME: This needs switching to a different item, like label.

!!! note
This cannot be top-level and must be within a container component such
Expand Down Expand Up @@ -180,6 +184,12 @@
component and therefore will always be top-level.
"""

LABEL = 18
"""A label component.

FIXME: This needs a better description.
"""


@typing.final
class ButtonStyle(int, enums.Enum):
Expand Down Expand Up @@ -565,6 +575,20 @@
"""The components within the container."""


@attrs.define(kw_only=True, weakref_slot=False)
class LabelComponent(PartialComponent):
"""Represents a label component."""

label: str = attrs.field()
"""The label name of the label component."""

description: undefined.UndefinedOr[str] = attrs.field()
"""The description of the label component."""

component: LabelTypesT = attrs.field()
"""The component within the label."""


TopLevelComponentTypesT = typing.Union[
ActionRowComponent[PartialComponent],
TextDisplayComponent,
Expand Down Expand Up @@ -701,15 +725,34 @@
* [`hikari.components.ButtonComponent`][]
* [`hikari.components.SelectMenuComponent`][]
""" # noqa: E501
ModalComponentTypesT = TextInputComponent

ModalComponentTypesT = typing.Union[ActionRowComponent[PartialComponent], LabelComponent]
"""Type hint of the [`hikari.components.PartialComponent`][] that be contained in a [`hikari.components.PartialComponent`][].

Check failure on line 730 in hikari/components.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (E501)

hikari/components.py:730:121: E501 Line too long (125 > 120)

The following values are valid for this:

* [`hikari.components.ActionRowComponent`][]
* [`hikari.components.LabelComponent`][]
"""

ModalActionRowComponentTypesT = TextInputComponent # FIXME: This is a breaking change.

Check failure on line 738 in hikari/components.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (FIX001)

hikari/components.py:738:55: FIX001 Line contains FIXME, consider resolving the issue

Check failure on line 738 in hikari/components.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (TD001)

hikari/components.py:738:55: TD001 Invalid TODO tag: `FIXME`
"""Type hint of the [`hikari.components.PartialComponent`][] that be contained in a [`hikari.components.PartialComponent`][].

The following values are valid for this:

* [`hikari.components.TextInputComponent`][]
""" # noqa: E501

LabelTypesT = typing.Union[TextSelectMenuComponent, TextInputComponent]
"""Type hint of the [`hikari.components.PartialComponent`][] that be contained in a [`hikari.components.LabelComponent`][].

Check failure on line 747 in hikari/components.py

View workflow job for this annotation

GitHub Actions / linting

Ruff (E501)

hikari/components.py:747:121: E501 Line too long (123 > 120)

The following values are valid for this:

* [`hikari.components.TextSelectMenuComponent`][]
* [`hikari.components.TextInputComponent`][]
"""

MessageActionRowComponent = ActionRowComponent[MessageComponentTypesT]
"""A message action row component."""
ModalActionRowComponent = ActionRowComponent[ModalComponentTypesT]
ModalActionRowComponent = ActionRowComponent[ModalActionRowComponentTypesT]
"""A modal action row component."""
Loading
Loading