mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-13 19:27:52 +01:00
Remove the excess check in guess-a-number-bot
This commit is contained in:
parent
ec7db5ec7b
commit
95d3e7ceae
2 changed files with 8 additions and 26 deletions
17
README.md
17
README.md
|
@ -207,24 +207,15 @@ async fn receive_attempt(cx: Cx<u8>) -> Res {
|
|||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
}
|
||||
Some(text) => match text.parse::<u8>() {
|
||||
Ok(attempt) => match attempt {
|
||||
x if !(1..=10).contains(&x) => {
|
||||
cx.answer(
|
||||
"Oh, please, send me a number in the range [1; 10]!",
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
}
|
||||
x if x == cx.dialogue => {
|
||||
Ok(attempt) => {
|
||||
if attempt == cx.dialogue {
|
||||
cx.answer("Congratulations! You won!").send().await?;
|
||||
exit()
|
||||
}
|
||||
_ => {
|
||||
} else {
|
||||
cx.answer("No.").send().await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(_) => {
|
||||
cx.answer("Oh, please, send me a number in the range [1; 10]!")
|
||||
.send()
|
||||
|
|
|
@ -55,24 +55,15 @@ async fn receive_attempt(cx: Cx<u8>) -> Res {
|
|||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
}
|
||||
Some(text) => match text.parse::<u8>() {
|
||||
Ok(attempt) => match attempt {
|
||||
x if !(1..=10).contains(&x) => {
|
||||
cx.answer(
|
||||
"Oh, please, send me a number in the range [1; 10]!",
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
}
|
||||
x if x == cx.dialogue => {
|
||||
Ok(attempt) => {
|
||||
if attempt == cx.dialogue {
|
||||
cx.answer("Congratulations! You won!").send().await?;
|
||||
exit()
|
||||
}
|
||||
_ => {
|
||||
} else {
|
||||
cx.answer("No.").send().await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(_) => {
|
||||
cx.answer("Oh, please, send me a number in the range [1; 10]!")
|
||||
.send()
|
||||
|
|
Loading…
Add table
Reference in a new issue