Update examples/dialogue_bot

This commit is contained in:
Temirkhan Myrzamadi 2020-07-31 18:47:20 +06:00
parent 0445a803ca
commit e2d536bc91
3 changed files with 10 additions and 26 deletions

View file

@ -309,8 +309,6 @@ Finally, the `main` function looks like this:
```rust
// Imports are omitted...
type In = DialogueWithCx<Message, Dialogue, Infallible>;
#[tokio::main]
async fn main() {
teloxide::enable_logging!();
@ -318,15 +316,10 @@ async fn main() {
let bot = Bot::from_env();
Dispatcher::new(bot)
.messages_handler(DialogueDispatcher::new(
|DialogueWithCx { cx, dialogue }: In| async move {
let dialogue = dialogue.expect("std::convert::Infallible");
handle_message(cx, dialogue).await.expect("Something wrong with the bot!")
},
))
.dispatch()
.await;
teloxide::dialogues_repl(bot, |message, dialogue| async move {
handle_message(message, dialogue).await.expect("Something wrong with the bot!")
})
.await;
}
async fn handle_message(cx: UpdateWithCx<Message>, dialogue: Dialogue) -> TransitionOut<Dialogue> {
@ -338,7 +331,6 @@ async fn handle_message(cx: UpdateWithCx<Message>, dialogue: Dialogue) -> Transi
Some(ans) => dialogue.react(cx, ans).await,
}
}
```
<div align="center">

View file

@ -23,11 +23,8 @@ extern crate frunk;
mod dialogue;
use crate::dialogue::Dialogue;
use std::convert::Infallible;
use teloxide::prelude::*;
type In = DialogueWithCx<Message, Dialogue, Infallible>;
#[tokio::main]
async fn main() {
run().await;
@ -39,15 +36,10 @@ async fn run() {
let bot = Bot::from_env();
Dispatcher::new(bot)
.messages_handler(DialogueDispatcher::new(
|DialogueWithCx { cx, dialogue }: In| async move {
let dialogue = dialogue.expect("std::convert::Infallible");
handle_message(cx, dialogue).await.expect("Something wrong with the bot!")
},
))
.dispatch()
.await;
teloxide::dialogues_repl(bot, |message, dialogue| async move {
handle_message(message, dialogue).await.expect("Something wrong with the bot!")
})
.await;
}
async fn handle_message(cx: UpdateWithCx<Message>, dialogue: Dialogue) -> TransitionOut<Dialogue> {

View file

@ -27,7 +27,7 @@ pub async fn dialogues_repl<'a, H, D, Fut>(bot: Bot, handler: H)
where
H: Fn(UpdateWithCx<Message>, D) -> Fut + Send + Sync + 'static,
D: Default + Send + 'static,
Fut: Future<Output = DialogueStage<D>> + Send + Sync + 'static,
Fut: Future<Output = DialogueStage<D>> + Send + 'static,
{
let cloned_bot = bot.clone();
@ -54,7 +54,7 @@ pub async fn dialogues_repl_with_listener<'a, H, D, Fut, L, ListenerE>(
) where
H: Fn(UpdateWithCx<Message>, D) -> Fut + Send + Sync + 'static,
D: Default + Send + 'static,
Fut: Future<Output = DialogueStage<D>> + Send + Sync + 'static,
Fut: Future<Output = DialogueStage<D>> + Send + 'static,
L: UpdateListener<ListenerE> + Send + 'a,
ListenerE: Debug + Send + 'a,
{