summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 69f5ecc..49e4397 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
use std::env;
use tokio;
-use log::{ info, error };
+use log::{ info };
mod client;
//mod auth;
@@ -9,10 +9,44 @@ mod update;
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, ()> {
+ fn handle(&self, client: client::Client, req: pert_types::types::Update) -> futures::future::BoxFuture<'static, ()> {
Box::pin(async move {
- info!("update: {:#?}", req);
+ 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)
+ }
})
}
}
@@ -27,7 +61,5 @@ async fn main() {
let tg = client::Client::new(tg_log, UpdateHandler{});
-
-
std::thread::sleep(std::time::Duration::new(200, 0));
}