#[macro_use]
extern crate log;
use std::{env, time::Duration};
use mobot::{progress::ProgressBar, *};
async fn fun() -> anyhow::Result<String> {
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
Ok(String::from("Done"))
}
async fn handle_chat_event(e: Event, _: State<()>) -> Result<Action, anyhow::Error> {
let val = ProgressBar::new()
.with_timeout(Duration::from_secs(20))
.start(&e, fun())
.await?;
e.send_message(format!("Result: {}", val)).await?;
Ok(Action::Done)
}
#[tokio::main]
async fn main() {
mobot::init_logger();
info!("Starting pingbot...");
let client = Client::new(env::var("TELEGRAM_TOKEN").unwrap());
Router::new(client)
.add_route(
Route::Message(Matcher::Regex("[Pp][iI][nN][gG]".into())),
handle_chat_event,
)
.add_route(
Route::Message(Matcher::Exact("pong".into())),
handle_chat_event,
)
.add_route(Route::Default, handlers::log_handler)
.start()
.await;
}