Use repl in examples/dices_bot

This commit is contained in:
Temirkhan Myrzamadi 2020-07-30 19:07:58 +06:00
parent 461e1150e5
commit 67af702a81
4 changed files with 37 additions and 49 deletions

View file

@ -15,7 +15,7 @@
<img src="https://img.shields.io/badge/official%20chat-t.me%2Fteloxide-blueviolet">
</a>
<a href="https://core.telegram.org/bots/api">
<img src="https://img.shields.io/badge/API coverage-Up to 0.4.9 (inclusively)-green.svg">
<img src="https://img.shields.io/badge/API coverage-Up to 0.4.7 (inclusively)-green.svg">
</a>
A full-featured framework that empowers you to easily build [Telegram bots](https://telegram.org/blog/bot-revolution) using the [`async`/`.await`](https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html) syntax in [Rust](https://www.rust-lang.org/). It handles all the difficult stuff so you can focus only on your business logic.
@ -102,13 +102,10 @@ async fn main() {
let bot = Bot::from_env();
Dispatcher::new(bot)
.messages_handler(|rx: DispatcherHandlerRx<Message>| {
rx.for_each(|message| async move {
message.send_dice().send().await.log_on_error().await;
repl(bot, |message| async move {
message.send_dice().send().await?;
Ok(())
})
})
.dispatch()
.await;
}

View file

@ -13,12 +13,9 @@ async fn run() {
let bot = Bot::from_env();
Dispatcher::new(bot)
.messages_handler(|rx: DispatcherHandlerRx<Message>| {
rx.for_each(|message| async move {
message.send_dice().send().await.log_on_error().await;
repl(bot, |message| async move {
message.send_dice().send().await?;
Ok(())
})
})
.dispatch()
.await;
}

View file

@ -30,38 +30,7 @@
//!
//! Since they implement [`DispatcherHandler`] too.
//!
//! # The dices bot
//! This bot throws a dice on each incoming message:
//!
//! ([Full](https://github.com/teloxide/teloxide/blob/master/examples/dices_bot/src/main.rs))
//! ```no_run
//! use teloxide::prelude::*;
//!
//! # #[tokio::main]
//! # async fn main_() {
//! teloxide::enable_logging!();
//! log::info!("Starting dices_bot...");
//!
//! let bot = Bot::from_env();
//!
//! Dispatcher::new(bot)
//! .messages_handler(|rx: DispatcherHandlerRx<Message>| {
//! rx.for_each(|message| async move {
//! message.send_dice().send().await.log_on_error().await;
//! })
//! })
//! .dispatch()
//! .await;
//! # }
//! ```
//!
//! <div align="center">
//! <kbd>
//! <img src=https://github.com/teloxide/teloxide/raw/master/media/DICES_BOT.gif />
//! </kbd>
//! </div>
//!
//! [See more examples](https://github.com/teloxide/teloxide/tree/master/examples).
//! [See the examples](https://github.com/teloxide/teloxide/tree/master/examples).
//!
//! [`Dispatcher`]: crate::dispatching::Dispatcher
//! [all the update kinds]: crate::types::UpdateKind

View file

@ -4,6 +4,31 @@
//!
//! For a high-level overview, see [our GitHub repository](https://github.com/teloxide/teloxide).
//!
//! ([Full](https://github.com/teloxide/teloxide/blob/master/examples/dices_bot/src/main.rs))
//! ```no_run
//! use teloxide::prelude::*;
//!
//! # #[tokio::main]
//! # async fn main_() {
//! teloxide::enable_logging!();
//! log::info!("Starting dices_bot...");
//!
//! let bot = Bot::from_env();
//!
//! repl(bot, |message| async move {
//! message.send_dice().send().await?;
//! Ok(())
//! })
//! .await;
//! # }
//! ```
//!
//! <div align="center">
//! <kbd>
//! <img src=https://github.com/teloxide/teloxide/raw/master/media/DICES_BOT.gif />
//! </kbd>
//! </div>
//!
//! [Telegram bots]: https://telegram.org/blog/bot-revolution
//! [`async`/`.await`]: https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html
//! [Rust]: https://www.rust-lang.org/