docs and some renames

This commit is contained in:
Junko 2024-01-14 01:57:56 +01:00
parent 42894c4939
commit 6603958567
4 changed files with 57 additions and 46 deletions

View File

@ -13,16 +13,21 @@ On the first run, if it does not exist, PluralSync will create a configuration d
{ {
"pk_key": "// Pluralkit token", "pk_key": "// Pluralkit token",
"sp_key": "// Simplplural token", "sp_key": "// Simplplural token",
"pfp_module": { "avatar_module": {
"enabled": false, "enabled": false,
"pfp_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",
"pfp_output_path": "// Path for the copied selected pfp" "avatar_output_path": "// Path for the copied selected avatar"
}, },
"disc_module": { "disc_module": {
"enabled": false, "enabled": false,
"token": "// Discord user token", "token": "// Discord user token",
"python_path": "// Path to the python executable", "python_path": "// Path to the python executable",
"script_path": "// Path to updatepfp.py" "script_path": "// Path to updatediscordavatar.py"
},
"fedi_module": {
"enabled": false,
"instance" : "// Fedi instance url",
"token": "// Fedi bearer token"
} }
} }
#+end_src #+end_src
@ -43,17 +48,22 @@ Just fill it with PluralKit and SimplyPlural tokens associated to your account.
- *Memberlist* - Writes the known list of members based on the =system.json= file. - *Memberlist* - Writes the known list of members based on the =system.json= file.
** Modules ** Modules
*** PFP module *** Avatar module
Will get a profile picture from a folder based on the currently fronting members and will copy it to the desired location. I recommend something it's easy to have at hand like =~/face=. Will get a profile picture from a folder based on the currently fronting members and will copy it to the desired location. I recommend something it's easy to have at hand like =~/face=.
The pictures in the path should be named according to the front. For example, if Bob and Alice are fronting, the module will copy ={PATH}/bobalice.png= to the location, or if it's only Bob it'll be =bob.png=. The pictures in the path should be named according to the front. For example, if Bob and Alice are fronting, the module will copy ={PATH}/bobalice.png= to the location, or if it's only Bob it'll be =bob.png=.
Notice this will cover all combinations, if the main front is Alice the combination =alicebob.png= instead. I recommend the use of a python script to generate the possible combinations. Notice this will cover all combinations, if the main front is Alice the combination =alicebob.png= instead. I personally use a python script to generate my set.
*** Discord module *** Discord module
**Use of this module goes against discord terms of service. USE AT YOUR OWN RISK.** **Use of this module goes against discord terms of service. USE AT YOUR OWN RISK.**
Requires the =PFP module= to be enabled and the latest version of [[https://github.com/dolfies/discord.py-self/][discord.py-self]]. Requires the =avatar module= to be enabled and the latest version of [[https://github.com/dolfies/discord.py-self/][discord.py-self]].
Will change your discord avatar with the one selected by the PFP module. Will change your discord avatar with the one selected by the avatar module.
*** Fedi module
Should be compatible with Mastodon, Pleroma and Akkoma.
Requires the =avatar module= to be enabled. Will set the avatar of your fediverse account to the one selected by the avatar module.
* Installation * Installation
Just build with cargo and move or symlink the executable wherever is more comofortable for you. Just build with cargo and move or symlink the executable wherever is more comofortable for you.
@ -65,5 +75,6 @@ cargo build -r
* Future * Future
Given the nature of the project as a learning exercise, there are currently a set of features and improvements I'd like to add eventually. Given the nature of the project as a learning exercise, there are currently a set of features and improvements I'd like to add eventually.
- [X] Proper error handling (What I have currently is simply a mess) - [X] Proper error handling (What I have currently is simply a mess)
- [ ] Rofi and zenity support - [ ] Allow the user to set which front is used in cased of mismatch between PK and SP
- [ ] Proper way to handle front conflicts between PluralKit and SimplyPlural - [ ] Implement clippy
- [ ] Actually separate the modules as actual modules

View File

@ -1,20 +1,20 @@
{ {
"pk_key": "// Pluralkit token", "pk_key": "// Pluralkit token",
"sp_key": "// Simplplural token", "sp_key": "// Simplplural token",
"pfp_module": { "avatar_module": {
"enabled": false, "enabled": false,
"pfp_folder": "// Folder to grab profile pictures, they follow they member1member2.png format", "avatar_folder": "// Folder to grab profile pictures, they follow they member1member2...memberX.png format",
"pfp_output_path": "// Path for the copied selected pfp" "avatar_output_path": "// Path for the copied selected avatar"
}, },
"disc_module": { "disc_module": {
"enabled": false, "enabled": false,
"token": "// Discord user token", "token": "// Discord user token",
"python_path": "// Path to the python executable", "python_path": "// Path to the python executable",
"script_path": "// Path to updatepfp.py" "script_path": "// Path to updatediscordavatar.py"
}, },
"pleroma_module": { "fedi_module": {
"enabled": true, "enabled": false,
"instance" : "// Pleroma instance url", "instance" : "// Fedi instance url",
"token": "// Pleroma bearer token" "token": "// Fedi bearer token"
} }
} }

View File

@ -16,16 +16,16 @@ use dirs;
struct Config { struct Config {
pk_key: String, pk_key: String,
sp_key: String, sp_key: String,
pfp_module: PfpModule, avatar_module: AvatarModule,
disc_module: DiscModule, disc_module: DiscModule,
pleroma_module: PleromaModule, fedi_module: FediModule,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct PfpModule { struct AvatarModule {
enabled: bool, enabled: bool,
pfp_folder: String, avatar_folder: String,
pfp_output_path: String, avatar_output_path: String,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -37,7 +37,7 @@ struct DiscModule {
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct PleromaModule { struct FediModule {
enabled: bool, enabled: bool,
instance: String, instance: String,
token: String, token: String,
@ -76,21 +76,21 @@ const SP_URL: &str = "https://api.apparyllis.com/v1";
const EXAMPLE_JSON: &str = r#"{ const EXAMPLE_JSON: &str = r#"{
"pk_key": "// Pluralkit token", "pk_key": "// Pluralkit token",
"sp_key": "// Simplplural token", "sp_key": "// Simplplural token",
"pfp_module": { "avatar_module": {
"enabled": false, "enabled": false,
"pfp_folder": "// Folder to grab profile pictures, they follow they member1member2.png format", "avatar_folder": "// Folder to grab profile pictures, they follow they member1member2...memberX.png format",
"pfp_output_path": "// Path for the copied selected pfp" "avatar_output_path": "// Path for the copied selected avatar"
}, },
"disc_module": { "disc_module": {
"enabled": false, "enabled": false,
"token": "// Discord user token", "token": "// Discord user token",
"python_path": "// Path to the python executable", "python_path": "// Path to the python executable",
"script_path": "// Path to updatepfp.py" "script_path": "// Path to updatediscordavatar.py"
}, },
"pleroma_module": { "fedi_module": {
"enabled": true, "enabled": false,
"instance" : "// Pleroma instance url", "instance" : "// Fedi instance url",
"token": "// Pleroma bearer token" "token": "// Fedi bearer token"
} }
}"#; }"#;
@ -307,16 +307,16 @@ fn get(config_path: String) -> Result<(), &'static str> {
println!("Currently fronting: {}", fronters); println!("Currently fronting: {}", fronters);
let _ = fs::write(format!("{}/.front", config_path), fronters); let _ = fs::write(format!("{}/.front", config_path), fronters);
if config.pfp_module.enabled { if config.avatar_module.enabled {
let pfpnames = names.join("").to_lowercase() + ".png"; let avatarnames = names.join("").to_lowercase() + ".png";
if Path::new(&config.pfp_module.pfp_output_path).exists() { if Path::new(&config.avatar_module.avatar_output_path).exists() {
let _ = remove_file(&config.pfp_module.pfp_output_path); let _ = remove_file(&config.avatar_module.avatar_output_path);
} }
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
let cmdaug = format!("copy {}\\{} {}", &config.pfp_module.pfp_folder, pfpnames, &config.pfp_module.pfp_output_path); let cmdaug = format!("copy {}\\{} {}", &config.avatar_module.avatar_folder, avatarnames, &config.avatar_module.avatar_output_path);
Command::new("cmd").args(["/C", &cmdaug]).output().expect("PFP module error"); Command::new("cmd").args(["/C", &cmdaug]).output().expect("Avatar module error");
if config.disc_module.enabled { if config.disc_module.enabled {
let mut c = Command::new("cmd").args(["/C", format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path).as_str()]).spawn().expect("Discord module error"); let mut c = Command::new("cmd").args(["/C", format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path).as_str()]).spawn().expect("Discord module error");
@ -324,15 +324,15 @@ fn get(config_path: String) -> Result<(), &'static str> {
} }
} else { } else {
Command::new("sh").arg("-c").arg(format!("cp {}/{} {}", &config.pfp_module.pfp_folder, pfpnames, &config.pfp_module.pfp_output_path)).output().expect("PFP 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");
if config.disc_module.enabled { if config.disc_module.enabled {
let mut c = Command::new("sh").arg("-c").arg(format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path)).spawn().expect("Discord module error"); let mut c = Command::new("sh").arg("-c").arg(format!("{} {}", &config.disc_module.python_path, &config.disc_module.script_path)).spawn().expect("Discord module error");
let _ = c.wait().expect("Error"); let _ = c.wait().expect("Error");
} }
if config.pleroma_module.enabled { if config.fedi_module.enabled {
let _ = http_patch_request_pleroma(config.pleroma_module.instance + "/api/v1/accounts/update_credentials", format!("Bearer {}", &config.pleroma_module.token).as_str(), config.pfp_module.pfp_output_path); let _ = http_patch_request_fedi(config.fedi_module.instance + "/api/v1/accounts/update_credentials", format!("Bearer {}", &config.fedi_module.token).as_str(), config.avatar_module.avatar_output_path);
} }
} }
} }
@ -640,7 +640,7 @@ async fn http_patch_request(url: String, key: &str, body: String ) -> Result<(),
} }
#[tokio::main] #[tokio::main]
async fn http_patch_request_pleroma(url: String, key: &str, file_path: String ) -> Result<(), Box<dyn std::error::Error>> { async fn http_patch_request_fedi(url: String, key: &str, file_path: String ) -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let form = Form::new().part("avatar", Part::bytes(fs::read(file_path).unwrap()).file_name("face.png").mime_str("image/png").unwrap()); let form = Form::new().part("avatar", Part::bytes(fs::read(file_path).unwrap()).file_name("face.png").mime_str("image/png").unwrap());
let c = client let c = client

View File

@ -13,10 +13,10 @@ json = json.load(f)
class MyClient(discord.Client): class MyClient(discord.Client):
async def on_ready(self): async def on_ready(self):
print('Logged on as', self.user) print('Logged on as', self.user)
pfp_path = json["pfp_module"]["pfp_output_path"] avatar_path = json["avatar_module"]["avatar_output_path"]
fp = open(pfp_path, 'rb') fp = open(avatar_path, 'rb')
pfp = fp.read() avatar = fp.read()
await self.user.edit(avatar=pfp) await self.user.edit(avatar=avatar)
print('Discord module finished') print('Discord module finished')
await self.close() await self.close()