Browse Source

chore: update some things for storing items

pull/10166/head
DA-344 1 month ago
parent
commit
8c807e1e20
  1. 6
      discord/ui/action_row.py
  2. 6
      discord/ui/container.py
  3. 5
      discord/ui/item.py
  4. 10
      discord/ui/section.py
  5. 32
      discord/ui/view.py

6
discord/ui/action_row.py

@ -207,12 +207,6 @@ class ActionRow(Item[V]):
is_fully_dynamic = False
return is_fully_dynamic
def is_dispatchable(self) -> bool:
return any(c.is_dispatchable() for c in self.children)
def is_persistent(self) -> bool:
return all(c.is_persistent() for c in self.children)
def _update_children_view(self, view: LayoutView) -> None:
for child in self._children:
child._view = view # pyright: ignore[reportAttributeAccessIssue]

6
discord/ui/container.py

@ -213,12 +213,6 @@ class Container(Item[V]):
return children
def is_dispatchable(self) -> bool:
return bool(self.__dispatchable)
def is_persistent(self) -> bool:
return all(c.is_persistent() for c in self.children)
def __init_subclass__(cls) -> None:
super().__init_subclass__()

5
discord/ui/item.py

@ -83,11 +83,6 @@ class Item(Generic[V]):
self._max_row: int = 5 if not self._is_v2() else 40
self._parent: Optional[Item] = None
if self._is_v2():
# this is done so v2 components can be stored on ViewStore._views
# and does not break v1 components custom_id property
self.custom_id: str = os.urandom(16).hex()
def to_component_dict(self) -> Dict[str, Any]:
raise NotImplementedError

10
discord/ui/section.py

@ -117,16 +117,6 @@ class Section(Item[V]):
def _is_v2(self) -> bool:
return True
# Accessory can be a button, and thus it can have a callback so, maybe
# allow for section to be dispatchable and make the callback func
# be accessory component callback, only called if accessory is
# dispatchable?
def is_dispatchable(self) -> bool:
return self.accessory.is_dispatchable()
def is_persistent(self) -> bool:
return self.accessory.is_persistent()
def walk_children(self) -> Generator[Item[V], None, None]:
"""An iterator that recursively walks through all the children of this section.
and it's children, if applicable.

32
discord/ui/view.py

@ -1057,39 +1057,13 @@ class ViewStore:
dispatch_info = self._views.setdefault(message_id, {})
is_fully_dynamic = True
for item in view._children:
for item in view.walk_children():
if isinstance(item, DynamicItem):
pattern = item.__discord_ui_compiled_template__
self._dynamic_items[pattern] = item.__class__
elif item.is_dispatchable():
if getattr(item, '__discord_ui_container__', False):
is_fully_dynamic = (
item._update_store_data( # type: ignore
dispatch_info,
self._dynamic_items,
)
or is_fully_dynamic
)
elif getattr(item, '__discord_ui_action_row__', False):
is_fully_dynamic = (
item._update_store_data( # type: ignore
dispatch_info,
self._dynamic_items,
)
or is_fully_dynamic
)
elif getattr(item, '__discord_ui_section__', False):
accessory: Item = item.accessory # type: ignore
accessory._view = view
if isinstance(accessory, DynamicItem):
pattern = accessory.__discord_ui_compiled_template__
self._dynamic_items[pattern] = accessory.__class__
else:
dispatch_info[(accessory.type.value, accessory.custom_id)] = accessory
else:
dispatch_info[(item.type.value, item.custom_id)] = item
is_fully_dynamic = False
dispatch_info[(item.type.value, item.custom_id)] = item
is_fully_dynamic = False
view._cache_key = message_id
if message_id is not None and not is_fully_dynamic:

Loading…
Cancel
Save