new imp with broken out behaviour

This commit is contained in:
Dan Ballard 2022-05-02 14:43:19 -07:00
parent 9eba701ec6
commit 7d7dca67c9
3 changed files with 12 additions and 13 deletions

4
Cargo.lock generated
View File

@ -151,9 +151,9 @@ checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]] [[package]]
name = "libcwtch" name = "libcwtch"
version = "0.3.0" version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25c487f128e73d0c8a18f421f67efa7cf0b3ee913dbd2b1ef49b0854e25abf85" checksum = "82cfe2b14be43f9f77596fa12beb3a12a3e2c12eaa82b25be933d537e6e3d4f9"
dependencies = [ dependencies = [
"hex-literal", "hex-literal",
"libc", "libc",

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
libcwtch = "0.3.0" libcwtch = "0.3.2"
imp = {path = "../imp"} imp = {path = "../imp"}
serde_json = "1.0" serde_json = "1.0"

View File

@ -1,22 +1,21 @@
extern crate core; extern crate core;
use std::borrow::{Borrow, BorrowMut}; use std::borrow::{BorrowMut};
use std::collections::HashMap;
use std::fs::read_dir; use std::fs::read_dir;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::thread; use std::thread;
use ::imp::event::Event; use ::imp::event::Event;
use ::imp::imp; use ::imp::imp;
use ::imp::imp::EventHandler; use ::imp::behaviour;
use ::imp::imp::NewContactPolicy; use ::imp::behaviour::BehaviourBuilder;
use ::imp::behaviour::Behaviour;
use ::imp::imp::Imp;
use libcwtch; use libcwtch;
use libcwtch::CwtchLib; use libcwtch::CwtchLib;
use libcwtch::structs::*; use libcwtch::structs::*;
use serde_json; use serde_json;
use crate::imp::{Behaviour, BehaviourBuilder, Imp};
const DIST_DIR: &str = "cwtch_dist"; const DIST_DIR: &str = "cwtch_dist";
const BOT_HOME: &str = "~/.cwtch/bots/update_bot"; const BOT_HOME: &str = "~/.cwtch/bots/update_bot";
const PASSWORD: &str = "be gay do crime"; const PASSWORD: &str = "be gay do crime";
@ -72,7 +71,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()).new_contact_policy(imp::NewContactPolicy::Accept).build(); let behaviour: Behaviour = BehaviourBuilder::new().name(BOT_NAME.to_string()).profile_pic_path("build_bot.png".to_string()).new_contact_policy(behaviour::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());
@ -96,7 +95,7 @@ impl UpdateBot {
Some(last_offered) => last_offered != self.version, Some(last_offered) => last_offered != self.version,
None => true, None => true,
}, },
Err(e) => false Err(_) => false
}; };
if do_offer { if do_offer {
self.offer(cwtch, profile_opt, convo_id); self.offer(cwtch, profile_opt, convo_id);
@ -148,7 +147,7 @@ impl imp::EventHandler for UpdateBot {
}; };
} }
} }
Event::NewMessageFromPeer { conversation_id, handle, timestamp_received, message } => { Event::NewMessageFromPeer { conversation_id, handle: _, timestamp_received: _, message } => {
match profile_opt { match profile_opt {
Some(profile) => { Some(profile) => {
let from = profile.handle.as_str(); let from = profile.handle.as_str();
@ -186,7 +185,7 @@ impl imp::EventHandler for UpdateBot {
_ => {} _ => {}
} }
} }
Event::ErrUnhandled { name, data } => eprintln!("unhandled event: {}!", name), Event::ErrUnhandled { name, data: _ } => eprintln!("unhandled event: {}!", name),
_ => () _ => ()
}; };
} }