feat: modified to use the wolves api

This commit is contained in:
silver 2023-10-27 01:39:03 +01:00
parent 4125ad634f
commit 49363d02aa
2 changed files with 62 additions and 129 deletions

View file

@ -31,6 +31,8 @@ pub struct Config {
pub mail_smtp: String,
pub mail_user: String,
pub mail_pass: String,
pub wolves_url: String,
}
impl TypeMapKey for Config {
type Value = Arc<RwLock<Config>>;
@ -58,6 +60,7 @@ pub fn get_config() -> Config {
mail_smtp: "".to_string(),
mail_user: "".to_string(),
mail_pass: "".to_string(),
wolves_url: "".to_string(),
};
if let Ok(x) = env::var("LDAP_API") {
@ -94,6 +97,10 @@ pub fn get_config() -> Config {
config.mail_pass = x.trim().to_string();
}
if let Ok(x) = env::var("WOLVES_URL") {
config.wolves_url = x.trim().to_string();
}
config
}
@ -104,7 +111,7 @@ fn str_to_num<T: FromStr + Default>(x: &str) -> T {
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ServerMembers {
pub server: GuildId,
pub id_wolves: String,
pub id_wolves: i64,
pub expiry: String,
}
impl<'r> FromRow<'r, SqliteRow> for ServerMembers {
@ -123,7 +130,7 @@ impl<'r> FromRow<'r, SqliteRow> for ServerMembers {
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ServerMembersWolves {
pub server: GuildId,
pub id_wolves: String,
pub id_wolves: i64,
pub expiry: String,
pub email: String,
pub discord: Option<UserId>,
@ -158,7 +165,7 @@ impl<'r> FromRow<'r, SqliteRow> for ServerMembersWolves {
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Wolves {
pub id_wolves: String,
pub id_wolves: i64,
pub email: String,
pub discord: Option<UserId>,
pub minecraft: Option<String>,
@ -268,7 +275,7 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
sqlx::query(
"CREATE TABLE IF NOT EXISTS wolves (
id_wolves text PRIMARY KEY,
id_wolves integer PRIMARY KEY,
email text not null,
discord integer,
minecraft text
@ -297,7 +304,7 @@ pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
sqlx::query(
"CREATE TABLE IF NOT EXISTS server_members (
server integer not null,
id_wolves text not null,
id_wolves integer not null,
expiry text not null,
PRIMARY KEY(server,id_wolves),
FOREIGN KEY (id_wolves) REFERENCES wolves (id_wolves)