feat: will now create a channel for any new club/soc

This commit is contained in:
silver 2024-11-09 16:23:03 +00:00
parent e4a8cce725
commit c98baa9d72
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -135,6 +135,7 @@ pub mod committee {
use crate::common::wolves::committees::Committees; use crate::common::wolves::committees::Committees;
use crate::Config; use crate::Config;
use serenity::client::Context; use serenity::client::Context;
use serenity::model::channel::ChannelType;
use serenity::model::guild::Member; use serenity::model::guild::Member;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
use std::collections::HashMap; use std::collections::HashMap;
@ -172,6 +173,7 @@ pub mod committee {
// information about the server // information about the server
let roles = server.roles(&ctx).await.unwrap_or_default(); 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 // make a hashmap of the nameof roles to quickly get them out again
let mut roles_name = HashMap::new(); let mut roles_name = HashMap::new();
@ -179,6 +181,11 @@ pub mod committee {
roles_name.insert(role.name.to_owned(), role.to_owned()); 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 // 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();
@ -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 // so if the role exists
if let Some(r) = role { if let Some(r) = role {
committee_roles.push(r.id); committee_roles.push(r.id);