raito.plugins.scenes.manager module¶
- class raito.plugins.scenes.manager.SceneManager(router, states, data_type)[исходный код]¶
Базовые классы:
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)[исходный код]¶
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 persist(state, draft, base)[исходный код]¶
Snapshot the draft into FSM storage.
- async clear(state, base)[исходный код]¶
Remove only this scene’s payload and reset the FSM state.
- async begin(state, base, data, *, at=None)[исходный код]¶
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.- Параметры:
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
- Исключение:
ValueError – if
atis not a step of this scene- Тип результата:
None
- build_handler(callback, event_name, *, entry)[исходный код]¶
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().