2020-07-25 18:37:58 +02:00
|
|
|
// This is a bot that asks you three questions, e.g. a simple test.
|
2020-02-13 18:38:05 +01:00
|
|
|
//
|
|
|
|
// # Example
|
|
|
|
// ```
|
2020-07-26 09:18:29 +02:00
|
|
|
// - Hey
|
|
|
|
// - Let's start! What's your full name?
|
|
|
|
// - Gandalf the Grey
|
|
|
|
// - How old are you?
|
|
|
|
// - 223
|
|
|
|
// - What's your location?
|
|
|
|
// - Middle-earth
|
|
|
|
// - Full name: Gandalf the Grey
|
|
|
|
// Age: 223
|
|
|
|
// Location: Middle-earth
|
2020-02-13 18:38:05 +01:00
|
|
|
// ```
|
|
|
|
|
2020-02-12 10:55:36 +01:00
|
|
|
#![allow(clippy::trivial_regex)]
|
2020-05-24 13:08:40 +02:00
|
|
|
#![allow(dead_code)]
|
2020-02-12 10:55:36 +01:00
|
|
|
|
2020-07-25 23:10:48 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate frunk;
|
2020-07-01 14:52:53 +02:00
|
|
|
|
2020-07-26 19:16:49 +02:00
|
|
|
mod dialogue;
|
2020-05-24 10:19:46 +02:00
|
|
|
|
2020-07-26 19:16:49 +02:00
|
|
|
use crate::dialogue::Dialogue;
|
2020-05-24 14:55:13 +02:00
|
|
|
use teloxide::prelude::*;
|
2020-01-29 23:54:40 +01:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2020-02-13 09:55:46 +01:00
|
|
|
run().await;
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn run() {
|
2020-02-13 18:23:22 +01:00
|
|
|
teloxide::enable_logging!();
|
2020-07-25 15:45:57 +02:00
|
|
|
log::info!("Starting dialogue_bot...");
|
2020-01-29 23:54:40 +01:00
|
|
|
|
2021-03-05 22:24:10 +01:00
|
|
|
let bot = Bot::from_env().auto_send();
|
2020-02-13 18:23:22 +01:00
|
|
|
|
2020-07-31 14:47:20 +02:00
|
|
|
teloxide::dialogues_repl(bot, |message, dialogue| async move {
|
|
|
|
handle_message(message, dialogue).await.expect("Something wrong with the bot!")
|
|
|
|
})
|
|
|
|
.await;
|
2020-01-29 23:54:40 +01:00
|
|
|
}
|
2020-07-26 19:16:49 +02:00
|
|
|
|
2021-03-05 22:24:10 +01:00
|
|
|
async fn handle_message(
|
|
|
|
cx: UpdateWithCx<AutoSend<Bot>, Message>,
|
|
|
|
dialogue: Dialogue,
|
|
|
|
) -> TransitionOut<Dialogue> {
|
2021-03-17 20:56:41 +01:00
|
|
|
match cx.update.text().map(ToOwned::to_owned) {
|
2020-07-26 19:16:49 +02:00
|
|
|
None => {
|
2021-03-05 22:24:10 +01:00
|
|
|
cx.answer("Send me a text message.").await?;
|
2020-07-26 19:16:49 +02:00
|
|
|
next(dialogue)
|
|
|
|
}
|
|
|
|
Some(ans) => dialogue.react(cx, ans).await,
|
|
|
|
}
|
|
|
|
}
|