feat: will check if a person needs a committee role on teh committee server
This commit is contained in:
parent
8645a9b3ce
commit
348020ecfe
1 changed files with 38 additions and 2 deletions
|
@ -280,11 +280,12 @@ pub mod link {
|
||||||
|
|
||||||
pub mod verify {
|
pub mod verify {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::commands::link_email::link::{db_pending_clear_expired, get_verify_from_db};
|
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};
|
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption, GuildId, RoleId};
|
||||||
use serenity::model::user::User;
|
use serenity::model::user::User;
|
||||||
use skynet_discord_bot::common::database::get_server_config;
|
use skynet_discord_bot::common::database::get_server_config;
|
||||||
use skynet_discord_bot::common::database::{ServerMembersWolves, Servers};
|
use skynet_discord_bot::common::database::{ServerMembersWolves, Servers};
|
||||||
|
use skynet_discord_bot::common::wolves::committees::Committees;
|
||||||
use sqlx::Error;
|
use sqlx::Error;
|
||||||
|
|
||||||
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
|
||||||
|
@ -323,6 +324,10 @@ pub mod verify {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// get teh right roles for the user
|
// get teh right roles for the user
|
||||||
set_server_roles(&db, &command.user, ctx).await;
|
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()
|
"Discord username linked to Wolves".to_string()
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -402,6 +407,37 @@ pub mod verify {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_committees_id(db: &Pool<Sqlite>, wolves_id: i64) -> Vec<Committees> {
|
||||||
|
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<Sqlite>, 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<Sqlite>, discord: &UserId) -> Result<Vec<ServerMembersWolves>, Error> {
|
async fn get_servers(db: &Pool<Sqlite>, discord: &UserId) -> Result<Vec<ServerMembersWolves>, Error> {
|
||||||
sqlx::query_as::<_, ServerMembersWolves>(
|
sqlx::query_as::<_, ServerMembersWolves>(
|
||||||
"
|
"
|
||||||
|
|
Loading…
Add table
Reference in a new issue