aboutsummaryrefslogtreecommitdiff
path: root/src/ext/framework/configuration.rs
blob: cd68c695d4f2414a36a7d5a34017ded7b4d65b6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::default::Default;
use ::client::http;

pub struct Configuration {
    pub depth: usize,
    pub on_mention: Option<Vec<String>>,
    pub prefix: Option<String>,
}

impl Configuration {
    /// The default depth of the message to check for commands. Defaults to 5.
    pub fn depth(mut self, depth: u8) -> Self {
        self.depth = depth as usize;

        self
    }

    pub fn on_mention(mut self, on_mention: bool) -> Self {
        if !on_mention {
            return self;
        }

        if let Ok(current_user) = http::get_current_user() {
            self.on_mention = Some(vec![
                format!("<@{}>", current_user.id), // Regular mention
                format!("<@!{}>", current_user.id), // Nickname mention
            ]);
        }

        self
    }

    pub fn prefix<S: Into<String>>(mut self, prefix: S) -> Self {
        self.prefix = Some(prefix.into());

        self
    }
}

impl Default for Configuration {
    fn default() -> Configuration {
        Configuration {
            depth: 5,
            on_mention: None,
            prefix: None,
        }
    }
}