diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 105 |
1 files changed, 5 insertions, 100 deletions
diff --git a/src/main.rs b/src/main.rs index 0a6b256..69f5ecc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,16 +6,16 @@ mod client; //mod auth; mod update; //mod message; -/* + struct UpdateHandler; impl update::Handler for UpdateHandler { - fn handle(&self, _client: client::Client, req: serde_json::Value) -> 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) + info!("update: {:#?}", req); }) } -}*/ +} #[tokio::main] async fn main() { @@ -25,103 +25,8 @@ async fn main() { .ok() .and_then(|var| var.parse().ok()); - let mut updater = update::UpdateRouter::new( - tokio::runtime::Handle::try_current().expect("Must be in runtime") - ); - - let update_auth_state = |tg: client::Client, val: serde_json::Value| async move { - let cache = env::current_dir().unwrap().join("cache"); - info!("auth update: val: {:#}", val); - match val.pointer("/authorization_state/@type").unwrap() - .as_str().unwrap() { - "authorizationStateWaitTdlibParameters" => { - let resp = tg.send(&serde_json::json!({ - "@type": "setTdlibParameters", - "parameters": { - "use_test_dc": true, - "api_id": env::var("API_ID").unwrap(), - "api_hash": env::var("API_HASH").unwrap(), - "device_model": "mbia", - "system_version": "Catalina", - "application_version": "0.1", - "system_language_code": "en", - "database_directory": cache.join("database").to_str().unwrap(), - "use_message_database": false, - "files_directory": cache.join("files").to_str().unwrap(), - "use_secret_chats": false, - }, - })).await; - info!("settdlib: {}", resp); - }, - "authorizationStateWaitEncryptionKey" => { - let resp = tg.send(&serde_json::json!({ - "@type": "setDatabaseEncryptionKey", - "encryption_key": "sup3rs3cr3t", - })).await; - info!("setenckey: {}", resp); - }, - "authorizationStateWaitPhoneNumber" => { - let resp = tg.send(&serde_json::json!({ - "@type": "setAuthenticationPhoneNumber", - "phone_number": "+79859053875", - "settings": { - "allow_flash_call": false, - "is_current_phone_number": false, - "allow_sms_retriever_api": false, - } - })).await; - info!("setphone: {}", resp); - }, - "authorizationStateWaitRegistration" => { - let resp = tg.send(&serde_json::json!({ - "@type": "registerUser", - "first_name": "John", - "last_name": "Doe", - })).await; - info!("reg: {}", resp); - }, - "authorizationStateWaitCode" => { - let code = { - let mut s = String::new(); - std::io::stdin().read_line(&mut s).expect("Could not read line"); - s - }; - let resp = tg.send(&serde_json::json!({ - "@type": "checkAuthenticationCode", - "code": code, - })).await; - info!("checkcode: {}", resp); - }, - auth_state => { - error!("Unknown auth state update: {} / {:#}", auth_state, val); - } - }; - }; - - updater.add_handler("updateAuthorizationState", update_auth_state); + let tg = client::Client::new(tg_log, UpdateHandler{}); - let tg = client::Client::new(tg_log, updater); - std::thread::sleep(std::time::Duration::new(2, 0)); - let get_chats = tg.send(&serde_json::json!({ - "@type": "getChats", - "chat_list": { - "@type": "chatListMain" - }, - "offset_order": "9223372036854775807", - "offset_chat_id": "9223372036854775807", - "limit": 5 - })).await; - error!("send msg: {}", get_chats); - let chat = get_chats.pointer("/chat_ids/0").unwrap_or(&serde_json::json!(0)).as_u64().unwrap(); - let get_chat = tg.send(&serde_json::json!({ - "@type": "getChat", - "chat_id": chat, - })).await; - error!("get_chat: {:#}", get_chat); - let me = tg.send(&serde_json::json!({ - "@type": "getMe", - })).await; - error!("me: {:#}", me); std::thread::sleep(std::time::Duration::new(200, 0)); |