From 2f75dc41c87d12bb04cde777b533bd6887302f5d Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sat, 9 Nov 2024 16:47:48 +0000 Subject: [PATCH] feat: will properly re-order the channels created Also focuses on anything in teh right category --- src/common/set_roles.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/common/set_roles.rs b/src/common/set_roles.rs index ced3ad5..9b26117 100644 --- a/src/common/set_roles.rs +++ b/src/common/set_roles.rs @@ -183,7 +183,12 @@ pub mod committee { let mut channels_name = HashMap::new(); for channel in channels.values() { - channels_name.insert(channel.name.to_owned(), channel.to_owned()); + // 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()); + } + } } // a map of users and the roles they are goign to be getting @@ -269,6 +274,32 @@ pub mod committee { 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::>(); + 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) -> Vec {