diff --git a/README.md b/README.md index 938beffc..093eaa5f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - + 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,14 +102,11 @@ async fn main() { let bot = Bot::from_env(); - Dispatcher::new(bot) - .messages_handler(|rx: DispatcherHandlerRx| { - rx.for_each(|message| async move { - message.send_dice().send().await.log_on_error().await; - }) - }) - .dispatch() - .await; + repl(bot, |message| async move { + message.send_dice().send().await?; + Ok(()) + }) + .await; } ``` diff --git a/examples/dices_bot/src/main.rs b/examples/dices_bot/src/main.rs index be2386eb..64a52f78 100644 --- a/examples/dices_bot/src/main.rs +++ b/examples/dices_bot/src/main.rs @@ -13,12 +13,9 @@ async fn run() { let bot = Bot::from_env(); - Dispatcher::new(bot) - .messages_handler(|rx: DispatcherHandlerRx| { - rx.for_each(|message| async move { - message.send_dice().send().await.log_on_error().await; - }) - }) - .dispatch() - .await; + repl(bot, |message| async move { + message.send_dice().send().await?; + Ok(()) + }) + .await; } diff --git a/src/dispatching/mod.rs b/src/dispatching/mod.rs index a99c954e..02306349 100644 --- a/src/dispatching/mod.rs +++ b/src/dispatching/mod.rs @@ -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| { -//! rx.for_each(|message| async move { -//! message.send_dice().send().await.log_on_error().await; -//! }) -//! }) -//! .dispatch() -//! .await; -//! # } -//! ``` -//! -//!
-//! -//! -//! -//!
-//! -//! [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 diff --git a/src/lib.rs b/src/lib.rs index f4e60912..9079e39b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; +//! # } +//! ``` +//! +//!
+//! +//! +//! +//!
+//! //! [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/