blob: 220b7ce1beeec06ab60f43b08e84349578915cbf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
use std::error::Error;
use teloxide::prelude::*;
use thirtyfour::WebDriver;
mod browser;
mod commands;
mod config;
use crate::config::Config;
use tokio_stream::wrappers::UnboundedReceiverStream;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
teloxide::enable_logging!();
log::info!("Starting bot...");
let bot = Bot::from_env().auto_send();
let config = Config::from_env().unwrap();
let driver: WebDriver = browser::init().await;
match browser::login(&driver, &config).await {
Ok(_) => {}
Err(e) => {
panic!("You can't connect: `{}`, credentials are {:?}", e, config);
}
};
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(())
}
|