mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-08-28 14:05:05 +00:00
Update total count tracking to always consider the wrapper object
This commit is contained in:
parent
0309aac335
commit
9bda89b0d6
@ -203,6 +203,11 @@ class ActionRow(Item[V]):
|
|||||||
def width(self):
|
def width(self):
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _total_count(self) -> int:
|
||||||
|
# 1 for self and all children
|
||||||
|
return 1 + len(self._children)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self) -> Literal[ComponentType.action_row]:
|
def type(self) -> Literal[ComponentType.action_row]:
|
||||||
return ComponentType.action_row
|
return ComponentType.action_row
|
||||||
|
@ -234,6 +234,11 @@ class Container(Item[V]):
|
|||||||
def width(self):
|
def width(self):
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _total_count(self) -> int:
|
||||||
|
# 1 for self and all children
|
||||||
|
return 1 + len(tuple(self.walk_children()))
|
||||||
|
|
||||||
def _is_v2(self) -> bool:
|
def _is_v2(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -313,10 +318,8 @@ class Container(Item[V]):
|
|||||||
if not isinstance(item, Item):
|
if not isinstance(item, Item):
|
||||||
raise TypeError(f'expected Item not {item.__class__.__name__}')
|
raise TypeError(f'expected Item not {item.__class__.__name__}')
|
||||||
|
|
||||||
if item._has_children() and self._view:
|
if self._view:
|
||||||
self._view._add_count(len(tuple(item.walk_children()))) # type: ignore
|
self._view._add_count(item._total_count)
|
||||||
elif self._view:
|
|
||||||
self._view._add_count(1)
|
|
||||||
|
|
||||||
self._children.append(item)
|
self._children.append(item)
|
||||||
item._update_view(self.view)
|
item._update_view(self.view)
|
||||||
@ -341,10 +344,7 @@ class Container(Item[V]):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if self._view:
|
if self._view:
|
||||||
if item._has_children():
|
self._view._add_count(-item._total_count)
|
||||||
self._view._add_count(-len(tuple(item.walk_children()))) # type: ignore
|
|
||||||
else:
|
|
||||||
self._view._add_count(-1)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def find_item(self, id: int, /) -> Optional[Item[V]]:
|
def find_item(self, id: int, /) -> Optional[Item[V]]:
|
||||||
|
@ -168,6 +168,10 @@ class DynamicItem(Generic[BaseT], Item[Union[View, LayoutView]]):
|
|||||||
def width(self) -> int:
|
def width(self) -> int:
|
||||||
return self.item.width
|
return self.item.width
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _total_count(self) -> int:
|
||||||
|
return self.item._total_count
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def from_custom_id(
|
async def from_custom_id(
|
||||||
cls: Type[Self], interaction: Interaction[ClientT], item: Item[Any], match: re.Match[str], /
|
cls: Type[Self], interaction: Interaction[ClientT], item: Item[Any], match: re.Match[str], /
|
||||||
|
@ -147,6 +147,10 @@ class Item(Generic[V]):
|
|||||||
def width(self) -> int:
|
def width(self) -> int:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _total_count(self) -> int:
|
||||||
|
return 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def view(self) -> Optional[V]:
|
def view(self) -> Optional[V]:
|
||||||
"""Optional[Union[:class:`View`, :class:`LayoutView`]]: The underlying view for this item."""
|
"""Optional[Union[:class:`View`, :class:`LayoutView`]]: The underlying view for this item."""
|
||||||
|
@ -102,6 +102,11 @@ class Section(Item[V]):
|
|||||||
def width(self):
|
def width(self):
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _total_count(self) -> int:
|
||||||
|
# Count the accessory, ourselves, and all children
|
||||||
|
return 2 + len(self._children)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def accessory(self) -> Item[V]:
|
def accessory(self) -> Item[V]:
|
||||||
""":class:`Item`: The section's accessory."""
|
""":class:`Item`: The section's accessory."""
|
||||||
|
@ -428,12 +428,7 @@ class BaseView:
|
|||||||
raise ValueError('v2 items cannot be added to this view')
|
raise ValueError('v2 items cannot be added to this view')
|
||||||
|
|
||||||
item._update_view(self)
|
item._update_view(self)
|
||||||
added = 1
|
self._add_count(item._total_count)
|
||||||
|
|
||||||
if item._has_children():
|
|
||||||
added += len(tuple(item.walk_children())) # type: ignore
|
|
||||||
|
|
||||||
self._add_count(added)
|
|
||||||
self._children.append(item)
|
self._children.append(item)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -454,10 +449,7 @@ class BaseView:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
removed = 1
|
self._add_count(-item._total_count)
|
||||||
if item._has_children():
|
|
||||||
removed += len(tuple(item.walk_children())) # type: ignore
|
|
||||||
self._add_count(-removed)
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user