lbr and imp versions

This commit is contained in:
Dan Ballard 2022-07-21 01:05:12 -07:00
parent 24dae6f3dc
commit 14cfe91f9a
3 changed files with 30 additions and 21 deletions

15
Cargo.lock generated
View File

@ -152,13 +152,13 @@ checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "libcwtch"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82cfe2b14be43f9f77596fa12beb3a12a3e2c12eaa82b25be933d537e6e3d4f9"
dependencies = [
"chrono",
"hex-literal",
"libc",
"serde",
"serde_json",
"serde_repr",
"serde_with",
"sha2",
]
@ -243,6 +243,17 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_repr"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2ad84e47328a31223de7fed7a4f5087f2d6ddfe586cf3ca25b7a165bc0a5aed"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_with"
version = "1.11.0"

View File

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

View File

@ -13,6 +13,7 @@ use ::imp::imp::Imp;
use chrono::{DateTime, FixedOffset};
use libcwtch;
use libcwtch::CwtchLib;
use libcwtch::event::{ContactIdentity, ConversationID};
use libcwtch::structs::*;
use serde_json;
@ -84,9 +85,9 @@ fn main() {
impl UpdateBot {
pub fn greet(&self, cwtch: &dyn CwtchLib, profile: &Profile, convo_id: i32) {
pub fn greet(&self, cwtch: &dyn CwtchLib, profile: &Profile, convo_id: ConversationID) {
let do_offer = match cwtch.get_conversation_attribute(
&profile.handle,
&profile.profile_id,
convo_id,
&format!("local.{}", LAST_OFFERED_KEY),
) {
@ -99,7 +100,7 @@ impl UpdateBot {
if do_offer {
self.offer(cwtch, profile, convo_id);
cwtch.set_conversation_attribute(
&profile.handle,
&profile.profile_id,
convo_id,
LAST_OFFERED_KEY,
&self.version,
@ -107,17 +108,17 @@ impl UpdateBot {
}
}
pub fn offer(&self, cwtch: &dyn CwtchLib, profile: &Profile, convo_id: i32) {
pub fn offer(&self, cwtch: &dyn CwtchLib, profile: &Profile, convo_id: ConversationID) {
let resp_message = format!(
"Currently offering Cwtch {}\nPlease respond with the OS you would like a package for:\n- Windows\n- Android\n- MacOS\n- Linux",
self.version
);
let response = Message {
o: 1,
o: MessageType::TextMessage,
d: resp_message,
};
match serde_json::to_string(&response) {
Ok(response_json) => cwtch.send_message(&profile.handle, convo_id, &response_json),
Ok(response_json) => cwtch.send_message(&profile.profile_id, convo_id, &response_json),
Err(e) => { println!("Error parsing json response: {}", e.to_string()); "".to_string() }
};
}
@ -125,37 +126,34 @@ impl UpdateBot {
}
impl imp::EventHandler for UpdateBot {
fn on_contact_online(&self, cwtch: &dyn libcwtch::CwtchLib, profile: &Profile, convo_id: i32) {
fn on_contact_online(&self, cwtch: &dyn libcwtch::CwtchLib, profile: &Profile, convo_id: ConversationID) {
self.greet(cwtch, profile, convo_id);
}
fn on_new_message_from_contact(&self, cwtch: &dyn libcwtch::CwtchLib, profile: &Profile, conversation_id: i32, _handle: String, _timestamp_received: DateTime<FixedOffset>, message: String) {
let from = profile.handle.as_str();
let message_wrapper: Message =
serde_json::from_str(&message).expect("Error parsing message");
let mut message = message_wrapper.d.clone();
message.make_ascii_lowercase();
fn on_new_message_from_contact(&self, cwtch: &dyn libcwtch::CwtchLib, profile: &Profile, conversation_id: ConversationID, _handle: String, _timestamp_received: DateTime<FixedOffset>, message: Message) {
let mut body = message.d.clone();
body.make_ascii_lowercase();
match message.as_str() {
match body.as_str() {
"windows" => {
let mut windows_path = self.latest_version.clone();
windows_path.push("cwtch-installer.exe");
cwtch.share_file(&from, conversation_id, windows_path.to_str().unwrap());
cwtch.share_file(&profile.profile_id, conversation_id, windows_path.to_str().unwrap());
}
"linux" => {
let mut linux_path = self.latest_version.clone();
linux_path.push(format!("cwtch-{}.tar.gz", self.version));
cwtch.share_file(&from, conversation_id, linux_path.to_str().unwrap());
cwtch.share_file(&profile.profile_id, conversation_id, linux_path.to_str().unwrap());
}
"macos" => {
let mut mac_path = self.latest_version.clone();
mac_path.push("Cwtch.dmg");
cwtch.share_file(&from, conversation_id, mac_path.to_str().unwrap());
cwtch.share_file(&profile.profile_id, conversation_id, mac_path.to_str().unwrap());
}
"android" => {
let mut android_path = self.latest_version.clone();
android_path.push("app-release.apk");
cwtch.share_file(&from, conversation_id, android_path.to_str().unwrap());
cwtch.share_file(&profile.profile_id, conversation_id, android_path.to_str().unwrap());
}
_ => {
self.offer(cwtch, profile, conversation_id);