blacklisting members from avatar module
This commit is contained in:
parent
a8072bc530
commit
15d9ea5aab
|
@ -16,7 +16,8 @@ On the first run, if it does not exist, PluralSync will create a configuration d
|
||||||
"avatar_module": {
|
"avatar_module": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"avatar_folder": "// Folder to grab profile pictures, they follow they member1member2...memberX.png format",
|
"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": {
|
"disc_module": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub struct AvatarModule {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub avatar_folder: String,
|
pub avatar_folder: String,
|
||||||
pub avatar_output_path: String,
|
pub avatar_output_path: String,
|
||||||
|
pub blacklist: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "discord")]
|
#[cfg(feature = "discord")]
|
||||||
|
|
48
src/main.rs
48
src/main.rs
|
@ -36,7 +36,8 @@ const EXAMPLE_JSON: &str = r#"{
|
||||||
"avatar_module": {
|
"avatar_module": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"avatar_folder": "// Folder to grab profile pictures, they follow they member1member2...memberX.png format",
|
"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": {
|
"disc_module": {
|
||||||
"enabled": false,
|
"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();
|
let names = get(config_path, ForceFrom::None).unwrap();
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
|
||||||
avatar_module(&config, &names);
|
|
||||||
|
|
||||||
#[cfg(feature = "discord")] {
|
#[cfg(feature = "avatar")]
|
||||||
config.disc_module.enabled |= discord;
|
match avatar_module(&config, &names) {
|
||||||
discord_module(&config);
|
Ok(_) => {
|
||||||
}
|
#[cfg(feature = "discord")] {
|
||||||
#[cfg(feature = "fedi")] {
|
config.disc_module.enabled |= discord;
|
||||||
config.fedi_module.enabled |= fedi;
|
discord_module(&config);
|
||||||
fedi_module(&config);
|
}
|
||||||
|
#[cfg(feature = "fedi")] {
|
||||||
|
config.fedi_module.enabled |= fedi;
|
||||||
|
fedi_module(&config);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => println!("{}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")]
|
||||||
fn avatar_module(config: &Config, names: &Vec<String>) {
|
fn avatar_module(config: &Config, names: &Vec<String>) -> Result<(), &'static str>{
|
||||||
if config.avatar_module.enabled {
|
if config.avatar_module.enabled {
|
||||||
let avatarnames = names.join("").to_lowercase() + ".png";
|
let mut whitelisted_names: Vec<String> = names.iter().map(|i| i.to_lowercase()).collect();
|
||||||
|
let blacklist: Vec<String> = 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() {
|
if Path::new(&config.avatar_module.avatar_output_path).exists() {
|
||||||
let _ = remove_file(&config.avatar_module.avatar_output_path);
|
let _ = remove_file(&config.avatar_module.avatar_output_path);
|
||||||
|
@ -463,7 +478,14 @@ fn avatar_module(config: &Config, names: &Vec<String>) {
|
||||||
} else {
|
} 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");
|
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue