cleanup echobot warnings; update to libcwtch-rs 0.8.0

This commit is contained in:
Dan Ballard 2024-02-24 19:32:40 -08:00
parent d2abf3af24
commit d62cffca66
2 changed files with 9 additions and 7 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cwtch-imp" name = "cwtch-imp"
version = "0.2.3" version = "0.3.0"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
description = "small demon, a familiar of a witch. imp is a set of bot creating utilities built on top of libcwtch-rs" description = "small demon, a familiar of a witch. imp is a set of bot creating utilities built on top of libcwtch-rs"
@ -12,5 +12,5 @@ documentation = "https://docs.rs/cwtch-imp/"
# 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 = {path = "./../libcwtch-rs"} # "0.7.0" libcwtch = "0.8.0"
chrono = "0.4.19" chrono = "0.4.19"

View File

@ -16,7 +16,7 @@ const BOT_NAME: &str = "echobot";
struct Echobot {} struct Echobot {}
fn main() { fn main() {
let behaviour: Behaviour = BehaviourBuilder::new().name(BOT_NAME.to_string()).new_contact_policy(NewContactPolicy::Accept).build(); let behaviour: Behaviour = BehaviourBuilder::new().name(BOT_NAME.to_string()).new_contact_policy(NewContactPolicy::Accept).contact_interaction_policy(ContactInteractionPolicy::Accept).build();
let event_loop_handle = thread::spawn(move || { let event_loop_handle = thread::spawn(move || {
let mut echobot = Echobot {}; let mut echobot = Echobot {};
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());
@ -26,17 +26,19 @@ fn main() {
} }
impl imp::EventHandler for Echobot { impl imp::EventHandler for Echobot {
fn on_new_message_from_contact(&self, cwtch: &dyn libcwtch::CwtchLib, profile: &Profile, conversation_id: ConversationID, handle: String, timestamp_received: DateTime<FixedOffset>, message: MessageWrapper) { fn on_new_message_from_contact(&self, cwtch: &dyn libcwtch::CwtchLib, profile: &Profile, conversation_id: ConversationID, _handle: String, _timestamp_received: DateTime<FixedOffset>, message: MessageWrapper) {
let response = MessageWrapper { let response = MessageWrapper {
o: MessageType::TextMessage, o: MessageType::TextMessage,
d: message.d, d: message.d,
}; };
cwtch.send_message(&profile.profile_id, conversation_id, &response); if let Err(e) = cwtch.send_message(&profile.profile_id, conversation_id, &response) {
println!("Error sending message: {}", e.to_string());
}
} }
fn handle(&mut self, cwtch: &dyn CwtchLib, profile_opt: Option<&Profile>, event: &Event) { fn handle(&mut self, _cwtch: &dyn CwtchLib, _profile_opt: Option<&Profile>, event: &Event) {
match event { match event {
Event::NewPeer { profile_id, tag, created, name, default_picture, picture, online, profile_data } => { Event::NewPeer { profile_id, tag: _, created: _, name, default_picture: _, picture: _, online: _, profile_data: _ } => {
println!( println!(
"\n***** {} at {} *****\n", "\n***** {} at {} *****\n",
name, profile_id.as_str() name, profile_id.as_str()