fmt: fmt and clippy
This commit is contained in:
parent
a745d7631d
commit
974173857c
1 changed files with 15 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
||||||
use skynet_discord_bot::{db_init, get_config, Accounts, Config, DataBase, get_server_config_bulk, Servers};
|
use skynet_discord_bot::{db_init, get_config, get_server_config_bulk, Accounts, Config, DataBase, Servers};
|
||||||
use std::{process, sync::Arc};
|
use std::{process, sync::Arc};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -78,7 +78,6 @@ async fn fetch_accounts(ctx: &Context) {
|
||||||
|
|
||||||
// get from skynet for the compsoc server only
|
// get from skynet for the compsoc server only
|
||||||
get_skynet(&db, &config).await;
|
get_skynet(&db, &config).await;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
@ -86,11 +85,11 @@ pub struct SkynetResult {
|
||||||
discord: String,
|
discord: String,
|
||||||
wolves_id: String,
|
wolves_id: String,
|
||||||
}
|
}
|
||||||
async fn get_skynet(db: &Pool<Sqlite>, config: &Config){
|
async fn get_skynet(db: &Pool<Sqlite>, config: &Config) {
|
||||||
let url = format!("{}/ldap/discord?auth={}", &config.ldap_api, &config.auth);
|
let url = format!("{}/ldap/discord?auth={}", &config.ldap_api, &config.auth);
|
||||||
if let Ok(result) = surf::get(url).recv_json::<Vec<SkynetResult>>().await {
|
if let Ok(result) = surf::get(url).recv_json::<Vec<SkynetResult>>().await {
|
||||||
for user in result {
|
for user in result {
|
||||||
add_users_skynet(&db, &config.skynet_server, &user).await;
|
add_users_skynet(db, &config.skynet_server, &user).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +121,7 @@ struct WolvesResult {
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub expiry: String,
|
pub expiry: String,
|
||||||
}
|
}
|
||||||
async fn get_wolves(db: &Pool<Sqlite>){
|
async fn get_wolves(db: &Pool<Sqlite>) {
|
||||||
for server_config in get_server_config_bulk(db).await {
|
for server_config in get_server_config_bulk(db).await {
|
||||||
let Servers {
|
let Servers {
|
||||||
server,
|
server,
|
||||||
|
@ -131,27 +130,27 @@ async fn get_wolves(db: &Pool<Sqlite>){
|
||||||
} = server_config;
|
} = server_config;
|
||||||
|
|
||||||
// get the data here
|
// get the data here
|
||||||
let mut result: Vec<WolvesResult> = vec![];
|
let result: Vec<WolvesResult> = vec![];
|
||||||
|
|
||||||
for user in result {
|
for user in result {
|
||||||
add_users_wolves(&db, &server, &user).await;
|
add_users_wolves(db, &server, &user).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn add_users_wolves(db: &Pool<Sqlite>, server: &GuildId, user: &WolvesResult) {
|
async fn add_users_wolves(db: &Pool<Sqlite>, server: &GuildId, user: &WolvesResult) {
|
||||||
match sqlx::query_as::<_, Accounts>(
|
match sqlx::query_as::<_, Accounts>(
|
||||||
"
|
"
|
||||||
INSERT OR REPLACE INTO accounts (server, wolves_id, email, expiry)
|
INSERT OR REPLACE INTO accounts (server, wolves_id, email, expiry)
|
||||||
VALUES (?1, ?2, ?3, ?4)
|
VALUES (?1, ?2, ?3, ?4)
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(*server.as_u64() as i64)
|
.bind(*server.as_u64() as i64)
|
||||||
.bind(&user.id_wolves)
|
.bind(&user.id_wolves)
|
||||||
.bind(&user.email)
|
.bind(&user.email)
|
||||||
.bind(&user.expiry)
|
.bind(&user.expiry)
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
Loading…
Reference in a new issue