integrates changes to echobot example
This commit is contained in:
commit
47d9a9b7ab
|
@ -5,16 +5,13 @@ use libcwtch::structs::*;
|
|||
use libcwtch::CwtchLib;
|
||||
|
||||
fn main() {
|
||||
let bot_home: String = "example_cwtch_dir".to_string();
|
||||
match std::fs::remove_dir_all(&bot_home) {
|
||||
Err(_e) => (),
|
||||
_ => (),
|
||||
}
|
||||
std::fs::create_dir_all(&bot_home).unwrap();
|
||||
let bot_home = "example_cwtch_dir";
|
||||
std::fs::remove_dir_all(&bot_home).expect("Error removing previous bot_home directory");
|
||||
std::fs::create_dir_all(&bot_home).expect("Error creating bot_home directory");
|
||||
|
||||
let cwtch = libcwtch::new_cwtchlib_go();
|
||||
println!("start_cwtch");
|
||||
let ret = cwtch.start_cwtch(bot_home.as_str(), "");
|
||||
let ret = cwtch.start_cwtch(bot_home, "");
|
||||
println!("start_cwtch returned {}", ret);
|
||||
|
||||
let event_loop_handle = thread::spawn(move || {
|
||||
|
@ -22,7 +19,8 @@ fn main() {
|
|||
let event_str = cwtch.get_appbus_event();
|
||||
println!("event: {}", event_str);
|
||||
|
||||
let event: CwtchEvent = serde_json::from_str(&event_str).unwrap();
|
||||
let event: CwtchEvent =
|
||||
serde_json::from_str(&event_str).expect("Error parsing Cwtch event");
|
||||
match event.event_type.as_str() {
|
||||
"CwtchStarted" => {
|
||||
println!("event CwtchStarted!");
|
||||
|
@ -46,19 +44,20 @@ fn main() {
|
|||
print!("profile: {:?}", profile);
|
||||
}
|
||||
"NewMessageFromPeer" => {
|
||||
let to = event.data["ProfileOnion"].to_string();
|
||||
let conversation = event.data["RemotePeer"].to_string();
|
||||
let to = &event.data["ProfileOnion"];
|
||||
let conversation = &event.data["RemotePeer"];
|
||||
let message: Message =
|
||||
serde_json::from_str(event.data["Data"].as_str()).unwrap();
|
||||
serde_json::from_str(&event.data["Data"]).expect("Error parsing message");
|
||||
|
||||
let response = Message { o: 1, d: message.d };
|
||||
let response_json = serde_json::to_string(&response).unwrap();
|
||||
cwtch.send_message(to.as_str(), conversation.as_str(), response_json.as_str());
|
||||
let response_json =
|
||||
serde_json::to_string(&response).expect("Error parsing json response");
|
||||
cwtch.send_message(&to, &conversation, &response_json);
|
||||
}
|
||||
_ => println!("unhandled event!"),
|
||||
_ => eprintln!("unhandled event!"),
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
event_loop_handle.join().unwrap();
|
||||
event_loop_handle.join().expect("Error running event loop");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue