Browse Source

chore: add id to every item

pull/10166/head
DA-344 3 months ago
parent
commit
9891f85c8b
  1. 2
      discord/ui/button.py
  2. 6
      discord/ui/container.py
  3. 2
      discord/ui/file.py
  4. 2
      discord/ui/media_gallery.py
  5. 3
      discord/ui/section.py
  6. 2
      discord/ui/select.py
  7. 2
      discord/ui/separator.py
  8. 6
      discord/ui/text_display.py
  9. 8
      discord/ui/text_input.py
  10. 6
      discord/ui/thumbnail.py

2
discord/ui/button.py

@ -149,6 +149,7 @@ class Button(Item[V]):
style=style, style=style,
emoji=emoji, emoji=emoji,
sku_id=sku_id, sku_id=sku_id,
id=id,
) )
self._parent: Optional[ActionRow] = None self._parent: Optional[ActionRow] = None
self.row = row self.row = row
@ -250,6 +251,7 @@ class Button(Item[V]):
emoji=button.emoji, emoji=button.emoji,
row=None, row=None,
sku_id=button.sku_id, sku_id=button.sku_id,
id=button.id,
) )
@property @property

6
discord/ui/container.py

@ -194,12 +194,15 @@ class Container(Item[V]):
def to_component_dict(self) -> Dict[str, Any]: def to_component_dict(self) -> Dict[str, Any]:
components = self.to_components() components = self.to_components()
return { base = {
'type': self.type.value, 'type': self.type.value,
'accent_color': self._colour.value if self._colour else None, 'accent_color': self._colour.value if self._colour else None,
'spoiler': self.spoiler, 'spoiler': self.spoiler,
'components': components, 'components': components,
} }
if self.id is not None:
base['id'] = self.id
return base
def _update_store_data( def _update_store_data(
self, self,
@ -222,4 +225,5 @@ class Container(Item[V]):
children=[_component_to_item(c) for c in component.children], children=[_component_to_item(c) for c in component.children],
accent_colour=component.accent_colour, accent_colour=component.accent_colour,
spoiler=component.spoiler, spoiler=component.spoiler,
id=component.id,
) )

2
discord/ui/file.py

@ -75,6 +75,7 @@ class File(Item[V]):
self._underlying = FileComponent._raw_construct( self._underlying = FileComponent._raw_construct(
media=UnfurledMediaItem(media) if isinstance(media, str) else media, media=UnfurledMediaItem(media) if isinstance(media, str) else media,
spoiler=spoiler, spoiler=spoiler,
id=id,
) )
self.row = row self.row = row
@ -126,4 +127,5 @@ class File(Item[V]):
return cls( return cls(
media=component.media, media=component.media,
spoiler=component.spoiler, spoiler=component.spoiler,
id=component.id,
) )

2
discord/ui/media_gallery.py

@ -75,6 +75,7 @@ class MediaGallery(Item[V]):
self._underlying = MediaGalleryComponent._raw_construct( self._underlying = MediaGalleryComponent._raw_construct(
items=items, items=items,
id=id,
) )
self.row = row self.row = row
@ -183,4 +184,5 @@ class MediaGallery(Item[V]):
def from_component(cls, component: MediaGalleryComponent) -> Self: def from_component(cls, component: MediaGalleryComponent) -> Self:
return cls( return cls(
items=component.items, items=component.items,
id=component.id,
) )

3
discord/ui/section.py

@ -174,6 +174,7 @@ class Section(Item[V]):
return cls( return cls(
children=[_component_to_item(c) for c in component.components], children=[_component_to_item(c) for c in component.components],
accessory=_component_to_item(component.accessory), accessory=_component_to_item(component.accessory),
id=component.id,
) )
def to_component_dict(self) -> Dict[str, Any]: def to_component_dict(self) -> Dict[str, Any]:
@ -182,4 +183,6 @@ class Section(Item[V]):
'components': [c.to_component_dict() for c in self._children], 'components': [c.to_component_dict() for c in self._children],
'accessory': self.accessory.to_component_dict(), 'accessory': self.accessory.to_component_dict(),
} }
if self.id is not None:
data['id'] = self.id
return data return data

2
discord/ui/select.py

