make it an acceptor bot

This commit is contained in:
Dan Ballard 2022-05-01 19:49:56 -07:00
parent 0aaf126be6
commit 9eba701ec6
1 changed files with 6 additions and 6 deletions

View File

@ -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::<i32>().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 => (),