feat: will now create a channel for any new club/soc
This commit is contained in:
parent
e4a8cce725
commit
c98baa9d72
1 changed files with 25 additions and 0 deletions
|
@ -135,6 +135,7 @@ pub mod committee {
|
|||
use crate::common::wolves::committees::Committees;
|
||||
use crate::Config;
|
||||
use serenity::client::Context;
|
||||
use serenity::model::channel::ChannelType;
|
||||
use serenity::model::guild::Member;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use std::collections::HashMap;
|
||||
|
@ -172,6 +173,7 @@ pub mod committee {
|
|||
|
||||
// information about the server
|
||||
let roles = server.roles(&ctx).await.unwrap_or_default();
|
||||
let channels = server.channels(&ctx).await.unwrap_or_default();
|
||||
|
||||
// make a hashmap of the nameof roles to quickly get them out again
|
||||
let mut roles_name = HashMap::new();
|
||||
|
@ -179,6 +181,11 @@ pub mod committee {
|
|||
roles_name.insert(role.name.to_owned(), role.to_owned());
|
||||
}
|
||||
|
||||
let mut channels_name = HashMap::new();
|
||||
for channel in channels.values() {
|
||||
channels_name.insert(channel.name.to_owned(), channel.to_owned());
|
||||
}
|
||||
|
||||
// a map of users and the roles they are goign to be getting
|
||||
let mut users_roles = HashMap::new();
|
||||
|
||||
|
@ -198,6 +205,24 @@ pub mod committee {
|
|||
}
|
||||
};
|
||||
|
||||
// create teh channel if it does nto exist
|
||||
if !channels_name.contains_key(&committee.name) {
|
||||
match server
|
||||
.create_channel(&ctx, |c| c.name(&committee.name).kind(ChannelType::Text).category(config.committee_category))
|
||||
.await
|
||||
{
|
||||
Ok(x) => {
|
||||
// update teh channels name list
|
||||
channels_name.insert(x.name.to_owned(), x.to_owned());
|
||||
|
||||
println!("Created channel: {}", &committee.name);
|
||||
}
|
||||
Err(x) => {
|
||||
dbg!("Unable to create channel: ", x);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// so if the role exists
|
||||
if let Some(r) = role {
|
||||
committee_roles.push(r.id);
|
||||
|
|
Loading…
Reference in a new issue