raito.plugins.scenes.manager moduleΒΆ
- class raito.plugins.scenes.manager.SceneManager(router, states, data_type)[source]ΒΆ
Bases:
Generic[TSceneData]A scene: the steps of a
StatesGroup, its draft type, and its handlers.Returned by
raito.Router.scene(). Register handlers through the per-event registrarson_message,on_callback_query,on_edited_messageβscene.on_message.enter(...)to start,scene.on_message(state, ...)/scene.on_callback_query(state, ...)for steps. ASceneMiddlewarecallscleanup()before them to drop a stale scene, and each active handler receives aScenehandle that persists the draft throughpersist()/clear().- async cleanup(state, raw_state)[source]ΒΆ
Clear the active scene if
raw_statebelongs to it but no longer exists.Cheap when the update is not sitting in this scene: it returns
Falseafter a string check, without touching storage.
- async begin(state, base, data, *, at=None)[source]ΒΆ
Seed a fresh draft for this scene and switch to a step.
Used by
Scene.start()andScene.restart()to (re)enter a scene; it replaces whatever scene payload is currently stored under the FSM key.- Parameters:
state (FSMContext) β FSM context for the current chat/user
base (dict[str, Any] | None) β FSM data already read this update, or
Noneto read it nowdata (dict[str, object]) β initial fields for the draft, validated against the
SceneDataat (State | None) β step to open at; defaults to the first step
- Raises:
ValueError β if
atis not a step of this scene- Return type:
None
- build_handler(callback, event_name, *, entry)[source]ΒΆ
Wrap a user callback into a scene handler.
The wrapper hydrates a
Scenehandle β a fresh draft for an entry handler, the stored one for a step handler β and injects both the event (underevent_name) andsceneinto the callback. The step is resolved fromraw_stateat call time, so one wrapper serves a specific step orSceneRegistry.any().