raito.plugins.scenes.registry module

class raito.plugins.scenes.registry.SceneRegistry(scene, observer, name, middleware)[source]

Bases: object

Registers a scene’s handlers for one aiogram event type.

A scene exposes one of these per event as scene.on_message, scene.on_callback_query, and scene.on_edited_message. Call it with a step’s state to handle that step, use any() for a handler that runs on every step, or use enter() to start the scene. Its SceneMiddleware is installed on the observer only when the first handler is added, so an event type without scene handlers is never touched.

Parameters:
any(*filters)[source]

Register a handler that runs on any active step of this scene.

Useful for something that should work no matter where the user is in the dialog, e.g. a /cancel command or a persistent “Cancel” button:

@mute.on_message.any(filters.Command("cancel"))
async def cancel_anywhere(scene: Scene[MuteData]) -> None:
    await scene.cancel()
Parameters:

filters (CallbackType) – filters applied on top of “any step of this scene”

Returns:

decorator for the handler

Return type:

Callable[[CallbackType], CallbackType]

enter(*filters)[source]

Register a handler that starts the scene from a fresh draft.

Parameters:

filters (CallbackType) – filters that trigger the scene, e.g. Command("mute")

Returns:

decorator for the entry handler

Return type:

Callable[[CallbackType], CallbackType]