|
@ -23,13 +23,14 @@ DEALINGS IN THE SOFTWARE. |
|
|
""" |
|
|
""" |
|
|
from __future__ import annotations |
|
|
from __future__ import annotations |
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING, List, Literal, Optional, TypeVar |
|
|
from typing import TYPE_CHECKING, List, Literal, Optional, TypeVar, Union |
|
|
|
|
|
|
|
|
from .item import Item |
|
|
from .item import Item |
|
|
from ..enums import ComponentType |
|
|
from ..enums import ComponentType |
|
|
from ..components import ( |
|
|
from ..components import ( |
|
|
MediaGalleryItem, |
|
|
MediaGalleryItem, |
|
|
MediaGalleryComponent, |
|
|
MediaGalleryComponent, |
|
|
|
|
|
UnfurledMediaItem, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
if TYPE_CHECKING: |
|
|
if TYPE_CHECKING: |
|
@ -100,12 +101,49 @@ class MediaGallery(Item[V]): |
|
|
def _is_v2(self) -> bool: |
|
|
def _is_v2(self) -> bool: |
|
|
return True |
|
|
return True |
|
|
|
|
|
|
|
|
def add_item(self, item: MediaGalleryItem) -> Self: |
|
|
def add_item( |
|
|
|
|
|
self, |
|
|
|
|
|
*, |
|
|
|
|
|
media: Union[str, UnfurledMediaItem], |
|
|
|
|
|
description: Optional[str] = None, |
|
|
|
|
|
spoiler: bool = False, |
|
|
|
|
|
) -> Self: |
|
|
"""Adds an item to this gallery. |
|
|
"""Adds an item to this gallery. |
|
|
|
|
|
|
|
|
This function returns the class instance to allow for fluent-style |
|
|
This function returns the class instance to allow for fluent-style |
|
|
chaining. |
|
|
chaining. |
|
|
|
|
|
|
|
|
|
|
|
Parameters |
|
|
|
|
|
---------- |
|
|
|
|
|
media: Union[:class:`str`, :class:`.UnfurledMediaItem`] |
|
|
|
|
|
The media item data. This can be a string representing a local |
|
|
|
|
|
file uploaded as an attachment in the message, which can be accessed |
|
|
|
|
|
using the ``attachment://<filename>`` format, or an arbitrary url. |
|
|
|
|
|
description: Optional[:class:`str`] |
|
|
|
|
|
The description to show within this item. Up to 256 characters. Defaults |
|
|
|
|
|
to ``None``. |
|
|
|
|
|
spoiler: :class:`bool` |
|
|
|
|
|
Whether this item should be flagged as a spoiler. Defaults to ``False``. |
|
|
|
|
|
|
|
|
|
|
|
Raises |
|
|
|
|
|
------ |
|
|
|
|
|
ValueError |
|
|
|
|
|
Maximum number of items has been exceeded (10). |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
if len(self._underlying.items) >= 10: |
|
|
|
|
|
raise ValueError('maximum number of items has been exceeded') |
|
|
|
|
|
|
|
|
|
|
|
item = MediaGalleryItem(media, description=description, spoiler=spoiler) |
|
|
|
|
|
self._underlying.items.append(item) |
|
|
|
|
|
return self |
|
|
|
|
|
|
|
|
|
|
|
def append_item(self, item: MediaGalleryItem) -> Self: |
|
|
|
|
|
"""Appends an item to this gallery. |
|
|
|
|
|
|
|
|
|
|
|
This function returns the class instance to allow for fluent-style |
|
|
|
|
|
chaining. |
|
|
|
|
|
|
|
|
Parameters |
|
|
Parameters |
|
|
---------- |
|
|
---------- |
|
|
item: :class:`.MediaGalleryItem` |
|
|
item: :class:`.MediaGalleryItem` |
|
@ -128,39 +166,66 @@ class MediaGallery(Item[V]): |
|
|
self._underlying.items.append(item) |
|
|
self._underlying.items.append(item) |
|
|
return self |
|
|
return self |
|
|
|
|
|
|
|
|
def remove_item(self, item: MediaGalleryItem) -> Self: |
|
|
def insert_item_at( |
|
|
"""Removes an item from the gallery. |
|
|
self, |
|
|
|
|
|
index: int, |
|
|
|
|
|
*, |
|
|
|
|
|
media: Union[str, UnfurledMediaItem], |
|
|
|
|
|
description: Optional[str] = None, |
|
|
|
|
|
spoiler: bool = False, |
|
|
|
|
|
) -> Self: |
|
|
|
|
|
"""Inserts an item before a specified index to the media gallery. |
|
|
|
|
|
|
|
|
This function returns the class instance to allow for fluent-style |
|
|
This function returns the class instance to allow for fluent-style |
|
|
chaining. |
|
|
chaining. |
|
|
|
|
|
|
|
|
Parameters |
|
|
Parameters |
|
|
---------- |
|
|
---------- |
|
|
item: :class:`.MediaGalleryItem` |
|
|
index: :class:`int` |
|
|
The item to remove from the gallery. |
|
|
The index of where to insert the field. |
|
|
|
|
|
media: Union[:class:`str`, :class:`.UnfurledMediaItem`] |
|
|
|
|
|
The media item data. This can be a string representing a local |
|
|
|
|
|
file uploaded as an attachment in the message, which can be accessed |
|
|
|
|
|
using the ``attachment://<filename>`` format, or an arbitrary url. |
|
|
|
|
|
description: Optional[:class:`str`] |
|
|
|
|
|
The description to show within this item. Up to 256 characters. Defaults |
|
|
|
|
|
to ``None``. |
|
|
|
|
|
spoiler: :class:`bool` |
|
|
|
|
|
Whether this item should be flagged as a spoiler. Defaults to ``False``. |
|
|
|
|
|
|
|
|
|
|
|
Raises |
|
|
|
|
|
------ |
|
|
|
|
|
ValueError |
|
|
|
|
|
Maximum number of items has been exceeded (10). |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
try: |
|
|
if len(self._underlying.items) >= 10: |
|
|
self._underlying.items.remove(item) |
|
|
raise ValueError('maximum number of items has been exceeded') |
|
|
except ValueError: |
|
|
|
|
|
pass |
|
|
item = MediaGalleryItem( |
|
|
|
|
|
media, |
|
|
|
|
|
description=description, |
|
|
|
|
|
spoiler=spoiler, |
|
|
|
|
|
) |
|
|
|
|
|
self._underlying.items.insert(index, item) |
|
|
return self |
|
|
return self |
|
|
|
|
|
|
|
|
def insert_item_at(self, index: int, item: MediaGalleryItem) -> Self: |
|
|
def remove_item(self, item: MediaGalleryItem) -> Self: |
|
|
"""Inserts an item before a specified index to the gallery. |
|
|
"""Removes an item from the gallery. |
|
|
|
|
|
|
|
|
This function returns the class instance to allow for fluent-style |
|
|
This function returns the class instance to allow for fluent-style |
|
|
chaining. |
|
|
chaining. |
|
|
|
|
|
|
|
|
Parameters |
|
|
Parameters |
|
|
---------- |
|
|
---------- |
|
|
index: :class:`int` |
|
|
|
|
|
The index of where to insert the item. |
|
|
|
|
|
item: :class:`.MediaGalleryItem` |
|
|
item: :class:`.MediaGalleryItem` |
|
|
The item to insert. |
|
|
The item to remove from the gallery. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
self._underlying.items.insert(index, item) |
|
|
try: |
|
|
|
|
|
self._underlying.items.remove(item) |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
pass |
|
|
return self |
|
|
return self |
|
|
|
|
|
|
|
|
def clear_items(self) -> Self: |
|
|
def clear_items(self) -> Self: |
|
|