feat: use values from teh env file to dictate the servers
This commit is contained in:
parent
72226cc59b
commit
a6eff75e39
5 changed files with 33 additions and 29 deletions
|
@ -282,7 +282,7 @@ pub mod link {
|
|||
pub mod verify {
|
||||
use super::*;
|
||||
use crate::commands::wolves::link::{db_pending_clear_expired, get_server_member_discord, get_verify_from_db};
|
||||
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, GuildId, RoleId};
|
||||
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction};
|
||||
use serenity::model::user::User;
|
||||
use skynet_discord_bot::common::database::get_server_config;
|
||||
use skynet_discord_bot::common::database::{ServerMembersWolves, Servers};
|
||||
|
@ -429,12 +429,18 @@ pub mod verify {
|
|||
}
|
||||
|
||||
async fn set_server_roles_committee(db: &Pool<Sqlite>, discord: &User, ctx: &Context) {
|
||||
let config_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
|
||||
};
|
||||
let config = config_lock.read().await;
|
||||
|
||||
if let Some(x) = get_server_member_discord(db, &discord.id).await {
|
||||
// if they are a member of one or more committees, and in teh committee server then give the teh general committee role
|
||||
// they will get teh more specific vanity role later
|
||||
if !get_committees_id(db, x.id_wolves).await.is_empty() {
|
||||
let server = GuildId::new(1220150752656363520);
|
||||
let committee_member = RoleId::new(1226602779968274573);
|
||||
let server = config.committee_server;
|
||||
let committee_member = config.committee_role;
|
||||
|
||||
if let Ok(member) = server.member(ctx, &discord.id).await {
|
||||
member.add_roles(&ctx, &[committee_member]).await.unwrap_or_default();
|
||||
|
|
|
@ -114,7 +114,7 @@ pub mod update_icon {
|
|||
|
||||
/// Update the server icon, pulling from open governance.
|
||||
pub async fn update_icon_main(ctx: &Context, db: &Pool<Sqlite>, config_global: &Config, config_toml_local: &ConfigTomlLocal) {
|
||||
let server = GuildId::new(689189992417067052);
|
||||
let server = config_global.compsoc_server;
|
||||
|
||||
// clone repo into local folder
|
||||
clone_repo(config_global, config_toml_local);
|
||||
|
|
|
@ -135,7 +135,7 @@ pub mod committee {
|
|||
use crate::common::wolves::committees::Committees;
|
||||
use crate::Config;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serenity::all::{EditRole, GuildId};
|
||||
use serenity::all::EditRole;
|
||||
use serenity::builder::CreateChannel;
|
||||
use serenity::client::Context;
|
||||
use serenity::model::channel::ChannelType;
|
||||
|
@ -161,7 +161,7 @@ pub mod committee {
|
|||
};
|
||||
let config_global = config_lock.read().await;
|
||||
|
||||
let server = GuildId::new(1220150752656363520);
|
||||
let server = config_global.committee_server;
|
||||
|
||||
// because to use it to update a single user we need to pre-get the members of teh server
|
||||
let mut members = server.members(&ctx, None, None).await.unwrap_or_default();
|
||||
|
@ -172,17 +172,11 @@ pub mod committee {
|
|||
/**
|
||||
This function can take a vec of members (or just one) and gives tehm the appropiate roles on teh committee server
|
||||
*/
|
||||
pub async fn update_committees(db: &Pool<Sqlite>, ctx: &Context, _config: &Config, members: &mut Vec<Member>) {
|
||||
let server = GuildId::new(1220150752656363520);
|
||||
let committee_member = RoleId::new(1226602779968274573);
|
||||
pub async fn update_committees(db: &Pool<Sqlite>, ctx: &Context, config: &Config, members: &mut Vec<Member>) {
|
||||
let server = config.committee_server;
|
||||
let committee_member = config.committee_role;
|
||||
let committees = get_committees(db).await;
|
||||
let categories = [
|
||||
ChannelId::new(1226606560973815839),
|
||||
// C&S Chats 2
|
||||
ChannelId::new(1341457244973305927),
|
||||
// C&S Chats 3
|
||||
ChannelId::new(1341457509717639279),
|
||||
];
|
||||
let categories = config.committee_category.clone();
|
||||
|
||||
// information about the server
|
||||
let mut roles_db = HashMap::new();
|
||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -32,7 +32,7 @@ pub struct Config {
|
|||
// discord server for committee
|
||||
pub committee_server: GuildId,
|
||||
pub committee_role: RoleId,
|
||||
pub committee_category: ChannelId,
|
||||
pub committee_category: Vec<ChannelId>,
|
||||
|
||||
// items pertaining to compsoc only
|
||||
pub compsoc_server: GuildId,
|
||||
|
@ -60,7 +60,7 @@ pub fn get_config() -> Config {
|
|||
wolves_api: "".to_string(),
|
||||
committee_server: GuildId::new(1),
|
||||
committee_role: RoleId::new(1),
|
||||
committee_category: ChannelId::new(1),
|
||||
committee_category: vec![],
|
||||
compsoc_server: GuildId::new(1),
|
||||
};
|
||||
|
||||
|
@ -109,8 +109,10 @@ pub fn get_config() -> Config {
|
|||
}
|
||||
}
|
||||
if let Ok(x) = env::var("COMMITTEE_CATEGORY") {
|
||||
if let Ok(x) = x.trim().parse::<u64>() {
|
||||
config.committee_category = ChannelId::new(x);
|
||||
for part in x.split(",") {
|
||||
if let Ok(x) = part.trim().parse::<u64>() {
|
||||
config.committee_category.push(ChannelId::new(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -1,9 +1,7 @@
|
|||
pub mod commands;
|
||||
|
||||
use crate::commands::role_adder::tools::on_role_change;
|
||||
use serenity::all::{
|
||||
ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildId, GuildMemberUpdateEvent, Interaction,
|
||||
};
|
||||
use serenity::all::{ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildMemberUpdateEvent, Interaction};
|
||||
use serenity::model::guild::Member;
|
||||
use serenity::{
|
||||
async_trait,
|
||||
|
@ -42,7 +40,7 @@ impl EventHandler for Handler {
|
|||
let config_global = config_lock.read().await;
|
||||
|
||||
// committee server takes priority
|
||||
let committee_server = GuildId::new(1220150752656363520);
|
||||
let committee_server = config_global.committee_server;
|
||||
if new_member.guild_id.get() == committee_server.get() {
|
||||
let mut member = vec![new_member.clone()];
|
||||
update_committees(&db, &ctx, &config_global, &mut member).await;
|
||||
|
@ -113,6 +111,12 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
|
|||
println!("[Main] {} is connected!", ready.user.name);
|
||||
ctx.set_presence(Some(ActivityData::playing("with humanity's fate")), OnlineStatus::Online);
|
||||
|
||||
let config_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
|
||||
};
|
||||
let config = config_lock.read().await;
|
||||
|
||||
match Command::set_global_commands(
|
||||
&ctx.http,
|
||||
vec and go to https://discord.com/channels/{}/{} and use
|
|||
}
|
||||
|
||||
// Inter-Committee server
|
||||
match GuildId::new(1220150752656363520)
|
||||
.set_commands(&ctx.http, vec![commands::count::committee::register()])
|
||||
.await
|
||||
{
|
||||
match config.committee_server.set_commands(&ctx.http, vec![commands::count::committee::register()]).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("{:?}", e)
|
||||
|
@ -143,7 +144,8 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
|
|||
}
|
||||
|
||||
// compsoc Server
|
||||
match GuildId::new(689189992417067052)
|
||||
match config
|
||||
.compsoc_server
|
||||
.set_commands(
|
||||
&ctx.http,
|
||||
vec![
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue