|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING, TypeVar |
| 4 | + |
| 5 | +from ..components import Separator as SeparatorComponent |
| 6 | +from ..components import _component_factory |
| 7 | +from ..enums import ComponentType, SeparatorSpacingSize |
| 8 | +from .item import Item |
| 9 | + |
| 10 | +__all__ = ("Separator",) |
| 11 | + |
| 12 | +if TYPE_CHECKING: |
| 13 | + from ..types.components import SeparatorComponent as SeparatorComponentPayload |
| 14 | + from .view import View |
| 15 | + |
| 16 | + |
| 17 | +S = TypeVar("S", bound="Separator") |
| 18 | +V = TypeVar("V", bound="View", covariant=True) |
| 19 | + |
| 20 | + |
| 21 | +class Separator(Item[V]): |
| 22 | + """Represents a UI Separator. |
| 23 | +
|
| 24 | + .. versionadded:: 2.7 |
| 25 | +
|
| 26 | + Parameters |
| 27 | + ---------- |
| 28 | + divider: :class:`bool` |
| 29 | + Whether the separator is a divider. Defaults to ``True``. |
| 30 | + spacing: :class:`~discord.SeparatorSpacingSize` |
| 31 | + The spacing size of the separator. Defaults to :attr:`~discord.SeparatorSpacingSize.small`. |
| 32 | + """ |
| 33 | + |
| 34 | + def __init__(self, *, divider: bool = True, spacing: SeparatorSpacingSize = SeparatorSpacingSize.small): |
| 35 | + super().__init__() |
| 36 | + |
| 37 | + self.divider = divider |
| 38 | + self.spacing = spacing |
| 39 | + |
| 40 | + self._underlying = SeparatorComponent._raw_construct( |
| 41 | + type=ComponentType.text_display, |
| 42 | + id=None, |
| 43 | + divider=divider, |
| 44 | + spacing=spacing, |
| 45 | + ) |
| 46 | + |
| 47 | + @property |
| 48 | + def type(self) -> ComponentType: |
| 49 | + return self._underlying.type |
| 50 | + |
| 51 | + @property |
| 52 | + def width(self) -> int: |
| 53 | + return 5 |
| 54 | + |
| 55 | + def to_component_dict(self) -> SeparatorComponentPayload: |
| 56 | + return self._underlying.to_dict() |
| 57 | + |
| 58 | + @classmethod |
| 59 | + def from_component(cls: type[S], component: SeparatorComponent) -> S: |
| 60 | + return cls(component.content) |
| 61 | + |
| 62 | + callback = None |
0 commit comments