Skip to content

Commit 032fb00

Browse files
authored
Separator
1 parent 8fd981d commit 032fb00

File tree

7 files changed

+70
-7
lines changed

7 files changed

+70
-7
lines changed

discord/abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ async def send(
16011601
)
16021602

16031603
components = view.to_components()
1604-
if view.is_v2():
1604+
if view.is_components_v2():
16051605
flags.is_components_v2 = True
16061606
else:
16071607
components = None

discord/enums.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
"EntitlementOwnerType",
7777
"IntegrationType",
7878
"InteractionContextType",
79+
"PollLayoutType",
80+
"SubscriptionStatus",
81+
"SeparatorSpacingSize",
82+
"MediaItemLoadingState",
7983
)
8084

8185

discord/interactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ async def send_message(
964964

965965
if view is not None:
966966
payload["components"] = view.to_components()
967-
if view.is_v2():
967+
if view.is_components_v2():
968968
flags.is_components_v2 = True
969969

970970
if poll is not None:

discord/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ async def edit(
16011601
if view is not MISSING:
16021602
self._state.prevent_view_updates_for(self.id)
16031603
payload["components"] = view.to_components() if view else []
1604-
if view and view.is_v2():
1604+
if view and view.is_components_v2():
16051605
flags.is_components_v2 = True
16061606
if file is not MISSING and files is not MISSING:
16071607
raise InvalidArgument("cannot pass both file and files parameter to edit()")

discord/ui/separator.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

discord/ui/view.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ def to_components(self) -> list[dict[str, Any]]:
240240
def key(item: Item) -> int:
241241
return item._rendered_row or 0
242242

243-
# if self.is_v2():
244-
# components = [item.to_component_dict() for item in self.children]
245-
# else:
246243
children = sorted(self.children, key=key)
247244
components: list[dict[str, Any]] = []
248245
for _, group in groupby(children, key=key):

discord/webhook/async_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def handle_message_parameters(
664664

665665
if view is not MISSING:
666666
payload["components"] = view.to_components() if view is not None else []
667-
if view and view.is_v2():
667+
if view and view.is_components_v2():
668668
flags.is_components_v2 = True
669669
if poll is not MISSING:
670670
payload["poll"] = poll.to_dict()

0 commit comments

Comments
 (0)