From 348020ecfee0963ef97458db25d16f5ddf1653a9 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Wed, 19 Feb 2025 22:36:39 +0000 Subject: [PATCH] feat: will check if a person needs a committee role on teh committee server --- src/commands/link_email.rs | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/commands/link_email.rs b/src/commands/link_email.rs index 750e0ee..35a29cc 100644 --- a/src/commands/link_email.rs +++ b/src/commands/link_email.rs @@ -280,11 +280,12 @@ pub mod link { pub mod verify { use super::*; - use crate::commands::link_email::link::{db_pending_clear_expired, get_verify_from_db}; - use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption}; + use crate::commands::link_email::link::{db_pending_clear_expired, get_server_member_discord, get_verify_from_db}; + use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption, GuildId, RoleId}; use serenity::model::user::User; use skynet_discord_bot::common::database::get_server_config; use skynet_discord_bot::common::database::{ServerMembersWolves, Servers}; + use skynet_discord_bot::common::wolves::committees::Committees; use sqlx::Error; pub async fn run(command: &CommandInteraction, ctx: &Context) -> String { @@ -323,6 +324,10 @@ pub mod verify { Ok(_) => { // get teh right roles for the user set_server_roles(&db, &command.user, ctx).await; + + // check if they are a committee member, and on that server + set_server_roles_committee(&db, &command.user, ctx).await; + "Discord username linked to Wolves".to_string() } Err(e) => { @@ -402,6 +407,37 @@ pub mod verify { } } + async fn get_committees_id(db: &Pool, wolves_id: i64) -> Vec { + sqlx::query_as::<_, Committees>( + r#" + SELECT * + committee like '%?1%' + "#, + ) + .bind(wolves_id) + .fetch_all(db) + .await + .unwrap_or_else(|e| { + dbg!(e); + vec![] + }) + } + + async fn set_server_roles_committee(db: &Pool, discord: &User, ctx: &Context) { + 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); + + if let Ok(member) = server.member(ctx, &discord.id).await { + member.add_roles(&ctx, &[committee_member]).await.unwrap_or_default(); + } + } + } + } + async fn get_servers(db: &Pool, discord: &UserId) -> Result, Error> { sqlx::query_as::<_, ServerMembersWolves>( "