feat: will properly re-order the channels created

Also focuses on anything in teh right category
This commit is contained in:
silver 2024-11-09 16:47:48 +00:00
parent c98baa9d72
commit 2f75dc41c8
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -183,8 +183,13 @@ pub mod committee {
let mut channels_name = HashMap::new(); let mut channels_name = HashMap::new();
for channel in channels.values() { for channel in channels.values() {
// we only care about teh channels in teh category
if let Some(x) = channel.parent_id {
if x.eq(&config.committee_category) {
channels_name.insert(channel.name.to_owned(), channel.to_owned()); channels_name.insert(channel.name.to_owned(), channel.to_owned());
} }
}
}
// a map of users and the roles they are goign to be getting // a map of users and the roles they are goign to be getting
let mut users_roles = HashMap::new(); let mut users_roles = HashMap::new();
@ -269,6 +274,32 @@ pub mod committee {
member.add_roles(&ctx, &roles_required).await.unwrap_or_default(); member.add_roles(&ctx, &roles_required).await.unwrap_or_default();
} }
} }
// finally re-order teh channels to make them visually apealing
let mut channel_names = channels_name.clone().into_keys().collect::<Vec<String>>();
channel_names.sort();
// get a list of all teh new positions
let mut new_positions = vec![];
for (i, name) in channel_names.iter().enumerate() {
if let Some(channel) = channels_name.get_mut(name) {
let position_new = i as u64;
if position_new != channel.position as u64 {
new_positions.push((channel.id.to_owned(), position_new));
}
}
}
if !new_positions.is_empty() {
match server.reorder_channels(&ctx, new_positions).await {
Ok(_) => {
println!("Successfully re-orderd the committee category");
}
Err(e) => {
dbg!("Failed to re-order ", e);
}
}
}
} }
async fn get_committees(db: &Pool<Sqlite>) -> Vec<Committees> { async fn get_committees(db: &Pool<Sqlite>) -> Vec<Committees> {