mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-06 11:57:17 +00:00
Mark state refresh methods as private with an underscore
People kept wondering what it is or what it does.
This commit is contained in:
parent
6dd8845e4f
commit
934ab4151a
@ -224,7 +224,7 @@ class Button(Item[V]):
|
|||||||
return self.url is not None
|
return self.url is not None
|
||||||
return super().is_persistent()
|
return super().is_persistent()
|
||||||
|
|
||||||
def refresh_component(self, button: ButtonComponent) -> None:
|
def _refresh_component(self, button: ButtonComponent) -> None:
|
||||||
self._underlying = button
|
self._underlying = button
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,10 +72,10 @@ class Item(Generic[V]):
|
|||||||
def to_component_dict(self) -> Dict[str, Any]:
|
def to_component_dict(self) -> Dict[str, Any]:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def refresh_component(self, component: Component) -> None:
|
def _refresh_component(self, component: Component) -> None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def refresh_state(self, data: Dict[str, Any]) -> None:
|
def _refresh_state(self, data: Dict[str, Any]) -> None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -171,7 +171,7 @@ class Modal(View):
|
|||||||
print(f'Ignoring exception in modal {self}:', file=sys.stderr)
|
print(f'Ignoring exception in modal {self}:', file=sys.stderr)
|
||||||
traceback.print_exception(error.__class__, error, error.__traceback__, file=sys.stderr)
|
traceback.print_exception(error.__class__, error, error.__traceback__, file=sys.stderr)
|
||||||
|
|
||||||
def refresh(self, components: Sequence[ModalSubmitComponentInteractionDataPayload]) -> None:
|
def _refresh(self, components: Sequence[ModalSubmitComponentInteractionDataPayload]) -> None:
|
||||||
for component in components:
|
for component in components:
|
||||||
if component['type'] == 1:
|
if component['type'] == 1:
|
||||||
self.refresh(component['components'])
|
self.refresh(component['components'])
|
||||||
@ -180,7 +180,7 @@ class Modal(View):
|
|||||||
if item is None:
|
if item is None:
|
||||||
_log.debug("Modal interaction referencing unknown item custom_id %s. Discarding", component['custom_id'])
|
_log.debug("Modal interaction referencing unknown item custom_id %s. Discarding", component['custom_id'])
|
||||||
continue
|
continue
|
||||||
item.refresh_state(component) # type: ignore
|
item._refresh_state(component) # type: ignore
|
||||||
|
|
||||||
async def _scheduled_task(self, interaction: Interaction):
|
async def _scheduled_task(self, interaction: Interaction):
|
||||||
try:
|
try:
|
||||||
|
@ -266,10 +266,10 @@ class Select(Item[V]):
|
|||||||
def to_component_dict(self) -> SelectMenuPayload:
|
def to_component_dict(self) -> SelectMenuPayload:
|
||||||
return self._underlying.to_dict()
|
return self._underlying.to_dict()
|
||||||
|
|
||||||
def refresh_component(self, component: SelectMenu) -> None:
|
def _refresh_component(self, component: SelectMenu) -> None:
|
||||||
self._underlying = component
|
self._underlying = component
|
||||||
|
|
||||||
def refresh_state(self, data: MessageComponentInteractionData) -> None:
|
def _refresh_state(self, data: MessageComponentInteractionData) -> None:
|
||||||
self._selected_values = data.get('values', [])
|
self._selected_values = data.get('values', [])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -207,10 +207,10 @@ class TextInput(Item[V]):
|
|||||||
def to_component_dict(self) -> TextInputPayload:
|
def to_component_dict(self) -> TextInputPayload:
|
||||||
return self._underlying.to_dict()
|
return self._underlying.to_dict()
|
||||||
|
|
||||||
def refresh_component(self, component: TextInputComponent) -> None:
|
def _refresh_component(self, component: TextInputComponent) -> None:
|
||||||
self._underlying = component
|
self._underlying = component
|
||||||
|
|
||||||
def refresh_state(self, data: ModalSubmitTextInputInteractionDataPayload) -> None:
|
def _refresh_state(self, data: ModalSubmitTextInputInteractionDataPayload) -> None:
|
||||||
self._value = data.get('value', None)
|
self._value = data.get('value', None)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -397,7 +397,7 @@ class View:
|
|||||||
|
|
||||||
asyncio.create_task(self._scheduled_task(item, interaction), name=f'discord-ui-view-dispatch-{self.id}')
|
asyncio.create_task(self._scheduled_task(item, interaction), name=f'discord-ui-view-dispatch-{self.id}')
|
||||||
|
|
||||||
def refresh(self, components: List[Component]) -> None:
|
def _refresh(self, components: List[Component]) -> None:
|
||||||
# This is pretty hacky at the moment
|
# This is pretty hacky at the moment
|
||||||
# fmt: off
|
# fmt: off
|
||||||
old_state: Dict[Tuple[int, str], Item[Any]] = {
|
old_state: Dict[Tuple[int, str], Item[Any]] = {
|
||||||
@ -413,7 +413,7 @@ class View:
|
|||||||
except (KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
children.append(_component_to_item(component))
|
children.append(_component_to_item(component))
|
||||||
else:
|
else:
|
||||||
older.refresh_component(component)
|
older._refresh_component(component)
|
||||||
children.append(older)
|
children.append(older)
|
||||||
|
|
||||||
self.children = children
|
self.children = children
|
||||||
@ -536,7 +536,7 @@ class ViewStore:
|
|||||||
return
|
return
|
||||||
|
|
||||||
view, item = value
|
view, item = value
|
||||||
item.refresh_state(interaction.data) # type: ignore
|
item._refresh_state(interaction.data) # type: ignore
|
||||||
view._dispatch_item(item, interaction)
|
view._dispatch_item(item, interaction)
|
||||||
|
|
||||||
def dispatch_modal(
|
def dispatch_modal(
|
||||||
@ -550,7 +550,7 @@ class ViewStore:
|
|||||||
_log.debug("Modal interaction referencing unknown custom_id %s. Discarding", custom_id)
|
_log.debug("Modal interaction referencing unknown custom_id %s. Discarding", custom_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
modal.refresh(components)
|
modal._refresh(components)
|
||||||
modal._dispatch_submit(interaction)
|
modal._dispatch_submit(interaction)
|
||||||
|
|
||||||
def is_message_tracked(self, message_id: int) -> bool:
|
def is_message_tracked(self, message_id: int) -> bool:
|
||||||
@ -562,4 +562,4 @@ class ViewStore:
|
|||||||
def update_from_message(self, message_id: int, components: List[ComponentPayload]) -> None:
|
def update_from_message(self, message_id: int, components: List[ComponentPayload]) -> None:
|
||||||
# pre-req: is_message_tracked == true
|
# pre-req: is_message_tracked == true
|
||||||
view = self._synced_message_views[message_id]
|
view = self._synced_message_views[message_id]
|
||||||
view.refresh([_component_factory(d) for d in components])
|
view._refresh([_component_factory(d) for d in components])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user