Compare commits
No commits in common. "2f75dc41c87d12bb04cde777b533bd6887302f5d" and "5b22f699d687fd41880c91a10938123fafccf85a" have entirely different histories.
2f75dc41c8
...
5b22f699d6
2 changed files with 1 additions and 64 deletions
|
@ -135,7 +135,6 @@ 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;
|
||||
|
@ -173,7 +172,6 @@ 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();
|
||||
|
@ -181,16 +179,6 @@ pub mod committee {
|
|||
roles_name.insert(role.name.to_owned(), role.to_owned());
|
||||
}
|
||||
|
||||
let mut channels_name = HashMap::new();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// a map of users and the roles they are goign to be getting
|
||||
let mut users_roles = HashMap::new();
|
||||
|
||||
|
@ -210,24 +198,6 @@ 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);
|
||||
|
@ -274,32 +244,6 @@ 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::<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> {
|
||||
|
|
|
@ -4,7 +4,7 @@ use chrono::{Datelike, SecondsFormat, Utc};
|
|||
use dotenvy::dotenv;
|
||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||
use serenity::client::Context;
|
||||
use serenity::model::id::{ChannelId, GuildId, RoleId};
|
||||
use serenity::model::id::{GuildId, RoleId};
|
||||
use serenity::model::prelude::application_command::ApplicationCommandInteraction;
|
||||
use serenity::prelude::TypeMapKey;
|
||||
use std::{env, sync::Arc};
|
||||
|
@ -31,7 +31,6 @@ pub struct Config {
|
|||
// discord server for committee
|
||||
pub committee_server: GuildId,
|
||||
pub committee_role: RoleId,
|
||||
pub committee_category: ChannelId,
|
||||
}
|
||||
impl TypeMapKey for Config {
|
||||
type Value = Arc<RwLock<Config>>;
|
||||
|
@ -55,7 +54,6 @@ pub fn get_config() -> Config {
|
|||
wolves_api: "".to_string(),
|
||||
committee_server: GuildId(0),
|
||||
committee_role: RoleId(0),
|
||||
committee_category: ChannelId(0),
|
||||
};
|
||||
|
||||
if let Ok(x) = env::var("DATABASE_HOME") {
|
||||
|
@ -100,11 +98,6 @@ pub fn get_config() -> Config {
|
|||
config.committee_role = RoleId(x);
|
||||
}
|
||||
}
|
||||
if let Ok(x) = env::var("COMMITTEE_CATEGORY") {
|
||||
if let Ok(x) = x.trim().parse::<u64>() {
|
||||
config.committee_category = ChannelId(x);
|
||||
}
|
||||
}
|
||||
|
||||
config
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue