From 48e80c5d1841eb712f7a6a94d6360900c83ebec5 Mon Sep 17 00:00:00 2001 From: Junko Date: Thu, 18 Jan 2024 10:03:09 +0100 Subject: [PATCH 1/2] avatar module launched even if missing memeber --- src/main.rs | 82 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index b624a99..b38a542 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,29 +75,53 @@ fn main() { Commands::Set { members, discord, fedi } => { res = set_member(config_path.clone(), members); - #[cfg(feature = "avatar")] - let _ = update_avatars(config_path.clone(), discord, fedi); + #[cfg(feature = "avatar")] { + match res { + Ok(_) => { + let _ = update_avatars(config_path.clone(), discord, fedi); + }, + Err(_) => (), + } + } }, #[cfg(all(feature = "discord", not(feature = "fedi")))] Commands::Set { members, discord } => { res = set_member(config_path.clone(), members); - #[cfg(feature = "avatar")] - let _ = update_avatars(config_path.clone(), discord, false); + #[cfg(feature = "avatar")] { + match res { + Ok(_) => { + let _ = update_avatars(config_path.clone(), discord, false); + }, + Err(_) => (), + } + } }, #[cfg(all(not(feature = "discord"), feature = "fedi"))] Commands::Set { members, fedi} => { res = set_member(config_path.clone(), members); - #[cfg(feature = "avatar")] - let _ = update_avatars(config_path.clone(), false, fedi); + #[cfg(feature = "avatar")] { + match res { + Ok(_) => { + let _ = update_avatars(config_path.clone(), false, fedi); + }, + Err(_) => (), + } + } }, #[cfg(all(not(feature = "discord"), not(feature = "fedi")))] Commands::Set { members } => { res = set_member(config_path.clone(), members); - #[cfg(feature = "avatar")] - let _ = update_avatars(config_path.clone(), false, false); + #[cfg(feature = "avatar")] { + match res { + Ok(_) => { + let _ = update_avatars(config_path.clone(), false, false); + }, + Err(_) => (), + } + } }, // ADD MEMBER @@ -105,29 +129,53 @@ fn main() { Commands::Add { members, discord, fedi } => { res = add_member(config_path.clone(), members); - #[cfg(feature = "avatar")] - let _ = update_avatars(config_path.clone(), discord, fedi); + #[cfg(feature = "avatar")] { + match res { + Ok(_) => { + let _ = update_avatars(config_path.clone(), discord, fedi); + }, + Err(_) => (), + } + } }, #[cfg(all(feature = "discord", not(feature = "fedi")))] Commands::Add { members, discord } => { res = add_member(config_path.clone(), members); - #[cfg(feature = "avatar")] - let _ = update_avatars(config_path.clone(), discord, false); + #[cfg(feature = "avatar")] { + match res { + Ok(_) => { + let _ = update_avatars(config_path.clone(), discord, false); + }, + Err(_) => (), + } + } }, #[cfg(all(not(feature = "discord"), feature = "fedi"))] Commands::Add { members, fedi} => { res = add_member(config_path.clone(), members); - #[cfg(feature = "avatar")] - let _ = update_avatars(config_path.clone(), false, fedi); + #[cfg(feature = "avatar")] { + match res { + Ok(_) => { + let _ = update_avatars(config_path.clone(), false, fedi); + }, + Err(_) => (), + } + } }, #[cfg(all(not(feature = "discord"), not(feature = "fedi")))] Commands::Add { members } => { res = add_member(config_path.clone(), members); - #[cfg(feature = "avatar")] - let _ = update_avatars(config_path.clone(), false, false); + #[cfg(feature = "avatar")] { + match res { + Ok(_) => { + let _ = update_avatars(config_path.clone(), false, false); + }, + Err(_) => (), + } + } }, // Get MEMBER @@ -270,6 +318,7 @@ fn set_member(config_path: String, tf_members: Vec) -> Result<(), &'stat println!("One or more members were not found. Known members:\n--------------------------"); let _ = memberlist(config_path); println!("--------------------------\nIf a member is missing from the system try running \"pluralsync sync\" to refresh the local database"); + return Err("Missing member"); } Ok(()) } @@ -307,6 +356,7 @@ fn add_member(config_path: String, tf_members: Vec) -> Result<(), &'stat println!("One or more members were not found. Known members:\n--------------------------"); let _ = memberlist(config_path); println!("--------------------------\nIf a member is missing from the system try running \"pluralsync sync\" to refresh the local database"); + return Err("Missing member"); } Ok(()) } From af893515c804763a73b1f636443a83c292785050 Mon Sep 17 00:00:00 2001 From: Junko Date: Fri, 19 Jan 2024 12:22:39 +0100 Subject: [PATCH 2/2] jlog --- Cargo.toml | 1 + src/main.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 367b044..518d301 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ tokio = { version = "1", features = ["full"] } avatar = [] discord = ["avatar"] fedi = ["avatar"] +jlog = [] [profile.release] opt-level = 'z' diff --git a/src/main.rs b/src/main.rs index b38a542..e22a44b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -320,6 +320,19 @@ fn set_member(config_path: String, tf_members: Vec) -> Result<(), &'stat println!("--------------------------\nIf a member is missing from the system try running \"pluralsync sync\" to refresh the local database"); return Err("Missing member"); } + + #[cfg(feature = "jlog")] { + let mut names = Vec::new(); + for m in &to_front { + names.push(String::from(&m.name)); + } + let log_fronters = names.join(" || "); + #[cfg(target_os = "windows")] + std::process::Command::new("jlog").args(["info", format!("Switch registered: {}", log_fronters)]).output().expect("Logging error"); + #[cfg(not(target_os = "windows"))] + std::process::Command::new("jlog").arg("info").arg(format!("Switch registered: {}", log_fronters)).output().expect("Logging error"); + } + Ok(()) } @@ -352,12 +365,26 @@ fn add_member(config_path: String, tf_members: Vec) -> Result<(), &'stat sp_set_fronters(&config.sp_key, &to_front, &fronters); let _ = get(config_path, ForceFrom::None); + } else { println!("One or more members were not found. Known members:\n--------------------------"); let _ = memberlist(config_path); println!("--------------------------\nIf a member is missing from the system try running \"pluralsync sync\" to refresh the local database"); return Err("Missing member"); } + + #[cfg(feature = "jlog")] { + let mut names = Vec::new(); + for m in &to_front { + names.push(String::from(&m.name)); + } + let log_fronters = names.join(" || "); + #[cfg(target_os = "windows")] + std::process::Command::new("jlog").args(["info", format!("Switch registered: {}", log_fronters)]).output().expect("Logging error"); + #[cfg(not(target_os = "windows"))] + std::process::Command::new("jlog").arg("info").arg(format!("Switch registered: {}", log_fronters)).output().expect("Logging error"); + } + Ok(()) } @@ -436,6 +463,7 @@ fn avatar_module(config: &Config, names: &Vec) { } else { Command::new("sh").arg("-c").arg(format!("cp {}/{} {}", &config.avatar_module.avatar_folder, avatarnames, &config.avatar_module.avatar_output_path)).output().expect("Avatar module error"); } + println!("Avatar module finished"); } } @@ -465,11 +493,11 @@ fn fedi_module(config: &Config) { .header(USER_AGENT, "Pluralsync") .header(AUTHORIZATION, format!("Bearer {}", &config.fedi_module.token).as_str()); + println!("Fedi module finished"); match http_request(rb) { Ok(_) => (), Err(e) => println!("{}", e.to_string()), } - } }