fmt: formatting and clippy
This commit is contained in:
parent
b7161e2614
commit
344d6d3585
14 changed files with 130 additions and 138 deletions
|
@ -1,12 +1,10 @@
|
|||
use crate::common::database::Wolves;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use crate::common::database::Wolves;
|
||||
|
||||
/**
|
||||
This file relates to anything that directly interacts with teh wolves API
|
||||
*/
|
||||
|
||||
|
||||
This file relates to anything that directly interacts with teh wolves API
|
||||
*/
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
struct WolvesResultUserMin {
|
||||
|
@ -33,10 +31,10 @@ async fn add_users_wolves(db: &Pool<Sqlite>, user: &WolvesResultUserMin) {
|
|||
ON CONFLICT(id_wolves) DO UPDATE SET email = $2
|
||||
",
|
||||
)
|
||||
.bind(&user.member_id)
|
||||
.bind(&user.contact_email)
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
.bind(&user.member_id)
|
||||
.bind(&user.contact_email)
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
|
@ -46,20 +44,19 @@ async fn add_users_wolves(db: &Pool<Sqlite>, user: &WolvesResultUserMin) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This is getting data for Clubs and Socs
|
||||
*/
|
||||
pub mod cns {
|
||||
use crate::common::database::{get_server_config_bulk, DataBase, ServerMembers, ServerMembersWolves, Servers};
|
||||
use crate::common::set_roles::normal::update_server;
|
||||
use std::collections::BTreeMap;
|
||||
use crate::common::wolves::{add_users_wolves, WolvesResultUserMin};
|
||||
use crate::Config;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serenity::client::Context;
|
||||
use serenity::model::id::GuildId;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use crate::Config;
|
||||
use crate::common::database::{get_server_config_bulk, DataBase, ServerMembers, ServerMembersWolves, Servers, Wolves};
|
||||
use crate::common::wolves::{add_users_wolves, WolvesResultUserMin};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
struct WolvesResultUser {
|
||||
|
@ -222,11 +219,11 @@ pub mod cns {
|
|||
Get and store the data on C&S committees
|
||||
*/
|
||||
pub mod committees {
|
||||
use crate::common::database::DataBase;
|
||||
use crate::Config;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serenity::client::Context;
|
||||
use sqlx::{ Pool, Sqlite};
|
||||
use crate::common::database::{DataBase};
|
||||
use crate::Config;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
// This is what Wolves returns to us
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
|
@ -243,22 +240,22 @@ pub mod committees {
|
|||
// Link to their page such as https://ulwolves.ie/society/computer
|
||||
link: String,
|
||||
// array of Committee members member_id's
|
||||
committee: Vec<String>
|
||||
committee: Vec<String>,
|
||||
}
|
||||
|
||||
// Database entry for it
|
||||
#[derive(Debug, Clone, sqlx::FromRow)]
|
||||
pub struct Committees {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub link: String,
|
||||
#[sqlx(json)]
|
||||
pub committee: Vec<i64>,
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub link: String,
|
||||
#[sqlx(json)]
|
||||
pub committee: Vec<i64>,
|
||||
}
|
||||
|
||||
impl From<WolvesResultCNS> for Committees {
|
||||
fn from(value: WolvesResultCNS) -> Self {
|
||||
Self{
|
||||
Self {
|
||||
id: value.id.parse().unwrap_or(0),
|
||||
name: value.name,
|
||||
link: value.link,
|
||||
|
@ -267,7 +264,7 @@ pub mod committees {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn get_cns(ctx: &Context){
|
||||
pub async fn get_cns(ctx: &Context) {
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||
|
@ -283,7 +280,7 @@ pub mod committees {
|
|||
// TODO: proper api key management
|
||||
let api_key = "";
|
||||
// request data from wolves
|
||||
for committee in get_committees(&config, api_key).await {
|
||||
for committee in get_committees(&config, api_key).await {
|
||||
let tmp = Committees::from(committee);
|
||||
add_committee(&db, &tmp).await;
|
||||
}
|
||||
|
@ -299,7 +296,11 @@ pub mod committees {
|
|||
|
||||
// get wolves data
|
||||
if let Ok(mut res) = surf::post(&url).header("X-AM-Identity", wolves_api).await {
|
||||
if let Ok(WolvesResult { success, result, }) = res.body_json().await {
|
||||
if let Ok(WolvesResult {
|
||||
success,
|
||||
result,
|
||||
}) = res.body_json().await
|
||||
{
|
||||
if success != 1 {
|
||||
return vec![];
|
||||
}
|
||||
|
@ -319,12 +320,12 @@ pub mod committees {
|
|||
ON CONFLICT(id) DO UPDATE SET committee = $4
|
||||
",
|
||||
)
|
||||
.bind(committee.id)
|
||||
.bind(&committee.name)
|
||||
.bind(&committee.link)
|
||||
.bind(serde_json::to_string(&committee.committee).unwrap_or_default())
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
.bind(committee.id)
|
||||
.bind(&committee.name)
|
||||
.bind(&committee.link)
|
||||
.bind(serde_json::to_string(&committee.committee).unwrap_or_default())
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
|
@ -339,12 +340,11 @@ pub mod committees {
|
|||
get the data for an individual user
|
||||
*/
|
||||
pub mod individual {
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serenity::client::Context;
|
||||
use crate::common::database::DataBase;
|
||||
use crate::common::wolves::{add_users_wolves, WolvesResultUserMin};
|
||||
use crate::Config;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serenity::client::Context;
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
struct WolvesResultUser {
|
||||
|
@ -378,8 +378,7 @@ pub mod individual {
|
|||
result: WolvesResultUser,
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_user(ctx: &Context, email: &str) -> bool{
|
||||
pub async fn get_user(ctx: &Context, email: &str) -> bool {
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||
|
@ -396,9 +395,7 @@ pub mod individual {
|
|||
let api_key = "";
|
||||
// request data from wolves
|
||||
match get_user_sub(&config, api_key, email).await {
|
||||
None => {
|
||||
false
|
||||
}
|
||||
None => false,
|
||||
// if exists save it and return true
|
||||
Some(user) => {
|
||||
// add to db
|
||||
|
@ -409,7 +406,7 @@ pub mod individual {
|
|||
}
|
||||
}
|
||||
|
||||
async fn get_user_sub(config: &Config, wolves_api: &str, email: &str) -> Option<WolvesResultUser> {
|
||||
async fn get_user_sub(config: &Config, wolves_api: &str, _email: &str) -> Option<WolvesResultUser> {
|
||||
if config.wolves_url.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
@ -419,7 +416,11 @@ pub mod individual {
|
|||
|
||||
// get wolves data
|
||||
if let Ok(mut res) = surf::post(&url).header("X-AM-Identity", wolves_api).await {
|
||||
if let Ok(WolvesResult { success, result, }) = res.body_json().await {
|
||||
if let Ok(WolvesResult {
|
||||
success,
|
||||
result,
|
||||
}) = res.body_json().await
|
||||
{
|
||||
if success != 1 {
|
||||
return None;
|
||||
}
|
||||
|
@ -430,4 +431,4 @@ pub mod individual {
|
|||
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue