spockbot.plugins.tools.task module

class spockbot.plugins.tools.task.Task(task, parent=None, name=None)

Bases: object

continue_with(func)
on_error(exception)
on_event(event, data)
on_success(data)
parse_response(response)
register(response)
run(task_manager)
tasktrace

List of all parent tasks up to this one.

Returns:List[Task]
class spockbot.plugins.tools.task.TaskCallback(cb=None, eb=None)

Bases: object

on_error(error)
on_success(data)
exception spockbot.plugins.tools.task.TaskFailed(message, *args)

Bases: Exception

Raising this exception in any task stops it and signalizes the parent task that the task was aborted due to an error.

message

str

Description of the failure

tasktrace

List[Task]

List of all failed tasks since raising this error.

prev_error

TaskFailed

The previous error, if any. Provide via with_error().

__str__()

Newline-separated text with all failed tasks and all previous errors.

full_tasktrace

List of all failed tasks caused by this and all previous errors.

Returns:List[Task]
with_error(prev_error)

Sets the previous error and returns self.

When re-throwing a TaskFailed, you can provide a new, more high level failure description and pass along the previously failed tasks to still be able to reconstruct the full history of failed tasks.

Examples

Re-throw a TaskFailed with a new, more high level description.

>>> try:
...     raise TaskFailed('Low level', {'some': 1}, 'args')
... except TaskFailed as prev_err:
...     raise TaskFailed('High level').with_error(prev_err)
Returns:TaskFailed
spockbot.plugins.tools.task.accept(evt, data)
spockbot.plugins.tools.task.check_key(key, value)

Generates a check function for a certain key-value pair.

Creates and returns a function that takes two arguments (event, data) and checks data[key] and value for equality.

This is supposed to be used as a check function generator for the yield statements in tasks.

Example

Wait for the next player_join event that has its name set to Bob, i.e. data = {'name': 'Bob'}.

>>> def my_task():
...     yield 'player_join', check_key('name', 'Bob')