Commands

class Command[source]

Base class for all Commands.

Subclass this and add the necessary fields to communicate the command to its Receiver.

Commands should simply carry data to their Receiver, they don’t do anything.

Using @define and field from attrs is recommended to keep it short.

class Receiver(command: Command)[source]

Abstract base class for Command implementations.

Note

Command receivers are located the first time a Command is used by searching through all subclasses of Receiver to find the one that accepts the command. It is cached after the first use.

Note

If any of your Receivers are not being used when they should be, make sure they are imported when your application starts up. Usually, importing them in an __init__.py file or keeping them in the same file with their Command will fix it.

abstract execute_command() ReceiverReturnType[source]

Your code to execute the Command.

classmethod handles_command(command: Command) bool[source]

Determines whether the Command may be executed by this Receiver.

handles_command_cls: ClassVar[type[Command]]

The Command class this receiver should respond to.