make it an acceptor bot
This commit is contained in:
parent
0aaf126be6
commit
9eba701ec6
12
src/main.rs
12
src/main.rs
|
@ -9,6 +9,7 @@ use std::thread;
|
||||||
use ::imp::event::Event;
|
use ::imp::event::Event;
|
||||||
use ::imp::imp;
|
use ::imp::imp;
|
||||||
use ::imp::imp::EventHandler;
|
use ::imp::imp::EventHandler;
|
||||||
|
use ::imp::imp::NewContactPolicy;
|
||||||
use libcwtch;
|
use libcwtch;
|
||||||
use libcwtch::CwtchLib;
|
use libcwtch::CwtchLib;
|
||||||
use libcwtch::structs::*;
|
use libcwtch::structs::*;
|
||||||
|
@ -71,7 +72,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut update_bot = UpdateBot::new();
|
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 event_loop_handle = thread::spawn(move || {
|
||||||
let mut bot = Imp::spawn(behaviour, PASSWORD.to_string(), BOT_HOME.to_string());
|
let mut bot = Imp::spawn(behaviour, PASSWORD.to_string(), BOT_HOME.to_string());
|
||||||
|
@ -128,7 +129,7 @@ impl UpdateBot {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl imp::EventHandler for 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 {
|
match event {
|
||||||
Event::ContactCreated { data } => {
|
Event::ContactCreated { data } => {
|
||||||
let convo_id = data["ConversationID"].parse::<i32>().unwrap();
|
let convo_id = data["ConversationID"].parse::<i32>().unwrap();
|
||||||
|
@ -138,10 +139,9 @@ impl imp::EventHandler for UpdateBot {
|
||||||
if data["ConnectionState"] == "Authenticated" {
|
if data["ConnectionState"] == "Authenticated" {
|
||||||
match profile_opt.as_ref() {
|
match profile_opt.as_ref() {
|
||||||
Some(profile) => {
|
Some(profile) => {
|
||||||
if profile.conversations.contains_key(&data["RemotePeer"]) {
|
match profile.find_conversation_id_by_handle(data["RemotePeer"].clone()) {
|
||||||
let conversation =
|
Some(conversation_id) => self.greet(cwtch, profile_opt, conversation_id),
|
||||||
&profile.conversations[&data["RemotePeer"]];
|
None => {}
|
||||||
self.greet(cwtch, profile_opt, conversation.identifier);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => (),
|
None => (),
|
||||||
|
|
Loading…
Reference in New Issue