config.rs 2.08 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,
Ash's avatar
Ash committed
27
    pub expired_member_role: u64,
28
29
30
31
32
33
34
    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,
35
    pub react_role_messages: Vec<ReactionMapping>,
Ash's avatar
fixes    
Ash committed
36
37
    #[serde(default = "ldap_bind_address")]
    pub bind_address: String,
38
39
}

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

impl UccbotConfig {
    pub fn allowed_reacts(&self) -> Vec<String> {
tec's avatar
tec committed
46
47
48
49
50
51
52
53
        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(),
        ]
54
55
    }
}
56

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

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

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

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