From 273c58d035bbbf1669d30547565c17caf721dae1 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 28 Oct 2024 01:29:01 +0000 Subject: [PATCH] fmt: re-organise the regular data request --- src/bin/update_data.rs | 4 ++-- src/commands/add_server.rs | 4 ++-- src/common/wolves.rs | 13 ++++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/bin/update_data.rs b/src/bin/update_data.rs index e4b662d..310b97a 100644 --- a/src/bin/update_data.rs +++ b/src/bin/update_data.rs @@ -8,7 +8,7 @@ use skynet_discord_bot::{get_config, Config}; use std::{process, sync::Arc}; use tokio::sync::RwLock; 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] async fn main() { @@ -46,7 +46,7 @@ impl EventHandler for Handler { println!("{} is connected!", ready.user.name); // get the data for each individual club/soc - get_wolves_cns(&ctx).await; + get_wolves(&ctx).await; // finish up process::exit(0); diff --git a/src/commands/add_server.rs b/src/commands/add_server.rs index dace04e..1886e56 100644 --- a/src/commands/add_server.rs +++ b/src/commands/add_server.rs @@ -6,7 +6,7 @@ use serenity::{ 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 sqlx::{Error, Pool, Sqlite}; use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers}; @@ -216,7 +216,7 @@ async fn add_server(db: &Pool, ctx: &Context, server: &Servers) -> Resul // update all users if update { // handle wolves api here - get_wolves_cns(ctx).await; + get_wolves(ctx).await; let mut roles_remove = vec![]; if current_remove { diff --git a/src/common/wolves.rs b/src/common/wolves.rs index 99e7818..71f30c0 100644 --- a/src/common/wolves.rs +++ b/src/common/wolves.rs @@ -11,7 +11,10 @@ // pub members: Vec, // } -pub mod get_data { +/** + This is getting data for Clubs and Socs +*/ +pub mod cns { use crate::set_roles::update_server; use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; @@ -50,7 +53,7 @@ pub mod get_data { pub email: String, pub expiry: String, } - pub async fn get_wolves_cns(ctx: &Context) { + pub async fn get_wolves(ctx: &Context) { let db_lock = { let data_read = ctx.data.read().await; data_read.get::().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 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::().unwrap_or_default(); match existing.get(&(id as i64)) { None => { @@ -103,7 +106,7 @@ pub mod get_data { } } - pub async fn get_server_member(db: &Pool, server: &GuildId) -> Vec { + async fn get_server_member(db: &Pool, server: &GuildId) -> Vec { sqlx::query_as::<_, ServerMembersWolves>( r#" SELECT * @@ -121,7 +124,7 @@ pub mod get_data { .unwrap_or_default() } - async fn get_wolves_cns_sub(config: &Config, wolves_api: &str) -> Vec { + async fn get_wolves_sub(config: &Config, wolves_api: &str) -> Vec { if config.wolves_url.is_empty() { return vec![]; }