feat: will properly re-order the channels created
Also focuses on anything in teh right category
This commit is contained in:
parent
c98baa9d72
commit
2f75dc41c8
1 changed files with 32 additions and 1 deletions
|
@ -183,7 +183,12 @@ 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() {
|
||||||
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
|
// 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();
|
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> {
|
||||||
|
|
Loading…
Reference in a new issue