feat: got the logos, and converted them if needs be

This commit is contained in:
silver 2025-06-07 19:55:36 +01:00
parent 0034bd34d6
commit b4f6835704
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -7,7 +7,7 @@ use serenity::{
use skynet_discord_bot::common::database::{db_init, DataBase};
use skynet_discord_bot::{get_config, Config};
use std::{fs, process, sync::Arc};
use std::ffi::OsStr;
use std::ffi::{OsStr, OsString};
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
@ -91,7 +91,7 @@ async fn update_icon_main(ctx: Arc<Context>) {
let festival_data = get_festival(&config_toml);
// get a list of all the graphics files
get_logos(&config_global, &config_toml);
let logos = get_logos(&config_global, &config_toml);
}
fn get_festival(config_toml: &ConfigToml)-> (Option<String>, Vec<String>){
@ -184,7 +184,7 @@ fn convert_svg_to_png(original: &PathBuf, out: &PathBuf){
fs::write(out, &bytes).expect("TODO: panic message");
}
fn get_logos(config: &Config, config_toml: &ConfigToml){
fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<(OsString, PathBuf)> {
let folder = format!("{}/open-governance/{}", &config.home, &config_toml.source.directory);
let folder_path = PathBuf::from(&folder);
let paths = fs::read_dir(folder).unwrap();
@ -198,10 +198,14 @@ fn get_logos(config: &Config, config_toml: &ConfigToml){
};
let mut r = Renderer::new(&args).unwrap();
for path in paths {
let tmp = path.unwrap();
let mut path_local = tmp.path().to_owned();
let mut logos = vec![];
for tmp in paths.flatten() {
let path_local = tmp.path().to_owned();
let path_local2 = tmp.path().to_owned();
let temp2 = path_local2.file_name().unwrap();
let mut file_path = tmp.path();
match tmp.path().extension() {
None => {}
Some(ext) => {
@ -216,11 +220,15 @@ fn get_logos(config: &Config, config_toml: &ConfigToml){
log::error!("Failed to render {path_local:?}: {}", e)
}
}
path_local = path_new;
file_path = path_new;
}
}
};
logos.push((temp2.to_owned(), file_path.to_owned()));
println!("Name: {}", &tmp.path().display());
}
logos
}