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