mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
Use repl in examples/dices_bot
This commit is contained in:
parent
461e1150e5
commit
67af702a81
4 changed files with 37 additions and 49 deletions
15
README.md
15
README.md
|
@ -15,7 +15,7 @@
|
||||||
<img src="https://img.shields.io/badge/official%20chat-t.me%2Fteloxide-blueviolet">
|
<img src="https://img.shields.io/badge/official%20chat-t.me%2Fteloxide-blueviolet">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://core.telegram.org/bots/api">
|
<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>
|
||||||
|
|
||||||
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.
|
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();
|
let bot = Bot::from_env();
|
||||||
|
|
||||||
Dispatcher::new(bot)
|
repl(bot, |message| async move {
|
||||||
.messages_handler(|rx: DispatcherHandlerRx<Message>| {
|
message.send_dice().send().await?;
|
||||||
rx.for_each(|message| async move {
|
Ok(())
|
||||||
message.send_dice().send().await.log_on_error().await;
|
})
|
||||||
})
|
.await;
|
||||||
})
|
|
||||||
.dispatch()
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -13,12 +13,9 @@ async fn run() {
|
||||||
|
|
||||||
let bot = Bot::from_env();
|
let bot = Bot::from_env();
|
||||||
|
|
||||||
Dispatcher::new(bot)
|
repl(bot, |message| async move {
|
||||||
.messages_handler(|rx: DispatcherHandlerRx<Message>| {
|
message.send_dice().send().await?;
|
||||||
rx.for_each(|message| async move {
|
Ok(())
|
||||||
message.send_dice().send().await.log_on_error().await;
|
})
|
||||||
})
|
.await;
|
||||||
})
|
|
||||||
.dispatch()
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,38 +30,7 @@
|
||||||
//!
|
//!
|
||||||
//! Since they implement [`DispatcherHandler`] too.
|
//! Since they implement [`DispatcherHandler`] too.
|
||||||
//!
|
//!
|
||||||
//! # The dices bot
|
//! [See the examples](https://github.com/teloxide/teloxide/tree/master/examples).
|
||||||
//! 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).
|
|
||||||
//!
|
//!
|
||||||
//! [`Dispatcher`]: crate::dispatching::Dispatcher
|
//! [`Dispatcher`]: crate::dispatching::Dispatcher
|
||||||
//! [all the update kinds]: crate::types::UpdateKind
|
//! [all the update kinds]: crate::types::UpdateKind
|
||||||
|
|
25
src/lib.rs
25
src/lib.rs
|
@ -4,6 +4,31 @@
|
||||||
//!
|
//!
|
||||||
//! For a high-level overview, see [our GitHub repository](https://github.com/teloxide/teloxide).
|
//! 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
|
//! [Telegram bots]: https://telegram.org/blog/bot-revolution
|
||||||
//! [`async`/`.await`]: https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html
|
//! [`async`/`.await`]: https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html
|
||||||
//! [Rust]: https://www.rust-lang.org/
|
//! [Rust]: https://www.rust-lang.org/
|
||||||
|
|
Loading…
Reference in a new issue