From 9eba701ec6cf7405ce6940d8be450134efc4b0a1 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Sun, 1 May 2022 19:49:56 -0700 Subject: [PATCH] make it an acceptor bot --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0b28a6a..329d455 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use std::thread; use ::imp::event::Event; use ::imp::imp; use ::imp::imp::EventHandler; +use ::imp::imp::NewContactPolicy; use libcwtch; use libcwtch::CwtchLib; use libcwtch::structs::*; @@ -71,7 +72,7 @@ fn main() { } let mut update_bot = UpdateBot::new(); - let behaviour: Behaviour = BehaviourBuilder::new().name(BOT_NAME.to_string()).profile_pic_path("build_bot.png".to_string()).build(); + let behaviour: Behaviour = BehaviourBuilder::new().name(BOT_NAME.to_string()).profile_pic_path("build_bot.png".to_string()).new_contact_policy(imp::NewContactPolicy::Accept).build(); let event_loop_handle = thread::spawn(move || { let mut bot = Imp::spawn(behaviour, PASSWORD.to_string(), BOT_HOME.to_string()); @@ -128,7 +129,7 @@ impl UpdateBot { } impl imp::EventHandler for UpdateBot { - fn handle(&mut self, cwtch: &dyn CwtchLib, profile_opt: Option<&Profile>, event: Event) { + fn handle(&mut self, cwtch: &dyn libcwtch::CwtchLib, profile_opt: Option<&Profile>, event: Event) { match event { Event::ContactCreated { data } => { let convo_id = data["ConversationID"].parse::().unwrap(); @@ -138,10 +139,9 @@ impl imp::EventHandler for UpdateBot { if data["ConnectionState"] == "Authenticated" { match profile_opt.as_ref() { Some(profile) => { - if profile.conversations.contains_key(&data["RemotePeer"]) { - let conversation = - &profile.conversations[&data["RemotePeer"]]; - self.greet(cwtch, profile_opt, conversation.identifier); + match profile.find_conversation_id_by_handle(data["RemotePeer"].clone()) { + Some(conversation_id) => self.greet(cwtch, profile_opt, conversation_id), + None => {} } } None => (),