diff --git a/README.org b/README.org index eb08208..60421ab 100644 --- a/README.org +++ b/README.org @@ -16,7 +16,8 @@ On the first run, if it does not exist, PluralSync will create a configuration d "avatar_module": { "enabled": false, "avatar_folder": "// Folder to grab profile pictures, they follow they member1member2...memberX.png format", - "avatar_output_path": "// Path for the copied selected avatar" + "avatar_output_path": "// Path for the copied selected avatar", + "blacklist": "// Array of members to not include in the avatar module" }, "disc_module": { "enabled": false, diff --git a/src/configdata.rs b/src/configdata.rs index c344f47..f73449d 100644 --- a/src/configdata.rs +++ b/src/configdata.rs @@ -18,6 +18,7 @@ pub struct AvatarModule { pub enabled: bool, pub avatar_folder: String, pub avatar_output_path: String, + pub blacklist: Vec, } #[cfg(feature = "discord")] diff --git a/src/main.rs b/src/main.rs index e22a44b..6eea9f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,8 @@ const EXAMPLE_JSON: &str = r#"{ "avatar_module": { "enabled": false, "avatar_folder": "// Folder to grab profile pictures, they follow they member1member2...memberX.png format", - "avatar_output_path": "// Path for the copied selected avatar" + "avatar_output_path": "// Path for the copied selected avatar", + "blacklist": "// Array of members to not include in the avatar module" }, "disc_module": { "enabled": false, @@ -433,25 +434,39 @@ fn update_avatars(config_path: String, discord: bool, fedi: bool) -> Result<(), let names = get(config_path, ForceFrom::None).unwrap(); - #[cfg(feature = "avatar")] - avatar_module(&config, &names); - #[cfg(feature = "discord")] { - config.disc_module.enabled |= discord; - discord_module(&config); - } - #[cfg(feature = "fedi")] { - config.fedi_module.enabled |= fedi; - fedi_module(&config); + #[cfg(feature = "avatar")] + match avatar_module(&config, &names) { + Ok(_) => { + #[cfg(feature = "discord")] { + config.disc_module.enabled |= discord; + discord_module(&config); + } + #[cfg(feature = "fedi")] { + config.fedi_module.enabled |= fedi; + fedi_module(&config); + } + }, + Err(e) => println!("{}", e), } + Ok(()) } #[cfg(feature = "avatar")] -fn avatar_module(config: &Config, names: &Vec) { +fn avatar_module(config: &Config, names: &Vec) -> Result<(), &'static str>{ if config.avatar_module.enabled { - let avatarnames = names.join("").to_lowercase() + ".png"; + let mut whitelisted_names: Vec = names.iter().map(|i| i.to_lowercase()).collect(); + let blacklist: Vec = config.avatar_module.blacklist.iter().map(|i| i.to_lowercase()).collect(); + for name in names { + if blacklist.contains(&name.to_lowercase()) { + let index = whitelisted_names.iter().position(|x| *x == name.to_lowercase()).unwrap(); + whitelisted_names.remove(index); + } + } + + let avatarnames = whitelisted_names.join("").to_lowercase() + ".png"; if Path::new(&config.avatar_module.avatar_output_path).exists() { let _ = remove_file(&config.avatar_module.avatar_output_path); @@ -463,7 +478,14 @@ 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"); + if Path::new(&config.avatar_module.avatar_output_path).exists() { + println!("Avatar module finished"); + return Ok(()) + } else { + return Err("Avatar module failed") + } + } else { + Err("Avatar mode disabled") } }