Component Factory Implementation¶
Standard implementation of the overarching component factory type.
Classes¶
- asyncbuild_component
- asyncdump_params
- clsfrom_component
- asyncload_params
- class disnake_compass.impl.factory.ComponentFactory(parsers, component)[source]¶
Bases:
ComponentFactory[ComponentT],Generic[ComponentT]Implementation of the overarching component factory type.
A component factory holds information about all the custom id fields of a component, and contains that component’s parsers. In most situations, a component factory can simply be created using
from_component().Attributes¶
Methods¶
- await build_component(params, component_params=None)[source]¶
Create a new component instance from the provided interaction.
This requires the custom id to already have been decomposed into individual fields. This is generally done by the component manager.
- await dump_params(component)[source]¶
Dump a component into a new custom id string.
This converts the component’s individual fields back into strings and and uses these strings to build a new custom id. This is generally done using the
ComponentManager.get_identifier()method.- Parameters:
component (
ComponentT) – The component to dump into a custom id.
- classmethod from_component(component)[source]¶
Create a component factory from the provided component.
This takes the component’s fields into account and generates the corresponding parser types for each field if a parser was not provided manually for that particular field.
- Parameters:
component (type[component_api.ComponentT]) – The component for which to create a component factory.
- asyncbuild_component
- asyncdump_params
- clsfrom_component
- asyncload_params
- class disnake_compass.impl.factory.NoopFactory[source]¶
Bases:
ComponentFactory[Any]Factory class to make component protocols typesafe.
Since component protocols cannot be instantiated, building a factory with parsers for them does not make sense. Instead, they will receive one of these to remain typesafe. Any operation on a NoopFactory will raise
NotImplementedError.Methods¶
- await build_component(params, component_params=None)[source]¶
Create a new component instance from the provided interaction.
This requires the custom id to already have been decomposed into individual fields. This is generally done by the component manager.
- await dump_params(*_)[source]¶
Dump a component into a new custom id string.
This converts the component’s individual fields back into strings and and uses these strings to build a new custom id. This is generally done using the
ComponentManager.get_identifier()method.- Parameters:
component – The component to dump into a custom id.
- classmethod from_component(_)[source]¶
Create a component factory from the provided component.
This takes the component’s fields into account and generates the corresponding parser types for each field if a parser was not provided manually for that particular field.
- Parameters:
component – The component for which to create a component factory.
- await load_params(*_)[source]¶
Create a new component instance from the provided custom id.
This requires the custom id to already have been decomposed into individual fields. This is generally done using the
ComponentManager.get_identifier()method.- Parameters:
params – A mapping of field name to to-be-parsed field values.