fmt: re-organise the regular data request

This commit is contained in:
silver 2024-10-28 01:29:01 +00:00
parent 3927734083
commit 273c58d035
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
3 changed files with 12 additions and 9 deletions

View file

@ -8,7 +8,7 @@ use skynet_discord_bot::{get_config, Config};
use std::{process, sync::Arc}; use std::{process, sync::Arc};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use skynet_discord_bot::common::database::{db_init, DataBase}; use skynet_discord_bot::common::database::{db_init, DataBase};
use skynet_discord_bot::common::wolves::get_data::get_wolves_cns; use skynet_discord_bot::common::wolves::cns::get_wolves;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
@ -46,7 +46,7 @@ impl EventHandler for Handler {
println!("{} is connected!", ready.user.name); println!("{} is connected!", ready.user.name);
// get the data for each individual club/soc // get the data for each individual club/soc
get_wolves_cns(&ctx).await; get_wolves(&ctx).await;
// finish up // finish up
process::exit(0); process::exit(0);

View file

@ -6,7 +6,7 @@ use serenity::{
prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue}, prelude::{command::CommandOptionType, interaction::application_command::CommandDataOptionValue},
}, },
}; };
use skynet_discord_bot::common::wolves::get_data::get_wolves_cns; use skynet_discord_bot::common::wolves::cns::get_wolves;
use skynet_discord_bot::{is_admin, set_roles::update_server}; use skynet_discord_bot::{is_admin, set_roles::update_server};
use sqlx::{Error, Pool, Sqlite}; use sqlx::{Error, Pool, Sqlite};
use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers}; use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers};
@ -216,7 +216,7 @@ async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Resul
// update all users // update all users
if update { if update {
// handle wolves api here // handle wolves api here
get_wolves_cns(ctx).await; get_wolves(ctx).await;
let mut roles_remove = vec![]; let mut roles_remove = vec![];
if current_remove { if current_remove {

View file

@ -11,7 +11,10 @@
// pub members: Vec<i64>, // pub members: Vec<i64>,
// } // }
pub mod get_data { /**
This is getting data for Clubs and Socs
*/
pub mod cns {
use crate::set_roles::update_server; use crate::set_roles::update_server;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -50,7 +53,7 @@ pub mod get_data {
pub email: String, pub email: String,
pub expiry: String, pub expiry: String,
} }
pub async fn get_wolves_cns(ctx: &Context) { pub async fn get_wolves(ctx: &Context) {
let db_lock = { let db_lock = {
let data_read = ctx.data.read().await; let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone() data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
@ -75,7 +78,7 @@ pub mod get_data {
// list of users that need to be updated for this server // list of users that need to be updated for this server
let mut user_to_update = vec![]; let mut user_to_update = vec![];
for user in get_wolves_cns_sub(&config, wolves_api).await { for user in get_wolves_sub(&config, wolves_api).await {
let id = user.member_id.parse::<u64>().unwrap_or_default(); let id = user.member_id.parse::<u64>().unwrap_or_default();
match existing.get(&(id as i64)) { match existing.get(&(id as i64)) {
None => { None => {
@ -103,7 +106,7 @@ pub mod get_data {
} }
} }
pub async fn get_server_member(db: &Pool<Sqlite>, server: &GuildId) -> Vec<ServerMembersWolves> { async fn get_server_member(db: &Pool<Sqlite>, server: &GuildId) -> Vec<ServerMembersWolves> {
sqlx::query_as::<_, ServerMembersWolves>( sqlx::query_as::<_, ServerMembersWolves>(
r#" r#"
SELECT * SELECT *
@ -121,7 +124,7 @@ pub mod get_data {
.unwrap_or_default() .unwrap_or_default()
} }
async fn get_wolves_cns_sub(config: &Config, wolves_api: &str) -> Vec<WolvesResultUser> { async fn get_wolves_sub(config: &Config, wolves_api: &str) -> Vec<WolvesResultUser> {
if config.wolves_url.is_empty() { if config.wolves_url.is_empty() {
return vec![]; return vec![];
} }