feat: now properly sets and removes roles for committee members
This commit is contained in:
parent
4eeb7f2135
commit
1aef86ad01
9 changed files with 137 additions and 89 deletions
|
@ -87,15 +87,22 @@ pub mod cns {
|
|||
server,
|
||||
// this is the unique api key for each club/soc
|
||||
wolves_api,
|
||||
server_name,
|
||||
..
|
||||
} = &server_config;
|
||||
// dbg!(&server_config);
|
||||
|
||||
let existing_tmp = get_server_member(&db, server).await;
|
||||
let existing = existing_tmp.iter().map(|data| (data.id_wolves, data)).collect::<BTreeMap<_, _>>();
|
||||
|
||||
// list of users that need to be updated for this server
|
||||
let mut user_to_update = vec![];
|
||||
let mut server_name_tmp = None;
|
||||
for user in wolves.get_members(wolves_api).await {
|
||||
// dbg!(&user.committee);
|
||||
if server_name_tmp.is_none() {
|
||||
server_name_tmp = Some(user.committee.to_owned());
|
||||
}
|
||||
let id = user.member_id.parse::<u64>().unwrap_or_default();
|
||||
match existing.get(&(id as i64)) {
|
||||
None => {
|
||||
|
@ -117,12 +124,38 @@ pub mod cns {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(name) = server_name_tmp {
|
||||
if &name != server_name {
|
||||
set_server_member(&db, server, &name).await;
|
||||
}
|
||||
}
|
||||
if !user_to_update.is_empty() {
|
||||
update_server(ctx, &server_config, &[], &user_to_update).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn set_server_member(db: &Pool<Sqlite>, server: &GuildId, name: &str) {
|
||||
match sqlx::query_as::<_, Servers>(
|
||||
"
|
||||
UPDATE servers
|
||||
SET server_name = ?
|
||||
WHERE server = ?
|
||||
",
|
||||
)
|
||||
.bind(name)
|
||||
.bind(*server.as_u64() as i64)
|
||||
.fetch_optional(db)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("Failure to set server name {}", server.as_u64());
|
||||
println!("{:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_server_member(db: &Pool<Sqlite>, server: &GuildId) -> Vec<ServerMembersWolves> {
|
||||
sqlx::query_as::<_, ServerMembersWolves>(
|
||||
r#"
|
||||
|
@ -223,7 +256,7 @@ pub mod committees {
|
|||
"
|
||||
INSERT INTO committees (id, name_profile, name_full, name_plain, link, committee)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT(id) DO UPDATE SET committee = $4
|
||||
ON CONFLICT(id) DO UPDATE SET committee = $6
|
||||
",
|
||||
)
|
||||
.bind(committee.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue