aboutsummaryrefslogtreecommitdiff
path: root/src/ext/framework/configuration.rs
blob: 09874c804218175caaf19e6d73d43845f4bb2b81 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::default::Default;
use ::client::http;

pub struct Configuration {
    pub depth: usize,
    pub on_mention: Option<Vec<String>>,
    pub allow_whitespace: bool,
    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
    }

    /// Whether to allow whitespace being optional between a mention and a
    /// command.
    ///
    /// **Note**: Defaults to `false`.
    ///
    /// # Examples
    ///
    /// Setting this to `true` will allow this scenario to occur, while `false`
    /// will not:
    ///
    /// ```ignore
    /// <@BOT_ID>about
    ///
    /// // bot processes and executes the "about" command if it exists
    /// ```
    pub fn allow_whitespace(mut self, allow_whitespace: bool)
        -> Self {
        self.allow_whitespace = allow_whitespace;

        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,
            allow_whitespace: false,
            prefix: None,
        }
    }
}