feat: bump up rust version and a big cleanup
Also added an example .env This will break stuff (briefly)
This commit is contained in:
parent
8ba92cc47e
commit
9452c0ac2e
7 changed files with 825 additions and 681 deletions
34
src/lib.rs
34
src/lib.rs
|
@ -23,19 +23,20 @@ use std::{env, str::FromStr, sync::Arc};
|
|||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct Config {
|
||||
pub skynet_server: GuildId,
|
||||
pub ldap_api: String,
|
||||
// manages where teh database is stored
|
||||
pub home: String,
|
||||
pub database: String,
|
||||
|
||||
pub auth: String,
|
||||
// tokens for discord and other API's
|
||||
pub discord_token: String,
|
||||
pub discord_minecraft: String,
|
||||
pub discord_token_minecraft: String,
|
||||
|
||||
// email settings
|
||||
pub mail_smtp: String,
|
||||
pub mail_user: String,
|
||||
pub mail_pass: String,
|
||||
|
||||
// wolves API base for clubs/socs
|
||||
pub wolves_url: String,
|
||||
}
|
||||
impl TypeMapKey for Config {
|
||||
|
@ -52,11 +53,8 @@ pub fn get_config() -> Config {
|
|||
|
||||
// reasonable defaults
|
||||
let mut config = Config {
|
||||
skynet_server: Default::default(),
|
||||
ldap_api: "https://api.account.skynet.ie".to_string(),
|
||||
auth: "".to_string(),
|
||||
discord_token: "".to_string(),
|
||||
discord_minecraft: "".to_string(),
|
||||
discord_token_minecraft: "".to_string(),
|
||||
|
||||
home: ".".to_string(),
|
||||
database: "database.db".to_string(),
|
||||
|
@ -67,12 +65,6 @@ pub fn get_config() -> Config {
|
|||
wolves_url: "".to_string(),
|
||||
};
|
||||
|
||||
if let Ok(x) = env::var("LDAP_API") {
|
||||
config.ldap_api = x.trim().to_string();
|
||||
}
|
||||
if let Ok(x) = env::var("SKYNET_SERVER") {
|
||||
config.skynet_server = GuildId::from(str_to_num::<u64>(&x));
|
||||
}
|
||||
if let Ok(x) = env::var("HOME") {
|
||||
config.home = x.trim().to_string();
|
||||
}
|
||||
|
@ -80,15 +72,11 @@ pub fn get_config() -> Config {
|
|||
config.database = x.trim().to_string();
|
||||
}
|
||||
|
||||
if let Ok(x) = env::var("LDAP_DISCORD_AUTH") {
|
||||
config.auth = x.trim().to_string();
|
||||
}
|
||||
|
||||
if let Ok(x) = env::var("DISCORD_TOKEN") {
|
||||
config.discord_token = x.trim().to_string();
|
||||
}
|
||||
if let Ok(x) = env::var("DISCORD_MINECRAFT") {
|
||||
config.discord_minecraft = x.trim().to_string();
|
||||
if let Ok(x) = env::var("DISCORD_TOKEN_MINECRAFT") {
|
||||
config.discord_token_minecraft = x.trim().to_string();
|
||||
}
|
||||
|
||||
if let Ok(x) = env::var("EMAIL_SMTP") {
|
||||
|
@ -108,10 +96,6 @@ pub fn get_config() -> Config {
|
|||
config
|
||||
}
|
||||
|
||||
fn str_to_num<T: FromStr + Default>(x: &str) -> T {
|
||||
x.trim().parse::<T>().unwrap_or_default()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct ServerMembers {
|
||||
pub server: GuildId,
|
||||
|
@ -727,7 +711,7 @@ pub async fn update_server(server_id: &str, db: &Pool<Sqlite>, g_id: &GuildId, c
|
|||
}
|
||||
}
|
||||
if !usernames.is_empty() {
|
||||
whitelist_update(&usernames, server_id, &config.discord_minecraft).await;
|
||||
whitelist_update(&usernames, server_id, &config.discord_token_minecraft).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue