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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
use std::env;
use tokio;
use log::{ info };
mod client;
//mod auth;
mod update;
//mod message;
struct UpdateHandler;
fn make_lib_params() -> pert_types::types::TdlibParameters {
let cache = env::current_dir().unwrap().join("cache");
let make_path = |p: &str| cache.join(p).to_str().map(|p| p.to_owned()).unwrap();
pert_types::types::TdlibParameters {
use_test_dc: true,
database_directory: make_path("database"),
files_directory: make_path("files"),
use_file_database: true,
use_chat_info_database: true,
use_message_database: true,
use_secret_chats: false,
api_id: env::var("API_ID").unwrap().parse().unwrap(),
api_hash: env::var("API_HASH").unwrap(),
system_language_code: "en".to_owned(),
device_model: "mbia v1".to_owned(),
system_version: "15".to_owned(),
application_version: "0.1".to_owned(),
enable_storage_optimizer: false,
ignore_file_names: true,
}
}
impl update::Handler for UpdateHandler {
fn handle(&self, client: client::Client, req: pert_types::types::Update) -> futures::future::BoxFuture<'static, ()> {
Box::pin(async move {
match req {
pert_types::types::Update::UpdateAuthorizationState(state) => {
match state.authorization_state {
pert_types::types::AuthorizationState::AuthorizationStateWaitTdlibParameters(_) => {
client.send(pert_types::methods::SetTdlibParameters {
parameters: make_lib_params(),
}).unwrap().await.unwrap();
}
_ => info!("auth state unknown: {:#?}", state)
}
}
_ => info!("unknown update: {:#?}", req)
}
})
}
}
#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
env_logger::init();
let tg_log: Option<i32> = env::var("TG_LOG")
.ok()
.and_then(|var| var.parse().ok());
let tg = client::Client::new(tg_log, UpdateHandler{});
std::thread::sleep(std::time::Duration::new(200, 0));
}
|