raito.plugins.scenes.scene module¶
- class raito.plugins.scenes.scene.Scene(manager, state, *, data, step, base)[исходный код]¶
Базовые классы:
Generic[TSceneData]Per-update handle to an active scene, injected into every handler as
scene.Carries the typed draft (
data) and the verbs to move between steps. One instance is built per update and discarded when the handler returns, so it never outlives a single message nor holds a resource.Navigation only changes state: it saves the draft and switches the FSM step. It never sends anything — reply with the message you already have (
await message.answer(...)), which exposes every Telegram option natively.- Параметры:
manager (SceneManager[TSceneData])
state (FSMContext)
data (TSceneData)
step (State | None)
- data¶
- async goto(target)[исходный код]¶
Save the draft and switch to
target.- Параметры:
target (State) – step to activate next
- Исключение:
ValueError – if
targetis not a step of this scene- Тип результата:
None
- async next()[исходный код]¶
Save the draft and advance to the next step (the first one, from entry).
- Тип результата:
None
- async back()[исходный код]¶
Save the draft and return to the previous step.
- Тип результата:
None
- async retry()[исходный код]¶
Stay on the current step, saving the draft.
- Тип результата:
None
- async finish()[исходный код]¶
End the scene, clearing only its own FSM payload.
- Тип результата:
None
- async cancel()[исходный код]¶
Alias of
finish()for an explicit cancellation path.- Тип результата:
None
- async escape()[исходный код]¶
Cancel the scene and let this update reach the next matching handler.
Use this to let an unrelated command interrupt the scene, e.g.
/startarriving mid-dialog. Combine withSceneRegistry.any()to catch it regardless of which step the user is on:@mute.on_message.any(F.text.startswith("/")) async def escape_on_any_command(scene: Scene[MuteData]) -> None: await scene.escape()
A plain
cancel()would still swallow the update — nothing else gets a turn at it.escapeclears the scene, then re-raises so aiogram keeps looking, exactly as if this handler had never matched (a real/starthandler registered after this one still runs for the same update).- Тип результата:
- async restart()[исходный код]¶
Discard the current draft and start this scene over from its first step.
- Тип результата:
None
- async start(target, *, at=None, **data)[исходный код]¶
End this scene and start
target, seeding its draft fromdata.The current payload is replaced by a fresh draft for
target, validated against itsSceneData. Send the target’s first prompt yourself, as with any navigation.- Параметры:
target (SceneManager[Any]) – scene to hand the dialog off to
at (State | None) – step to open
targetat; defaults to its first stepdata (object) – initial fields for the target’s draft
- Исключение:
ValueError – if
atis not a step oftarget- Тип результата:
None