Script Function#
This module provides base classes for functions used in Script
instances.
These functions allow dynamic script configuration and are essential to the scripting process.
- class BaseScriptFunc(**data)[source]#
Bases:
BaseModel
,ABC
Base class for any script function.
Defines
wrapped_call()
that wrapscall()
and handles exceptions and types conversions.- return_type: ClassVar[Union[type, Tuple[type, ...]]]#
Return type of the script function.
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__()
.- Returns:
An instance of
return_type
if possible. Otherwise, anException
instance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call()
:Call it (regardless of whether it is async);
Cast returned value to
return_type
.
- Returns:
An instance of
return_type
.- Raises:
TypeError – If
call()
returned value of incorrect type.
- class ConstScriptFunc(**data)[source]#
Bases:
BaseScriptFunc
Base class for script functions that return a constant value.
- root: None#
Value to return.
- class BaseCondition(**data)[source]#
Bases:
BaseScriptFunc
,ABC
Base class for condition functions.
These are used in
chatsky.core.transition.Transition.cnd
.- return_type#
alias of
bool
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__()
.- Return type:
Union
[bool
,Exception
]- Returns:
An instance of
return_type
if possible. Otherwise, anException
instance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call()
:Call it (regardless of whether it is async);
Cast returned value to
return_type
.
- Return type:
bool
- Returns:
An instance of
return_type
.- Raises:
TypeError – If
call()
returned value of incorrect type.
- async is_true(ctx, *, info='')[source]#
Same as
wrapped_call()
but instead of exceptions returnFalse
.- Return type:
bool
- class ConstCondition(**data)[source]#
Bases:
ConstScriptFunc
,BaseCondition
- root: bool#
Value to return.
- AnyCondition#
A type annotation that allows accepting both
ConstCondition
andBaseCondition
while validatingConstCondition
if possible.alias of
Union
[ConstCondition
,BaseCondition
][Union
[ConstCondition
,BaseCondition
]]
- class BaseResponse(**data)[source]#
Bases:
BaseScriptFunc
,ABC
Base class for response functions.
These are used in
chatsky.core.script.Node.response
.- abstract async call(ctx)[source]#
Implement this to create a custom function.
- Return type:
Union
[Message
,dict
,str
]
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__()
.- Return type:
Union
[Message
,Exception
]- Returns:
An instance of
return_type
if possible. Otherwise, anException
instance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call()
:Call it (regardless of whether it is async);
Cast returned value to
return_type
.
- Return type:
- Returns:
An instance of
return_type
.- Raises:
TypeError – If
call()
returned value of incorrect type.
- class ConstResponse(**data)[source]#
Bases:
ConstScriptFunc
,BaseResponse
- root: Message#
Value to return.
- AnyResponse#
A type annotation that allows accepting both
ConstResponse
andBaseResponse
while validatingConstResponse
if possible.alias of
Union
[ConstResponse
,BaseResponse
][Union
[ConstResponse
,BaseResponse
]]
- class BaseDestination(**data)[source]#
Bases:
BaseScriptFunc
,ABC
Base class for destination functions.
These are used in
chatsky.core.transition.Transition.dst
.- return_type#
alias of
AbsoluteNodeLabel
- abstract async call(ctx)[source]#
Implement this to create a custom function.
- Return type:
Union
[NodeLabel
,str
,Tuple
[str
,str
],List
[str
],dict
]
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__()
.- Return type:
Union
[AbsoluteNodeLabel
,Exception
]- Returns:
An instance of
return_type
if possible. Otherwise, anException
instance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call()
:Call it (regardless of whether it is async);
Cast returned value to
return_type
.
- Return type:
- Returns:
An instance of
return_type
.- Raises:
TypeError – If
call()
returned value of incorrect type.
- class ConstDestination(**data)[source]#
Bases:
ConstScriptFunc
,BaseDestination
- root: NodeLabel#
Value to return.
- AnyDestination#
A type annotation that allows accepting both
ConstDestination
andBaseDestination
while validatingConstDestination
if possible.alias of
Union
[ConstDestination
,BaseDestination
][Union
[ConstDestination
,BaseDestination
]]
- class BaseProcessing(**data)[source]#
Bases:
BaseScriptFunc
,ABC
Base class for processing functions.
These are used in
chatsky.core.script.Node.pre_transition
andchatsky.core.script.Node.pre_response
.- return_type#
alias of
None
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__()
.- Return type:
Optional
[Exception
]- Returns:
An instance of
return_type
if possible. Otherwise, anException
instance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call()
:Call it (regardless of whether it is async);
Cast returned value to
return_type
.
- Return type:
None
- Returns:
An instance of
return_type
.- Raises:
TypeError – If
call()
returned value of incorrect type.
- class BasePriority(**data)[source]#
Bases:
BaseScriptFunc
,ABC
Base class for priority functions.
These are used in
chatsky.core.transition.Transition.priority
.Has several possible return types:
float
: Transition successful with the corresponding priority;True
orNone
: Transition successful with thedefault_priority
;False
: Transition unsuccessful.
- return_type: ClassVar[Union[type, Tuple[type, ...]]] = (<class 'float'>, <class 'NoneType'>, <class 'bool'>)#
Return type of the script function.
- abstract async call(ctx)[source]#
Implement this to create a custom function.
- Return type:
Union
[float
,bool
,None
]
- async wrapped_call(ctx, *, info='')[source]#
Exception-safe wrapper for
__call__()
.- Return type:
Union
[float
,bool
,None
,Exception
]- Returns:
An instance of
return_type
if possible. Otherwise, anException
instance detailing what went wrong.
- async __call__(ctx)[source]#
Handle
call()
:Call it (regardless of whether it is async);
Cast returned value to
return_type
.
- Return type:
Union
[float
,bool
,None
]- Returns:
An instance of
return_type
.- Raises:
TypeError – If
call()
returned value of incorrect type.
- class ConstPriority(**data)[source]#
Bases:
ConstScriptFunc
,BasePriority
- root: Optional[float]#
Value to return.
- AnyPriority#
A type annotation that allows accepting both
ConstPriority
andBasePriority
while validatingConstPriority
if possible.alias of
Union
[ConstPriority
,BasePriority
][Union
[ConstPriority
,BasePriority
]]