diff options
| author | Arne Dußin | 2021-07-31 11:51:25 +0200 |
|---|---|---|
| committer | Arne Dußin | 2021-07-31 11:51:25 +0200 |
| commit | 2f14f7edf29bd7010e5f8be8691a907c8ede1278 (patch) | |
| tree | 2708ee050e3dba8ca75be2160428e1c4bd487367 /src/bot_config.rs | |
| parent | af7514d42b3ec6743fd8037c6e909ae8134dfa4f (diff) | |
| download | matrix-zizek-bot-2f14f7edf29bd7010e5f8be8691a907c8ede1278.tar.gz matrix-zizek-bot-2f14f7edf29bd7010e5f8be8691a907c8ede1278.zip | |
First basic testing zizek bot
Diffstat (limited to 'src/bot_config.rs')
| -rw-r--r-- | src/bot_config.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/bot_config.rs b/src/bot_config.rs new file mode 100644 index 0000000..2438c40 --- /dev/null +++ b/src/bot_config.rs @@ -0,0 +1,40 @@ +//! 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<BotConfig, ConfigError> + { + 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 } +} |
