//! Configuration module of the telegram bot. Here it gets its information to //! login to its homeserver. use config::{Config, ConfigError, File as ConfigFile}; /// Configuration struct of a bot pub struct BotConfig { user: String, password: String, homeserver_url: String, } impl BotConfig { /// Read the default bot configuration file /// /// # Return /// The configuration needed for the bot to function, or, if the /// configuration file cannot be read, the error that occured while /// trying to load the configuration file. pub fn from_config_file() -> Result { let mut config = Config::default(); config.merge(ConfigFile::with_name("botconfig"))?; Ok(Self { user: config.get_str("user")?, password: config.get_str("password")?, homeserver_url: config.get_str("homeserver_url")?, }) } /// Get the username that should be used by the bot pub fn user(&self) -> &String { &self.user } /// Get the password the bot should use to authenticate its user pub fn password(&self) -> &String { &self.password } /// Get the homeserver of the bot where it should send the login data to pub fn homeserver_url(&self) -> &String { &self.homeserver_url } }