@ -224,6 +224,7 @@ class BaseSelect(Item[V]):
'min_values', 'min_values',
'max_values', 'max_values',
'disabled', 'disabled',
'id',
) )
def __init__( def __init__(
@ -257,6 +258,7 @@ class BaseSelect(Item[V]):
channel_types=[] if channel_types is MISSING else channel_types, channel_types=[] if channel_types is MISSING else channel_types,
options=[] if options is MISSING else options, options=[] if options is MISSING else options,
default_values=[] if default_values is MISSING else default_values, default_values=[] if default_values is MISSING else default_values,
id=id,
) )
self.row = row self.row = row

2
discord/ui/separator.py

@ -74,6 +74,7 @@ class Separator(Item[V]):
self._underlying = SeparatorComponent._raw_construct( self._underlying = SeparatorComponent._raw_construct(
spacing=spacing, spacing=spacing,
visible=visible, visible=visible,
id=id,
) )
self.row = row self.row = row
@ -120,4 +121,5 @@ class Separator(Item[V]):
return cls( return cls(
visible=component.visible, visible=component.visible,
spacing=component.spacing, spacing=component.spacing,
id=component.id,
) )

6
discord/ui/text_display.py

@ -67,10 +67,13 @@ class TextDisplay(Item[V]):
self.id = id self.id = id
def to_component_dict(self): def to_component_dict(self):
return { base = {
'type': self.type.value, 'type': self.type.value,
'content': self.content, 'content': self.content,
} }
if self.id is not None:
base['id'] = self.id
return base
@property @property
def width(self): def width(self):
@ -87,4 +90,5 @@ class TextDisplay(Item[V]):
def from_component(cls, component: TextDisplayComponent) -> Self: def from_component(cls, component: TextDisplayComponent) -> Self:
return cls( return cls(
content=component.content, content=component.content,
id=component.id,
) )

8
discord/ui/text_input.py

@ -92,6 +92,10 @@ class TextInput(Item[V]):
like to control the relative positioning of the row then passing an index is advised. like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed). ordering. The row number must be between 0 and 4 (i.e. zero indexed).
id: Optional[:class:`int`]
The ID of the component. This must be unique across the view.
.. versionadded:: 2.6
""" """
__item_repr_attributes__: Tuple[str, ...] = ( __item_repr_attributes__: Tuple[str, ...] = (
@ -112,6 +116,7 @@ class TextInput(Item[V]):
min_length: Optional[int] = None, min_length: Optional[int] = None,
max_length: Optional[int] = None, max_length: Optional[int] = None,
row: Optional[int] = None, row: Optional[int] = None,
id: Optional[int] = None,
) -> None: ) -> None:
super().__init__() super().__init__()
self._value: Optional[str] = default self._value: Optional[str] = default
@ -129,8 +134,10 @@ class TextInput(Item[V]):
required=required, required=required,
min_length=min_length, min_length=min_length,
max_length=max_length, max_length=max_length,
id=id,
) )
self.row = row self.row = row
self.id = id
def __str__(self) -> str: def __str__(self) -> str:
return self.value return self.value
@ -241,6 +248,7 @@ class TextInput(Item[V]):
min_length=component.min_length, min_length=component.min_length,
max_length=component.max_length, max_length=component.max_length,
row=None, row=None,
id=component.id,
) )
@property @property

6
discord/ui/thumbnail.py

@ -96,12 +96,15 @@ class Thumbnail(Item[V]):
return True return True
def to_component_dict(self) -> Dict[str, Any]: def to_component_dict(self) -> Dict[str, Any]:
return { base = {
'type': self.type.value, 'type': self.type.value,
'spoiler': self.spoiler, 'spoiler': self.spoiler,
'media': self.media.to_dict(), 'media': self.media.to_dict(),
'description': self.description, 'description': self.description,
} }
if self.id is not None:
base['id'] = self.id
return base
@classmethod @classmethod
def from_component(cls, component: ThumbnailComponent) -> Self: def from_component(cls, component: ThumbnailComponent) -> Self:
@ -109,4 +112,5 @@ class Thumbnail(Item[V]):
media=component.media.url, media=component.media.url,
description=component.description, description=component.description,
spoiler=component.spoiler, spoiler=component.spoiler,
id=component.id,
) )

Loading…
Cancel
Save