feat: pull the config for the festivals locally, using teh imported repo
This commit is contained in:
parent
6d5ad8e418
commit
86a3af2a65
3 changed files with 74 additions and 60 deletions
|
@ -3,21 +3,4 @@
|
||||||
[source]
|
[source]
|
||||||
repo = "https://forgejo.skynet.ie/Computer_Society/open-goverance"
|
repo = "https://forgejo.skynet.ie/Computer_Society/open-goverance"
|
||||||
directory = "Resources/Logo_Variants"
|
directory = "Resources/Logo_Variants"
|
||||||
|
file = "_festivals.toml"
|
||||||
[[festivals]]
|
|
||||||
name = "pride"
|
|
||||||
all_year = true
|
|
||||||
start = { day = 1, month = 6, year = 0}
|
|
||||||
end = { day = 30, month = 6, year = 0}
|
|
||||||
|
|
||||||
[[festivals]]
|
|
||||||
name = "christmas"
|
|
||||||
all_year = false
|
|
||||||
start = { day = 1, month = 12, year = 0}
|
|
||||||
end = { day = 31, month = 12, year = 0}
|
|
||||||
|
|
||||||
[[festivals]]
|
|
||||||
name = "halloween"
|
|
||||||
all_year = false
|
|
||||||
start = { day = 1, month = 12, year = 0}
|
|
||||||
end = { day = 31, month = 12, year = 0}
|
|
|
@ -4,15 +4,12 @@ use serenity::{
|
||||||
model::gateway::{GatewayIntents, Ready},
|
model::gateway::{GatewayIntents, Ready},
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
use skynet_discord_bot::common::server_icon;
|
use skynet_discord_bot::common::server_icon::{get_config_icons, update_icon};
|
||||||
use skynet_discord_bot::{
|
use skynet_discord_bot::{
|
||||||
common::database::{db_init, DataBase},
|
common::database::{db_init, DataBase},
|
||||||
get_config, Config,
|
get_config, Config,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{process, sync::Arc};
|
||||||
process::self,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -62,9 +59,9 @@ impl EventHandler for Handler {
|
||||||
};
|
};
|
||||||
|
|
||||||
let config_global = config_lock.read().await;
|
let config_global = config_lock.read().await;
|
||||||
let config_toml = server_icon::get_config_icons();
|
let config_toml = get_config_icons::minimal();
|
||||||
|
|
||||||
server_icon::update_icon::update_icon_main(&ctx, &db, &config_global, &config_toml).await;
|
update_icon::update_icon_main(&ctx, &db, &config_global, &config_toml).await;
|
||||||
|
|
||||||
// finish up
|
// finish up
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
|
|
|
@ -1,37 +1,65 @@
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{ffi::OsString, path::PathBuf};
|
use std::{ffi::OsString, fs, path::PathBuf};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
pub mod get_config_icons {
|
||||||
pub struct ConfigToml {
|
use super::*;
|
||||||
pub source: ConfigTomlSource,
|
use crate::Config;
|
||||||
pub festivals: Vec<ConfigTomlFestivals>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct ConfigTomlSource {
|
pub struct ConfigToml {
|
||||||
pub repo: String,
|
pub source: ConfigTomlSource,
|
||||||
pub directory: String,
|
pub festivals: Vec<ConfigTomlFestivals>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct ConfigTomlFestivals {
|
pub struct ConfigTomlLocal {
|
||||||
pub name: String,
|
pub source: ConfigTomlSource,
|
||||||
pub all_year: bool,
|
}
|
||||||
pub start: ConfigTomlFestivalsTime,
|
#[derive(Deserialize)]
|
||||||
pub end: ConfigTomlFestivalsTime,
|
pub struct ConfigTomlRemote {
|
||||||
}
|
pub festivals: Vec<ConfigTomlFestivals>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct ConfigTomlFestivalsTime {
|
pub struct ConfigTomlSource {
|
||||||
pub day: u32,
|
pub repo: String,
|
||||||
pub month: u32,
|
pub directory: String,
|
||||||
pub year: i32,
|
pub file: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_config_icons() -> ConfigToml {
|
#[derive(Deserialize, Debug)]
|
||||||
let toml_raw = include_str!("../../.server-icons.toml");
|
pub struct ConfigTomlFestivals {
|
||||||
let config: ConfigToml = toml::from_str(toml_raw).unwrap();
|
pub name: String,
|
||||||
config
|
pub all_year: bool,
|
||||||
|
pub start: ConfigTomlFestivalsTime,
|
||||||
|
pub end: ConfigTomlFestivalsTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct ConfigTomlFestivalsTime {
|
||||||
|
pub day: u32,
|
||||||
|
pub month: u32,
|
||||||
|
pub year: i32,
|
||||||
|
}
|
||||||
|
pub fn minimal() -> ConfigTomlLocal {
|
||||||
|
let toml_raw_min = include_str!("../../.server-icons.toml");
|
||||||
|
let config_min: ConfigTomlLocal = toml::from_str(toml_raw_min).unwrap();
|
||||||
|
config_min
|
||||||
|
}
|
||||||
|
|
||||||
|
// since a copy of the festival file is in the repo we just need to get to it
|
||||||
|
pub fn full(config: &Config) -> ConfigToml {
|
||||||
|
let config_source = minimal();
|
||||||
|
|
||||||
|
let file_path = format!("{}/open-governance/{}/{}", &config.home, &config_source.source.directory, &config_source.source.file);
|
||||||
|
let contents = fs::read_to_string(file_path).expect("Should have been able to read the file");
|
||||||
|
let config_festivals: ConfigTomlRemote = toml::from_str(&contents).unwrap();
|
||||||
|
|
||||||
|
ConfigToml {
|
||||||
|
source: config_source.source,
|
||||||
|
festivals: config_festivals.festivals,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -50,7 +78,10 @@ pub struct ServerIcons {
|
||||||
pub mod update_icon {
|
pub mod update_icon {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
common::renderer::{Args, Renderer},
|
common::{
|
||||||
|
renderer::{Args, Renderer},
|
||||||
|
server_icon::get_config_icons::{self, ConfigToml, ConfigTomlLocal},
|
||||||
|
},
|
||||||
get_now_iso, Config,
|
get_now_iso, Config,
|
||||||
};
|
};
|
||||||
use chrono::{Datelike, Utc};
|
use chrono::{Datelike, Utc};
|
||||||
|
@ -61,20 +92,23 @@ pub mod update_icon {
|
||||||
client::Context,
|
client::Context,
|
||||||
};
|
};
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use std::{fs, process::Command};
|
use std::process::Command;
|
||||||
|
|
||||||
/// Update the server icon, pulling from open governance.
|
/// Update the server icon, pulling from open governance.
|
||||||
pub async fn update_icon_main(ctx: &Context, db: &Pool<Sqlite>, config_global: &Config, config_toml: &ConfigToml) {
|
pub async fn update_icon_main(ctx: &Context, db: &Pool<Sqlite>, config_global: &Config, config_toml_local: &ConfigTomlLocal) {
|
||||||
let server = GuildId::new(689189992417067052);
|
let server = GuildId::new(689189992417067052);
|
||||||
|
|
||||||
// clone repo into local folder
|
// clone repo into local folder
|
||||||
clone_repo(config_global, config_toml);
|
clone_repo(config_global, config_toml_local);
|
||||||
|
|
||||||
|
// now the repo has been downloaded/updated we can now access the festivals
|
||||||
|
let config_toml = get_config_icons::full(config_global);
|
||||||
|
|
||||||
// see if there is a current festival
|
// see if there is a current festival
|
||||||
let festival_data = get_festival(config_toml);
|
let festival_data = get_festival(&config_toml);
|
||||||
|
|
||||||
// get a list of all the graphics files
|
// get a list of all the graphics files
|
||||||
let logos = get_logos(config_global, config_toml);
|
let logos = get_logos(config_global, &config_toml);
|
||||||
|
|
||||||
// filter them so only the current season (if any) are active
|
// filter them so only the current season (if any) are active
|
||||||
let logos_filtered = logos_filter(&festival_data, logos);
|
let logos_filtered = logos_filter(&festival_data, logos);
|
||||||
|
@ -115,7 +149,7 @@ pub mod update_icon {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clone_repo(config: &Config, config_toml: &ConfigToml) {
|
fn clone_repo(config: &Config, config_toml: &ConfigTomlLocal) {
|
||||||
let url = &config_toml.source.repo;
|
let url = &config_toml.source.repo;
|
||||||
let folder = format!("{}/open-governance", &config.home);
|
let folder = format!("{}/open-governance", &config.home);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue