Replace examples/ping-pong-bot with examples/dices-bot

This commit is contained in:
Temirkhan Myrzamadi 2020-07-29 16:02:37 +06:00
parent a6eac93043
commit e74196a62f
6 changed files with 16 additions and 17 deletions

View file

@ -53,7 +53,7 @@ jobs:
dialogue_bot, dialogue_bot,
heroku_ping_pong_bot, heroku_ping_pong_bot,
ngrok_ping_pong_bot, ngrok_ping_pong_bot,
ping_pong_bot, dices_bot,
shared_state_bot, shared_state_bot,
simple_commands_bot, simple_commands_bot,
] ]

View file

@ -25,7 +25,7 @@
- [Highlights](https://github.com/teloxide/teloxide#highlights) - [Highlights](https://github.com/teloxide/teloxide#highlights)
- [Setting up your environment](https://github.com/teloxide/teloxide#setting-up-your-environment) - [Setting up your environment](https://github.com/teloxide/teloxide#setting-up-your-environment)
- [API overview](https://github.com/teloxide/teloxide#api-overview) - [API overview](https://github.com/teloxide/teloxide#api-overview)
- [The ping-pong bot](https://github.com/teloxide/teloxide#the-ping-pong-bot) - [The dices bot](https://github.com/teloxide/teloxide#the-dices-bot)
- [Commands](https://github.com/teloxide/teloxide#commands) - [Commands](https://github.com/teloxide/teloxide#commands)
- [Dialogues management](https://github.com/teloxide/teloxide#dialogues-management) - [Dialogues management](https://github.com/teloxide/teloxide#dialogues-management)
- [Recommendations](https://github.com/teloxide/teloxide#recommendations) - [Recommendations](https://github.com/teloxide/teloxide#recommendations)
@ -88,8 +88,8 @@ futures = "0.3.5"
## API overview ## API overview
### The ping-pong bot ### The dices bot
This bot has a single message handler, which answers "pong" to each incoming message: This bot throws a dice on each incoming message:
([Full](https://github.com/teloxide/teloxide/blob/master/examples/ping_pong_bot/src/main.rs)) ([Full](https://github.com/teloxide/teloxide/blob/master/examples/ping_pong_bot/src/main.rs))
```rust ```rust
@ -98,14 +98,14 @@ use teloxide::prelude::*;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
teloxide::enable_logging!(); teloxide::enable_logging!();
log::info!("Starting ping_pong_bot..."); log::info!("Starting dices_bot...");
let bot = Bot::from_env(); let bot = Bot::from_env();
Dispatcher::new(bot) Dispatcher::new(bot)
.messages_handler(|rx: DispatcherHandlerRx<Message>| { .messages_handler(|rx: DispatcherHandlerRx<Message>| {
rx.for_each(|message| async move { rx.for_each(|message| async move {
message.answer_str("pong").await.log_on_error().await; message.send_dice().send().await.log_on_error().await;
}) })
}) })
.dispatch() .dispatch()

View file

@ -2,7 +2,7 @@
Just enter the directory (for example, `cd dialogue_bot`) and execute `cargo run` to run an example. Don't forget to initialise the `TELOXIDE_TOKEN` environmental variable. Just enter the directory (for example, `cd dialogue_bot`) and execute `cargo run` to run an example. Don't forget to initialise the `TELOXIDE_TOKEN` environmental variable.
| Bot | Description | | Bot | Description |
|---|-----------| |---|-----------|
| [ping_pong_bot](ping_pong_bot) | Answers "pong" to each incoming message. | | [dices_bot](dices_bot) | This bot throws a dice on each incoming message. |
| [ngrok_ping_pong_bot](ngrok_ping_pong_bot) | The ngrok version of ping-pong-bot that uses webhooks. | | [ngrok_ping_pong_bot](ngrok_ping_pong_bot) | The ngrok version of ping-pong-bot that uses webhooks. |
| [heroku_ping_pong_bot](heroku_ping_pong_bot) | The Heroku version of ping-pong-bot that uses webhooks. | | [heroku_ping_pong_bot](heroku_ping_pong_bot) | The Heroku version of ping-pong-bot that uses webhooks. |
| [simple_commands_bot](simple_commands_bot) | Shows how to deal with bot's commands. | | [simple_commands_bot](simple_commands_bot) | Shows how to deal with bot's commands. |

View file

@ -1,5 +1,5 @@
[package] [package]
name = "ping_pong_bot" name = "dices_bot"
version = "0.1.0" version = "0.1.0"
authors = ["Temirkhan Myrzamadi <hirrolot@gmail.com>"] authors = ["Temirkhan Myrzamadi <hirrolot@gmail.com>"]
edition = "2018" edition = "2018"

View file

@ -1,4 +1,4 @@
// This bot just answers "pong" to each incoming UpdateKind::Message. // This bot throws a dice on each incoming message.
use teloxide::prelude::*; use teloxide::prelude::*;
@ -9,14 +9,14 @@ async fn main() {
async fn run() { async fn run() {
teloxide::enable_logging!(); teloxide::enable_logging!();
log::info!("Starting ping_pong_bot..."); log::info!("Starting dices_bot...");
let bot = Bot::from_env(); let bot = Bot::from_env();
Dispatcher::new(bot) Dispatcher::new(bot)
.messages_handler(|rx: DispatcherHandlerRx<Message>| { .messages_handler(|rx: DispatcherHandlerRx<Message>| {
rx.for_each(|message| async move { rx.for_each(|message| async move {
message.answer_str("pong").await.log_on_error().await; message.send_dice().send().await.log_on_error().await;
}) })
}) })
.dispatch() .dispatch()

View file

@ -30,25 +30,24 @@
//! //!
//! Since they implement [`DispatcherHandler`] too. //! Since they implement [`DispatcherHandler`] too.
//! //!
//! # The ping-pong bot //! # The dices bot
//! This bot has a single handler of messages, which answers "pong" to each //! This bot throws a dice on each incoming message:
//! incoming message:
//! //!
//! ([Full](https://github.com/teloxide/teloxide/blob/master/examples/ping_pong_bot/src/main.rs)) //! ([Full](https://github.com/teloxide/teloxide/blob/master/examples/dices_bot/src/main.rs))
//! ```no_run //! ```no_run
//! use teloxide::prelude::*; //! use teloxide::prelude::*;
//! //!
//! # #[tokio::main] //! # #[tokio::main]
//! # async fn main_() { //! # async fn main_() {
//! teloxide::enable_logging!(); //! teloxide::enable_logging!();
//! log::info!("Starting ping_pong_bot..."); //! log::info!("Starting dices_bot...");
//! //!
//! let bot = Bot::from_env(); //! let bot = Bot::from_env();
//! //!
//! Dispatcher::new(bot) //! Dispatcher::new(bot)
//! .messages_handler(|rx: DispatcherHandlerRx<Message>| { //! .messages_handler(|rx: DispatcherHandlerRx<Message>| {
//! rx.for_each(|message| async move { //! rx.for_each(|message| async move {
//! message.answer("pong").send().await.log_on_error().await; //! message.send_dice().send().await.log_on_error().await;
//! }) //! })
//! }) //! })
//! .dispatch() //! .dispatch()