config.rs 2.04 KB
Newer Older
1
use indexmap::IndexMap;
tec's avatar
tec committed
2
use serde::Deserialize;
Timothy du Heaume's avatar
Timothy du Heaume committed
3
use serde_yaml;
4
use serenity::model::id;
5 6 7
use std::fs;

lazy_static! {
8
    static ref CONFIG_FILE: String = fs::read_to_string("config.yml").unwrap();
9
    pub static ref CONFIG: UccbotConfig = serde_yaml::from_str(&CONFIG_FILE).unwrap();
10 11
    static ref SECRETS_FILE: String = fs::read_to_string("secrets.yml").unwrap();
    pub static ref SECRETS: UccbotSecrets = serde_yaml::from_str(&SECRETS_FILE).unwrap();
12 13
}

14
#[derive(Debug, Deserialize)]
15 16
pub struct UccbotConfig {
    pub server_id: u64,
17 18 19
    pub main_channel: id::ChannelId,
    pub welcome_channel: id::ChannelId,
    pub announcement_channel: id::ChannelId,
tec's avatar
tec committed
20
    pub readme_channel: id::ChannelId,
21 22 23 24 25 26
    pub bot_id: u64,
    pub vote_pool_size: i8,
    pub vote_role: u64,
    pub tiebreaker_role: u64,
    pub unregistered_member_role: u64,
    pub registered_member_role: u64,
27 28 29 30 31 32 33
    pub command_prefix: String,
    pub for_vote: String,
    pub against_vote: String,
    pub abstain_vote: String,
    pub approve_react: String,
    pub disapprove_react: String,
    pub unsure_react: String,
34
    pub react_role_messages: Vec<ReactionMapping>,
Ash's avatar
fixes  
Ash committed
35 36
    #[serde(default = "ldap_bind_address")]
    pub bind_address: String,
37 38
}

Ash's avatar
fixes  
Ash committed
39 40
pub fn ldap_bind_address() -> String {
    "ldaps://samson.ucc.asn.au:636".to_string()
41 42 43 44
}

impl UccbotConfig {
    pub fn allowed_reacts(&self) -> Vec<String> {
tec's avatar
tec committed
45 46 47 48 49 50 51 52
        vec![
            self.for_vote.to_string(),
            self.against_vote.to_string(),
            self.abstain_vote.to_string(),
            self.approve_react.to_string(),
            self.disapprove_react.to_string(),
            self.unsure_react.to_string(),
        ]
53 54
    }
}
55

Ash's avatar
cleanup  
Ash committed
56 57 58 59 60 61
#[derive(Debug, Deserialize)]
pub struct UccbotSecrets {
    pub ldap_pass: String,
    pub discord_token: String,
}

62 63
pub type ReactRoleMap = IndexMap<String, id::RoleId>;

64 65 66
#[derive(Debug, Deserialize, Clone)]
pub struct ReactionMapping {
    pub message: serenity::model::id::MessageId,
67
    #[serde(default = "empty_rr_map")]
68
    pub mapping: ReactRoleMap,
69
}
70 71 72 73

fn empty_rr_map() -> ReactRoleMap {
    IndexMap::new()
}