From a7fa18b5ff66ba6feb7cdbd07345f9ea95a9023a Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Sat, 23 Sep 2023 18:41:36 -0700 Subject: [PATCH] 0.2.2: protect create profile with check if one is set as sometimes we still get AppError 0 loaded --- Cargo.toml | 2 +- src/imp.rs | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4e8f4f4..3ffe240 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cwtch-imp" -version = "0.2.1" +version = "0.2.2" edition = "2021" license = "MIT" description = "small demon, a familiar of a witch. imp is a set of bot creating utilities built on top of libcwtch-rs" diff --git a/src/imp.rs b/src/imp.rs index 908512a..321b6c2 100644 --- a/src/imp.rs +++ b/src/imp.rs @@ -63,15 +63,11 @@ impl Imp { match &event { Event::CwtchStarted => { - println!("event CwtchStarted!"); + println!("Cwtch Started"); initialized = true; - match self.profile { - None => { - println!("Creating bot"); - self.cwtch.load_profiles(&self.password); - } - Some(_) => (), + if self.profile.is_none() { + self.cwtch.load_profiles(&self.password); } } Event::UpdateGlobalSettings { settings } => { @@ -108,7 +104,6 @@ impl Imp { self.settings = Some(local_settings); } Event::NewPeer { profile_id, tag, created, name, default_picture, picture, online, profile_data} => { - if let Err(e) = profile_data { panic!("error parsing profile: {}", e); } @@ -147,8 +142,10 @@ impl Imp { } Event::AppError { error, data } => { if initialized && error == "Loaded 0 profiles" { - self.cwtch - .create_profile(&self.behaviour.profile_name, &self.password, true); + if self.profile.is_none() { + self.cwtch + .create_profile(&self.behaviour.profile_name, &self.password, true); + } } } Event::ContactCreated {profile_id, conversation_id, contact_id, nick, status, unread, picture, default_picture, num_messages, accepted, access_control_list, blocked, loading, last_msg_time, .. } => {