diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-07-29 20:02:47 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-07-29 20:02:47 +0200 |
commit | 89168ff11d4adb4ca51fe14e7d54fb2d69d392a8 (patch) | |
tree | 852241fc743b8f600bdf1c1787c1b7c283d2de27 /src/main.rs | |
parent | a3be99079e9a644eaeaef857c52d7eebcc77e77e (diff) |
refactor: manage callbacks with tokio-stream
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 0ac5a4d..220b7ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,8 @@ mod config; use crate::config::Config; +use tokio_stream::wrappers::UnboundedReceiverStream; + #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { teloxide::enable_logging!(); @@ -23,7 +25,23 @@ async fn main() -> Result<(), Box<dyn Error>> { panic!("You can't connect: `{}`, credentials are {:?}", e, config); } }; - teloxide::commands_repl(bot, "unict-reservation", commands::handler).await; + + Dispatcher::new(bot) + .messages_handler(|rx: DispatcherHandlerRx<AutoSend<Bot>, Message>| { + UnboundedReceiverStream::new(rx).for_each_concurrent(None, |cx| async move { + commands::handler(cx).await.log_on_error().await; + }) + }) + .callback_queries_handler(|rx: DispatcherHandlerRx<AutoSend<Bot>, CallbackQuery>| { + UnboundedReceiverStream::new(rx).for_each_concurrent(None, |cx| async move { + let data = &cx.update.data; + if let Some(d) = data { + println!("{}", d); + } + }) + }) + .dispatch() + .await; log::info!("Closing bot... Goodbye!"); Ok(()) |