ferris_bot/
config.rs

1/// submodule to make the code more like java
2pub mod conf {
3    use serde::Deserialize;
4    use std::fs::File;
5    use std::io::{Error, Read};
6    use toml;
7
8    #[derive(Deserialize)]
9    /// struct for representing a configuration for this bot
10    pub struct Config {
11        pub token: String,
12        pub moderation: Option<bool>,
13        pub leveling: Option<bool>,
14        pub moderating: Option<ModerationSettings>,
15    }
16
17    #[derive(Deserialize)]
18    /// struct for moderation settings
19    pub struct ModerationSettings {
20        pub enablebl: Option<bool>,
21        pub blacklist: Option<Vec<String>>,
22        pub modrole: u64,
23    }
24
25    /// Try to load a configuration file
26    ///
27    /// # Arguments
28    ///
29    /// * `path` - the path to the config file
30    ///
31    /// # Return
32    ///
33    /// returns a Result of `Config` and `std::io::Error`
34    pub fn load_config(path: &str) -> Result<Config, Error> {
35        let mut file: File = match File::open(path) {
36            Ok(f) => f,
37            Err(e) => {
38                return Err(e);
39            }
40        };
41        let mut contents: String = String::new();
42        match file.read_to_string(&mut contents) {
43            Ok(_n) => (),
44            Err(e) => {
45                return Err(e);
46            }
47        }
48        let cfg: Config = toml::from_str(contents.as_str()).unwrap();
49        Ok(cfg)
50    }
51}
52
53/// some values for commands etc.
54pub mod val {
55    pub const VERSION: &str = "0.2.6";
56}