mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Add the 'let secret = cx.dialogue' binding
This commit is contained in:
parent
e44a2204bf
commit
23df2d0577
2 changed files with 12 additions and 8 deletions
10
README.md
10
README.md
|
@ -201,26 +201,28 @@ async fn start(cx: Cx<()>) -> Res {
|
|||
}
|
||||
|
||||
async fn receive_attempt(cx: Cx<u8>) -> Res {
|
||||
let secret = cx.dialogue;
|
||||
|
||||
match cx.update.text() {
|
||||
None => {
|
||||
cx.answer("Oh, please, send me a text message!").send().await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
next(Dialogue::ReceiveAttempt(secret))
|
||||
}
|
||||
Some(text) => match text.parse::<u8>() {
|
||||
Ok(attempt) => {
|
||||
if attempt == cx.dialogue {
|
||||
if attempt == secret {
|
||||
cx.answer("Congratulations! You won!").send().await?;
|
||||
exit()
|
||||
} else {
|
||||
cx.answer("No.").send().await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
next(Dialogue::ReceiveAttempt(secret))
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
cx.answer("Oh, please, send me a number in the range [1; 10]!")
|
||||
.send()
|
||||
.await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
next(Dialogue::ReceiveAttempt(secret))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -49,26 +49,28 @@ async fn start(cx: Cx<()>) -> Res {
|
|||
}
|
||||
|
||||
async fn receive_attempt(cx: Cx<u8>) -> Res {
|
||||
let secret = cx.dialogue;
|
||||
|
||||
match cx.update.text() {
|
||||
None => {
|
||||
cx.answer("Oh, please, send me a text message!").send().await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
next(Dialogue::ReceiveAttempt(secret))
|
||||
}
|
||||
Some(text) => match text.parse::<u8>() {
|
||||
Ok(attempt) => {
|
||||
if attempt == cx.dialogue {
|
||||
if attempt == secret {
|
||||
cx.answer("Congratulations! You won!").send().await?;
|
||||
exit()
|
||||
} else {
|
||||
cx.answer("No.").send().await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
next(Dialogue::ReceiveAttempt(secret))
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
cx.answer("Oh, please, send me a number in the range [1; 10]!")
|
||||
.send()
|
||||
.await?;
|
||||
next(Dialogue::ReceiveAttempt(cx.dialogue))
|
||||
next(Dialogue::ReceiveAttempt(secret))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue