commit
a8072bc530
|
@ -18,6 +18,7 @@ tokio = { version = "1", features = ["full"] }
|
||||||
avatar = []
|
avatar = []
|
||||||
discord = ["avatar"]
|
discord = ["avatar"]
|
||||||
fedi = ["avatar"]
|
fedi = ["avatar"]
|
||||||
|
jlog = []
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 'z'
|
opt-level = 'z'
|
||||||
|
|
96
src/main.rs
96
src/main.rs
|
@ -75,60 +75,108 @@ fn main() {
|
||||||
Commands::Set { members, discord, fedi } => {
|
Commands::Set { members, discord, fedi } => {
|
||||||
res = set_member(config_path.clone(), members);
|
res = set_member(config_path.clone(), members);
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")] {
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
let _ = update_avatars(config_path.clone(), discord, fedi);
|
let _ = update_avatars(config_path.clone(), discord, fedi);
|
||||||
},
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
#[cfg(all(feature = "discord", not(feature = "fedi")))]
|
#[cfg(all(feature = "discord", not(feature = "fedi")))]
|
||||||
Commands::Set { members, discord } => {
|
Commands::Set { members, discord } => {
|
||||||
res = set_member(config_path.clone(), members);
|
res = set_member(config_path.clone(), members);
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")] {
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
let _ = update_avatars(config_path.clone(), discord, false);
|
let _ = update_avatars(config_path.clone(), discord, false);
|
||||||
},
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
#[cfg(all(not(feature = "discord"), feature = "fedi"))]
|
#[cfg(all(not(feature = "discord"), feature = "fedi"))]
|
||||||
Commands::Set { members, fedi} => {
|
Commands::Set { members, fedi} => {
|
||||||
res = set_member(config_path.clone(), members);
|
res = set_member(config_path.clone(), members);
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")] {
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
let _ = update_avatars(config_path.clone(), false, fedi);
|
let _ = update_avatars(config_path.clone(), false, fedi);
|
||||||
},
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
#[cfg(all(not(feature = "discord"), not(feature = "fedi")))]
|
#[cfg(all(not(feature = "discord"), not(feature = "fedi")))]
|
||||||
Commands::Set { members } => {
|
Commands::Set { members } => {
|
||||||
res = set_member(config_path.clone(), members);
|
res = set_member(config_path.clone(), members);
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")] {
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
let _ = update_avatars(config_path.clone(), false, false);
|
let _ = update_avatars(config_path.clone(), false, false);
|
||||||
},
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// ADD MEMBER
|
// ADD MEMBER
|
||||||
#[cfg(all(feature = "discord", feature = "fedi"))]
|
#[cfg(all(feature = "discord", feature = "fedi"))]
|
||||||
Commands::Add { members, discord, fedi } => {
|
Commands::Add { members, discord, fedi } => {
|
||||||
res = add_member(config_path.clone(), members);
|
res = add_member(config_path.clone(), members);
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")] {
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
let _ = update_avatars(config_path.clone(), discord, fedi);
|
let _ = update_avatars(config_path.clone(), discord, fedi);
|
||||||
},
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
#[cfg(all(feature = "discord", not(feature = "fedi")))]
|
#[cfg(all(feature = "discord", not(feature = "fedi")))]
|
||||||
Commands::Add { members, discord } => {
|
Commands::Add { members, discord } => {
|
||||||
res = add_member(config_path.clone(), members);
|
res = add_member(config_path.clone(), members);
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")] {
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
let _ = update_avatars(config_path.clone(), discord, false);
|
let _ = update_avatars(config_path.clone(), discord, false);
|
||||||
},
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
#[cfg(all(not(feature = "discord"), feature = "fedi"))]
|
#[cfg(all(not(feature = "discord"), feature = "fedi"))]
|
||||||
Commands::Add { members, fedi} => {
|
Commands::Add { members, fedi} => {
|
||||||
res = add_member(config_path.clone(), members);
|
res = add_member(config_path.clone(), members);
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")] {
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
let _ = update_avatars(config_path.clone(), false, fedi);
|
let _ = update_avatars(config_path.clone(), false, fedi);
|
||||||
},
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
#[cfg(all(not(feature = "discord"), not(feature = "fedi")))]
|
#[cfg(all(not(feature = "discord"), not(feature = "fedi")))]
|
||||||
Commands::Add { members } => {
|
Commands::Add { members } => {
|
||||||
res = add_member(config_path.clone(), members);
|
res = add_member(config_path.clone(), members);
|
||||||
|
|
||||||
#[cfg(feature = "avatar")]
|
#[cfg(feature = "avatar")] {
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
let _ = update_avatars(config_path.clone(), false, false);
|
let _ = update_avatars(config_path.clone(), false, false);
|
||||||
},
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Get MEMBER
|
// Get MEMBER
|
||||||
#[cfg(all(feature = "discord", feature = "fedi"))]
|
#[cfg(all(feature = "discord", feature = "fedi"))]
|
||||||
|
@ -270,7 +318,21 @@ fn set_member(config_path: String, tf_members: Vec<String>) -> Result<(), &'stat
|
||||||
println!("One or more members were not found. Known members:\n--------------------------");
|
println!("One or more members were not found. Known members:\n--------------------------");
|
||||||
let _ = memberlist(config_path);
|
let _ = memberlist(config_path);
|
||||||
println!("--------------------------\nIf a member is missing from the system try running \"pluralsync sync\" to refresh the local database");
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,11 +365,26 @@ fn add_member(config_path: String, tf_members: Vec<String>) -> Result<(), &'stat
|
||||||
sp_set_fronters(&config.sp_key, &to_front, &fronters);
|
sp_set_fronters(&config.sp_key, &to_front, &fronters);
|
||||||
|
|
||||||
let _ = get(config_path, ForceFrom::None);
|
let _ = get(config_path, ForceFrom::None);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
println!("One or more members were not found. Known members:\n--------------------------");
|
println!("One or more members were not found. Known members:\n--------------------------");
|
||||||
let _ = memberlist(config_path);
|
let _ = memberlist(config_path);
|
||||||
println!("--------------------------\nIf a member is missing from the system try running \"pluralsync sync\" to refresh the local database");
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,6 +463,7 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -415,11 +493,11 @@ fn fedi_module(config: &Config) {
|
||||||
.header(USER_AGENT, "Pluralsync")
|
.header(USER_AGENT, "Pluralsync")
|
||||||
.header(AUTHORIZATION, format!("Bearer {}", &config.fedi_module.token).as_str());
|
.header(AUTHORIZATION, format!("Bearer {}", &config.fedi_module.token).as_str());
|
||||||
|
|
||||||
|
println!("Fedi module finished");
|
||||||
match http_request(rb) {
|
match http_request(rb) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => println!("{}", e.to_string()),
|
Err(e) => println!("{}", e.to_string()),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue