Compare commits
No commits in common. "e7caf148dd71de41abcc315ef799353faba48395" and "befced76f81fd4f4fe81ff99210e7b8943b6efdf" have entirely different histories.
e7caf148dd
...
befced76f8
6 changed files with 53 additions and 23 deletions
|
@ -1,8 +0,0 @@
|
||||||
HOME="."
|
|
||||||
DATABASE="database.db"
|
|
||||||
DISCORD_TOKEN=""
|
|
||||||
DISCORD_TOKEN_MINECRAFT=""
|
|
||||||
EMAIL_SMTP=""
|
|
||||||
EMAIL_USER=""
|
|
||||||
EMAIL_PASS=""
|
|
||||||
WOLVES_URL=""
|
|
26
flake.nix
26
flake.nix
|
@ -75,6 +75,8 @@
|
||||||
cfg = config.services."${package_name}";
|
cfg = config.services."${package_name}";
|
||||||
# secret options are in the env file(s) loaded separately
|
# secret options are in the env file(s) loaded separately
|
||||||
environment_config = {
|
environment_config = {
|
||||||
|
LDAP_API = cfg.ldap;
|
||||||
|
SKYNET_SERVER = cfg.discord.server;
|
||||||
HOME = cfg.home;
|
HOME = cfg.home;
|
||||||
DATABASE = "database.db";
|
DATABASE = "database.db";
|
||||||
};
|
};
|
||||||
|
@ -95,6 +97,7 @@
|
||||||
Group = "${cfg.user}";
|
Group = "${cfg.user}";
|
||||||
ExecStart = "${self.defaultPackage."${system}"}/bin/${script}";
|
ExecStart = "${self.defaultPackage."${system}"}/bin/${script}";
|
||||||
EnvironmentFile = [
|
EnvironmentFile = [
|
||||||
|
"${cfg.env.ldap}"
|
||||||
"${cfg.env.discord}"
|
"${cfg.env.discord}"
|
||||||
"${cfg.env.mail}"
|
"${cfg.env.mail}"
|
||||||
"${cfg.env.wolves}"
|
"${cfg.env.wolves}"
|
||||||
|
@ -130,9 +133,13 @@
|
||||||
enable = mkEnableOption "enable ${package_name}";
|
enable = mkEnableOption "enable ${package_name}";
|
||||||
|
|
||||||
env = {
|
env = {
|
||||||
|
ldap = mkOption rec {
|
||||||
|
type = types.str;
|
||||||
|
description = "ENV file with LDAP_DISCORD_AUTH";
|
||||||
|
};
|
||||||
discord = mkOption rec {
|
discord = mkOption rec {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "ENV file with DISCORD_TOKEN, DISCORD_TOKEN_MINECRAFT";
|
description = "ENV file with DISCORD_TOKEN, DISCORD_MINECRAFT";
|
||||||
};
|
};
|
||||||
mail = mkOption rec {
|
mail = mkOption rec {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
@ -140,10 +147,23 @@
|
||||||
};
|
};
|
||||||
wolves = mkOption rec {
|
wolves = mkOption rec {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "Mail details, has WOLVES_URL";
|
description = "Mail details, has WOLVES_URL, WOLVES_KEY";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
discord = {
|
||||||
|
server = mkOption rec {
|
||||||
|
type = types.str;
|
||||||
|
description = "ID of the server the bot runs on";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
ldap = mkOption rec {
|
||||||
|
type = types.str;
|
||||||
|
default = "https://api.account.skynet.ie";
|
||||||
|
description = "Location of the ldap api";
|
||||||
|
};
|
||||||
|
|
||||||
user = mkOption rec {
|
user = mkOption rec {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "${package_name}";
|
default = "${package_name}";
|
||||||
|
@ -191,12 +211,14 @@
|
||||||
ExecStart = "${self.defaultPackage."${system}"}/bin/${package_name}";
|
ExecStart = "${self.defaultPackage."${system}"}/bin/${package_name}";
|
||||||
# can have multiple env files
|
# can have multiple env files
|
||||||
EnvironmentFile = [
|
EnvironmentFile = [
|
||||||
|
"${cfg.env.ldap}"
|
||||||
"${cfg.env.discord}"
|
"${cfg.env.discord}"
|
||||||
"${cfg.env.mail}"
|
"${cfg.env.mail}"
|
||||||
"${cfg.env.wolves}"
|
"${cfg.env.wolves}"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
restartTriggers = [
|
restartTriggers = [
|
||||||
|
"${cfg.env.ldap}"
|
||||||
"${cfg.env.discord}"
|
"${cfg.env.discord}"
|
||||||
"${cfg.env.mail}"
|
"${cfg.env.mail}"
|
||||||
"${cfg.env.wolves}"
|
"${cfg.env.wolves}"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "1.80"
|
channel = "1.80.1"
|
||||||
|
|
|
@ -15,7 +15,7 @@ async fn main() {
|
||||||
for server in &servers {
|
for server in &servers {
|
||||||
// wipe whitelist first
|
// wipe whitelist first
|
||||||
if !wiped.contains(&server.minecraft) {
|
if !wiped.contains(&server.minecraft) {
|
||||||
whitelist_wipe(&server.minecraft, &config.discord_token_minecraft).await;
|
whitelist_wipe(&server.minecraft, &config.discord_minecraft).await;
|
||||||
// add it to teh done list so its not done again
|
// add it to teh done list so its not done again
|
||||||
wiped.insert(&server.minecraft);
|
wiped.insert(&server.minecraft);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub(crate) mod user {
|
||||||
// get a list of servers that the user is a member of
|
// get a list of servers that the user is a member of
|
||||||
if let Ok(servers) = get_servers(&db, &command.user.id).await {
|
if let Ok(servers) = get_servers(&db, &command.user.id).await {
|
||||||
for server in servers {
|
for server in servers {
|
||||||
whitelist_update(&vec![username.to_string()], &server.minecraft, &config.discord_token_minecraft).await;
|
whitelist_update(&vec![username.to_string()], &server.minecraft, &config.discord_minecraft).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ pub(crate) mod server {
|
||||||
|
|
||||||
let mut result = "Server Information:\n".to_string();
|
let mut result = "Server Information:\n".to_string();
|
||||||
for server in get_minecraft_config_server(&db, g_id).await {
|
for server in get_minecraft_config_server(&db, g_id).await {
|
||||||
if let Some(x) = server_information(&server.minecraft, &config.discord_token_minecraft).await {
|
if let Some(x) = server_information(&server.minecraft, &config.discord_minecraft).await {
|
||||||
result.push_str(&format!(
|
result.push_str(&format!(
|
||||||
r#"
|
r#"
|
||||||
Name: {name}
|
Name: {name}
|
||||||
|
|
34
src/lib.rs
34
src/lib.rs
|
@ -23,20 +23,19 @@ use std::{env, str::FromStr, sync::Arc};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
// manages where teh database is stored
|
pub skynet_server: GuildId,
|
||||||
|
pub ldap_api: String,
|
||||||
pub home: String,
|
pub home: String,
|
||||||
pub database: String,
|
pub database: String,
|
||||||
|
|
||||||
// tokens for discord and other API's
|
pub auth: String,
|
||||||
pub discord_token: String,
|
pub discord_token: String,
|
||||||
pub discord_token_minecraft: String,
|
pub discord_minecraft: String,
|
||||||
|
|
||||||
// email settings
|
|
||||||
pub mail_smtp: String,
|
pub mail_smtp: String,
|
||||||
pub mail_user: String,
|
pub mail_user: String,
|
||||||
pub mail_pass: String,
|
pub mail_pass: String,
|
||||||
|
|
||||||
// wolves API base for clubs/socs
|
|
||||||
pub wolves_url: String,
|
pub wolves_url: String,
|
||||||
}
|
}
|
||||||
impl TypeMapKey for Config {
|
impl TypeMapKey for Config {
|
||||||
|
@ -53,8 +52,11 @@ pub fn get_config() -> Config {
|
||||||
|
|
||||||
// reasonable defaults
|
// reasonable defaults
|
||||||
let mut config = Config {
|
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_token: "".to_string(),
|
||||||
discord_token_minecraft: "".to_string(),
|
discord_minecraft: "".to_string(),
|
||||||
|
|
||||||
home: ".".to_string(),
|
home: ".".to_string(),
|
||||||
database: "database.db".to_string(),
|
database: "database.db".to_string(),
|
||||||
|
@ -65,6 +67,12 @@ pub fn get_config() -> Config {
|
||||||
wolves_url: "".to_string(),
|
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") {
|
if let Ok(x) = env::var("HOME") {
|
||||||
config.home = x.trim().to_string();
|
config.home = x.trim().to_string();
|
||||||
}
|
}
|
||||||
|
@ -72,11 +80,15 @@ pub fn get_config() -> Config {
|
||||||
config.database = x.trim().to_string();
|
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") {
|
if let Ok(x) = env::var("DISCORD_TOKEN") {
|
||||||
config.discord_token = x.trim().to_string();
|
config.discord_token = x.trim().to_string();
|
||||||
}
|
}
|
||||||
if let Ok(x) = env::var("DISCORD_TOKEN_MINECRAFT") {
|
if let Ok(x) = env::var("DISCORD_MINECRAFT") {
|
||||||
config.discord_token_minecraft = x.trim().to_string();
|
config.discord_minecraft = x.trim().to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(x) = env::var("EMAIL_SMTP") {
|
if let Ok(x) = env::var("EMAIL_SMTP") {
|
||||||
|
@ -96,6 +108,10 @@ pub fn get_config() -> 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)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct ServerMembers {
|
pub struct ServerMembers {
|
||||||
pub server: GuildId,
|
pub server: GuildId,
|
||||||
|
@ -711,7 +727,7 @@ pub async fn update_server(server_id: &str, db: &Pool<Sqlite>, g_id: &GuildId, c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !usernames.is_empty() {
|
if !usernames.is_empty() {
|
||||||
whitelist_update(&usernames, server_id, &config.discord_token_minecraft).await;
|
whitelist_update(&usernames, server_id, &config.discord_minecraft).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue