Fixes a very nasty Send+Async bug

This commit is contained in:
Dandaedre 2025-01-21 18:32:30 +01:00
parent c80c89afc4
commit 829fe876fd
1 changed files with 33 additions and 30 deletions

View File

@ -29,6 +29,7 @@ use crate::votes::EventHolder;
use distance::levenshtein;
use log::debug;
use poise::serenity_prelude as serenity;
use poise::serenity_prelude::RoleId;
use poise::Modal as _;
use crate::error_handling::IdleError;
@ -433,44 +434,46 @@ async fn add_many(
) -> Result<(), GenericError> {
debug!("{}", roles);
// let guild = ctx.guild().unwrap();
let fetched_list_of_server_roles = &ctx.guild().unwrap().roles;
// println!("{:?}", list_of_server_roles);
let list_of_roles = fetched_list_of_server_roles
.iter()
.map(|(roleid, role)| (roleid, role.name.as_str()))
.collect();
// println!("{:?}", list_of_roles);
let mut roles_found = HashSet::new();
let mut roles_not_found = HashSet::new();
for r in roles.split(",") {
if let Some(role) = find_roleid_from_str(Some(r), &list_of_roles) {
roles_found.insert(role);
} else {
roles_not_found.insert(r.to_string());
};
}
let (roles_found, roles_not_found) = {
let fetched_list_of_server_roles = &ctx.guild().unwrap().roles;
// println!("{:?}", list_of_server_roles);
let list_of_roles = fetched_list_of_server_roles
.iter()
.map(|(roleid, role)| (roleid, role.name.as_str()))
.collect();
// println!("{:?}", list_of_roles);
let mut roles_found = HashSet::new();
let mut roles_not_found = HashSet::new();
for r in roles.split(",") {
if let Some(role) = find_roleid_from_str(Some(r), &list_of_roles) {
roles_found.insert(role);
} else {
roles_not_found.insert(r.to_string());
};
}
(roles_found, roles_not_found)
};
// TODO: import banlist from config
// TODO: move this role prunning to before levenstein (find_role_from_str)
println!("Roles found : {:?}", roles_found);
println!("Roles not found : {:?}", roles_not_found);
todo!();
//TODO: Make this work
// for r in roles_found {
// ctx.http()
// .add_member_role(
// ctx.guild_id().unwrap(),
// ctx.author().id,
// r,
// Some("User requested."),
// )
// .await?;
// }
// todo!();
// TODO: Make this work
for r in roles_found {
ctx.http()
.add_member_role(
ctx.guild_id().unwrap(),
ctx.author().id,
r,
Some("User requested."),
)
.await?;
}
// Ok(())
Ok(())
}
/// Remove one role from the list of all server roles.