From a6eff75e397a34b6b0b904b3aba6b0324d7c36ef Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 16 Jun 2025 21:50:26 +0100 Subject: [PATCH] feat: use values from teh env file to dictate the servers --- src/commands/wolves.rs | 12 +++++++++--- src/common/server_icon.rs | 2 +- src/common/set_roles.rs | 18 ++++++------------ src/lib.rs | 10 ++++++---- src/main.rs | 20 +++++++++++--------- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/commands/wolves.rs b/src/commands/wolves.rs index 92c6ec0..d790f9f 100644 --- a/src/commands/wolves.rs +++ b/src/commands/wolves.rs @@ -282,7 +282,7 @@ pub mod link { pub mod verify { use super::*; use crate::commands::wolves::link::{db_pending_clear_expired, get_server_member_discord, get_verify_from_db}; - use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, GuildId, RoleId}; + use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction}; use serenity::model::user::User; use skynet_discord_bot::common::database::get_server_config; use skynet_discord_bot::common::database::{ServerMembersWolves, Servers}; @@ -429,12 +429,18 @@ pub mod verify { } async fn set_server_roles_committee(db: &Pool, discord: &User, ctx: &Context) { + let config_lock = { + let data_read = ctx.data.read().await; + data_read.get::().expect("Expected Config in TypeMap.").clone() + }; + let config = config_lock.read().await; + if let Some(x) = get_server_member_discord(db, &discord.id).await { // if they are a member of one or more committees, and in teh committee server then give the teh general committee role // they will get teh more specific vanity role later if !get_committees_id(db, x.id_wolves).await.is_empty() { - let server = GuildId::new(1220150752656363520); - let committee_member = RoleId::new(1226602779968274573); + let server = config.committee_server; + let committee_member = config.committee_role; if let Ok(member) = server.member(ctx, &discord.id).await { member.add_roles(&ctx, &[committee_member]).await.unwrap_or_default(); diff --git a/src/common/server_icon.rs b/src/common/server_icon.rs index 167a105..8fcbcee 100644 --- a/src/common/server_icon.rs +++ b/src/common/server_icon.rs @@ -114,7 +114,7 @@ pub mod update_icon { /// Update the server icon, pulling from open governance. pub async fn update_icon_main(ctx: &Context, db: &Pool, config_global: &Config, config_toml_local: &ConfigTomlLocal) { - let server = GuildId::new(689189992417067052); + let server = config_global.compsoc_server; // clone repo into local folder clone_repo(config_global, config_toml_local); diff --git a/src/common/set_roles.rs b/src/common/set_roles.rs index 0dc7cc5..4e24b1a 100644 --- a/src/common/set_roles.rs +++ b/src/common/set_roles.rs @@ -135,7 +135,7 @@ pub mod committee { use crate::common::wolves::committees::Committees; use crate::Config; use serde::{Deserialize, Serialize}; - use serenity::all::{EditRole, GuildId}; + use serenity::all::EditRole; use serenity::builder::CreateChannel; use serenity::client::Context; use serenity::model::channel::ChannelType; @@ -161,7 +161,7 @@ pub mod committee { }; let config_global = config_lock.read().await; - let server = GuildId::new(1220150752656363520); + let server = config_global.committee_server; // because to use it to update a single user we need to pre-get the members of teh server let mut members = server.members(&ctx, None, None).await.unwrap_or_default(); @@ -172,17 +172,11 @@ pub mod committee { /** This function can take a vec of members (or just one) and gives tehm the appropiate roles on teh committee server */ - pub async fn update_committees(db: &Pool, ctx: &Context, _config: &Config, members: &mut Vec) { - let server = GuildId::new(1220150752656363520); - let committee_member = RoleId::new(1226602779968274573); + pub async fn update_committees(db: &Pool, ctx: &Context, config: &Config, members: &mut Vec) { + let server = config.committee_server; + let committee_member = config.committee_role; let committees = get_committees(db).await; - let categories = [ - ChannelId::new(1226606560973815839), - // C&S Chats 2 - ChannelId::new(1341457244973305927), - // C&S Chats 3 - ChannelId::new(1341457509717639279), - ]; + let categories = config.committee_category.clone(); // information about the server let mut roles_db = HashMap::new(); diff --git a/src/lib.rs b/src/lib.rs index 8a7273d..abf8a2d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ pub struct Config { // discord server for committee pub committee_server: GuildId, pub committee_role: RoleId, - pub committee_category: ChannelId, + pub committee_category: Vec, // items pertaining to compsoc only pub compsoc_server: GuildId, @@ -60,7 +60,7 @@ pub fn get_config() -> Config { wolves_api: "".to_string(), committee_server: GuildId::new(1), committee_role: RoleId::new(1), - committee_category: ChannelId::new(1), + committee_category: vec![], compsoc_server: GuildId::new(1), }; @@ -109,8 +109,10 @@ pub fn get_config() -> Config { } } if let Ok(x) = env::var("COMMITTEE_CATEGORY") { - if let Ok(x) = x.trim().parse::() { - config.committee_category = ChannelId::new(x); + for part in x.split(",") { + if let Ok(x) = part.trim().parse::() { + config.committee_category.push(ChannelId::new(x)); + } } } diff --git a/src/main.rs b/src/main.rs index ebad7a0..9de027e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,7 @@ pub mod commands; use crate::commands::role_adder::tools::on_role_change; -use serenity::all::{ - ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildId, GuildMemberUpdateEvent, Interaction, -}; +use serenity::all::{ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildMemberUpdateEvent, Interaction}; use serenity::model::guild::Member; use serenity::{ async_trait, @@ -42,7 +40,7 @@ impl EventHandler for Handler { let config_global = config_lock.read().await; // committee server takes priority - let committee_server = GuildId::new(1220150752656363520); + let committee_server = config_global.committee_server; if new_member.guild_id.get() == committee_server.get() { let mut member = vec![new_member.clone()]; update_committees(&db, &ctx, &config_global, &mut member).await; @@ -113,6 +111,12 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use println!("[Main] {} is connected!", ready.user.name); ctx.set_presence(Some(ActivityData::playing("with humanity's fate")), OnlineStatus::Online); + let config_lock = { + let data_read = ctx.data.read().await; + data_read.get::().expect("Expected Config in TypeMap.").clone() + }; + let config = config_lock.read().await; + match Command::set_global_commands( &ctx.http, vec![ @@ -132,10 +136,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use } // Inter-Committee server - match GuildId::new(1220150752656363520) - .set_commands(&ctx.http, vec![commands::count::committee::register()]) - .await - { + match config.committee_server.set_commands(&ctx.http, vec![commands::count::committee::register()]).await { Ok(_) => {} Err(e) => { println!("{:?}", e) @@ -143,7 +144,8 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use } // compsoc Server - match GuildId::new(689189992417067052) + match config + .compsoc_server .set_commands( &ctx.http, vec![