feat: nailing down teh format

This commit is contained in:
silver 2023-09-16 18:02:15 +01:00
parent 974173857c
commit 670a85d2ef
2 changed files with 47 additions and 20 deletions

View file

@ -83,7 +83,8 @@ async fn fetch_accounts(ctx: &Context) {
#[derive(Debug, Deserialize)]
pub struct SkynetResult {
discord: String,
wolves_id: String,
id_wolves: String,
id_member: String,
}
async fn get_skynet(db: &Pool<Sqlite>, config: &Config) {
let url = format!("{}/ldap/discord?auth={}", &config.ldap_api, &config.auth);
@ -94,23 +95,46 @@ async fn get_skynet(db: &Pool<Sqlite>, config: &Config) {
}
}
async fn add_users_skynet(db: &Pool<Sqlite>, server: &GuildId, user: &SkynetResult) {
match sqlx::query_as::<_, Accounts>(
"
if !user.id_wolves.is_empty() {
match sqlx::query_as::<_, Accounts>(
"
UPDATE accounts
SET discord = ?
WHERE server = ? AND wolves_id = ?
",
)
.bind(&user.discord)
.bind(*server.as_u64() as i64)
.bind(&user.wolves_id)
.fetch_optional(db)
.await
{
Ok(_) => {}
Err(e) => {
println!("Failure to insert into {} {:?}", server.as_u64(), user);
println!("{:?}", e);
)
.bind(&user.discord)
.bind(*server.as_u64() as i64)
.bind(&user.id_wolves)
.fetch_optional(db)
.await
{
Ok(_) => {}
Err(e) => {
println!("Failure to insert into {} {:?}", server.as_u64(), user);
println!("{:?}", e);
}
}
}
if !user.id_member.is_empty() {
match sqlx::query_as::<_, Accounts>(
"
UPDATE accounts
SET discord = ?
WHERE server = ? AND id_member = ?
",
)
.bind(&user.discord)
.bind(*server.as_u64() as i64)
.bind(&user.id_member)
.fetch_optional(db)
.await
{
Ok(_) => {}
Err(e) => {
println!("Failure to insert into {} {:?}", server.as_u64(), user);
println!("{:?}", e);
}
}
}
}
@ -141,7 +165,7 @@ async fn get_wolves(db: &Pool<Sqlite>) {
async fn add_users_wolves(db: &Pool<Sqlite>, server: &GuildId, user: &WolvesResult) {
match sqlx::query_as::<_, Accounts>(
"
INSERT OR REPLACE INTO accounts (server, wolves_id, email, expiry)
INSERT OR REPLACE INTO accounts (server, id_wolves, email, expiry)
VALUES (?1, ?2, ?3, ?4)
",
)