From 7fc58421b06e8db9287f3f0ae7d03f2a6e0fc1b4 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Tue, 26 May 2020 15:35:28 +0600 Subject: [PATCH] Add dialogue::{TransitionIn, TransitionOut} --- examples/dialogue_bot/src/transitions.rs | 14 +++++++------- src/dispatching/dialogue/mod.rs | 5 +++++ src/prelude.rs | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/dialogue_bot/src/transitions.rs b/examples/dialogue_bot/src/transitions.rs index f9da1920..b19e4bfd 100644 --- a/examples/dialogue_bot/src/transitions.rs +++ b/examples/dialogue_bot/src/transitions.rs @@ -2,17 +2,17 @@ use teloxide::prelude::*; use super::{favourite_music::FavouriteMusic, states::*}; -pub type Cx = DialogueWithCx; -pub type Res = ResponseResult>; +pub type In = TransitionIn; +pub type Out = TransitionOut; -pub async fn start(cx: Cx) -> Res { +pub async fn start(cx: In) -> Out { let (cx, dialogue) = cx.unpack(); cx.answer("Let's start! First, what's your full name?").send().await?; next(dialogue.up()) } -pub async fn receive_full_name(cx: Cx) -> Res { +pub async fn receive_full_name(cx: In) -> Out { let (cx, dialogue) = cx.unpack(); match cx.update.text_owned() { @@ -27,7 +27,7 @@ pub async fn receive_full_name(cx: Cx) -> Res { } } -pub async fn receive_age(cx: Cx) -> Res { +pub async fn receive_age(cx: In) -> Out { let (cx, dialogue) = cx.unpack(); match cx.update.text().map(str::parse) { @@ -46,8 +46,8 @@ pub async fn receive_age(cx: Cx) -> Res { } pub async fn receive_favourite_music( - cx: Cx, -) -> Res { + cx: In, +) -> Out { let (cx, dialogue) = cx.unpack(); match cx.update.text().map(str::parse) { diff --git a/src/dispatching/dialogue/mod.rs b/src/dispatching/dialogue/mod.rs index 2a9b07ea..d88a939d 100644 --- a/src/dispatching/dialogue/mod.rs +++ b/src/dispatching/dialogue/mod.rs @@ -49,6 +49,7 @@ mod dialogue_with_cx; mod get_chat_id; mod storage; +use crate::{requests::ResponseResult, types::Message}; pub use dialogue_dispatcher::DialogueDispatcher; pub use dialogue_dispatcher_handler::DialogueDispatcherHandler; pub use dialogue_stage::{exit, next, DialogueStage, DialogueWrapper}; @@ -218,3 +219,7 @@ macro_rules! up { )+ }; } + +pub type TransitionIn = + DialogueWithCx; +pub type TransitionOut = ResponseResult>; diff --git a/src/prelude.rs b/src/prelude.rs index fe23a2c6..43e29238 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,7 +5,7 @@ pub use crate::{ dispatching::{ dialogue::{ exit, next, DialogueDispatcher, DialogueStage, DialogueWithCx, - DialogueWrapper, GetChatId, + DialogueWrapper, GetChatId, TransitionIn, TransitionOut, }, Dispatcher, DispatcherHandlerRx, DispatcherHandlerRxExt, UpdateWithCx, },