mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 23:57:38 +01:00
Prettify examples/dialogues_bot a little bit
This commit is contained in:
parent
01dc7a0d42
commit
c9393aa5d6
2 changed files with 6 additions and 19 deletions
|
@ -20,21 +20,15 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate frunk;
|
extern crate frunk;
|
||||||
|
|
||||||
use frunk::Coproduct;
|
|
||||||
|
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
|
use parse_display::{Display, FromStr};
|
||||||
|
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
types::{KeyboardButton, ReplyKeyboardMarkup},
|
types::{KeyboardButton, ReplyKeyboardMarkup},
|
||||||
};
|
};
|
||||||
|
|
||||||
use parse_display::{Display, FromStr};
|
|
||||||
use teloxide::dispatching::dialogue::next;
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// [Favourite music kinds]
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Display, FromStr)]
|
#[derive(Copy, Clone, Display, FromStr)]
|
||||||
enum FavouriteMusic {
|
enum FavouriteMusic {
|
||||||
Rock,
|
Rock,
|
||||||
|
@ -54,9 +48,7 @@ impl FavouriteMusic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// Dialogue states.
|
||||||
// [A type-safe finite automaton]
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
struct StartState;
|
struct StartState;
|
||||||
|
|
||||||
|
@ -103,9 +95,7 @@ wrap_dialogue!(
|
||||||
default { Self(Dialogue::inject(StartState)) }
|
default { Self(Dialogue::inject(StartState)) }
|
||||||
);
|
);
|
||||||
|
|
||||||
// ============================================================================
|
// Transition functions.
|
||||||
// [Control a dialogue]
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
type Cx<State> = DialogueDispatcherHandlerCx<Message, State, Infallible>;
|
type Cx<State> = DialogueDispatcherHandlerCx<Message, State, Infallible>;
|
||||||
type Res = ResponseResult<DialogueStage<Wrapper>>;
|
type Res = ResponseResult<DialogueStage<Wrapper>>;
|
||||||
|
@ -171,10 +161,6 @@ async fn favourite_music(cx: Cx<ReceiveFavouriteMusicState>) -> Res {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// [Run!]
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
run().await;
|
run().await;
|
||||||
|
|
|
@ -17,5 +17,6 @@ pub use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use tokio::sync::mpsc::UnboundedReceiver;
|
pub use tokio::sync::mpsc::UnboundedReceiver;
|
||||||
|
pub use frunk::Coproduct;
|
||||||
|
|
||||||
pub use futures::StreamExt;
|
pub use futures::StreamExt;
|
||||||
|
|
Loading…
Add table
Reference in a new issue