Simplify examples/dialogue.rs

This commit is contained in:
Hirrolot 2022-02-04 09:58:56 +06:00
parent 7837db4201
commit 263478a20a
2 changed files with 18 additions and 28 deletions

View file

@ -254,7 +254,7 @@ async fn handle_receive_full_name(
dialogue.update(State::ReceiveAge { full_name: text.into() }).await?; dialogue.update(State::ReceiveAge { full_name: text.into() }).await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Send me a text message.").await?; bot.send_message(msg.chat_id(), "Send me plain text.").await?;
} }
} }
@ -267,18 +267,13 @@ async fn handle_receive_age(
dialogue: MyDialogue, dialogue: MyDialogue,
(full_name,): (String,), (full_name,): (String,),
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match msg.text() { match msg.text().map(|text| text.parse::<u8>()) {
Some(number) => match number.parse::<u8>() { Some(Ok(age)) => {
Ok(age) => { bot.send_message(msg.chat_id(), "What's your location?").await?;
bot.send_message(msg.chat_id(), "What's your location?").await?; dialogue.update(State::ReceiveLocation { full_name, age }).await?;
dialogue.update(State::ReceiveLocation { full_name, age }).await?; }
} _ => {
_ => { bot.send_message(msg.chat_id(), "Send me a number.").await?;
bot.send_message(msg.chat_id(), "Send me a number.").await?;
}
},
None => {
bot.send_message(msg.chat_id(), "Send me a text message.").await?;
} }
} }
@ -298,7 +293,7 @@ async fn handle_receive_location(
dialogue.exit().await?; dialogue.exit().await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Send me a text message.").await?; bot.send_message(msg.chat_id(), "Send me plain text.").await?;
} }
} }

View file

@ -80,7 +80,7 @@ async fn handle_receive_full_name(
dialogue.update(State::ReceiveAge { full_name: text.into() }).await?; dialogue.update(State::ReceiveAge { full_name: text.into() }).await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Send me a text message.").await?; bot.send_message(msg.chat_id(), "Send me plain text.").await?;
} }
} }
@ -93,18 +93,13 @@ async fn handle_receive_age(
dialogue: MyDialogue, dialogue: MyDialogue,
(full_name,): (String,), (full_name,): (String,),
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match msg.text() { match msg.text().map(|text| text.parse::<u8>()) {
Some(number) => match number.parse::<u8>() { Some(Ok(age)) => {
Ok(age) => { bot.send_message(msg.chat_id(), "What's your location?").await?;
bot.send_message(msg.chat_id(), "What's your location?").await?; dialogue.update(State::ReceiveLocation { full_name, age }).await?;
dialogue.update(State::ReceiveLocation { full_name, age }).await?; }
} _ => {
_ => { bot.send_message(msg.chat_id(), "Send me a number.").await?;
bot.send_message(msg.chat_id(), "Send me a number.").await?;
}
},
None => {
bot.send_message(msg.chat_id(), "Send me a text message.").await?;
} }
} }
@ -124,7 +119,7 @@ async fn handle_receive_location(
dialogue.exit().await?; dialogue.exit().await?;
} }
None => { None => {
bot.send_message(msg.chat_id(), "Send me a text message.").await?; bot.send_message(msg.chat_id(), "Send me plain text.").await?;
} }
} }