From 2f14f7edf29bd7010e5f8be8691a907c8ede1278 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Sat, 31 Jul 2021 11:51:25 +0200 Subject: First basic testing zizek bot --- src/bot_config.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bot_config.rs (limited to 'src/bot_config.rs') 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 + { + 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 } +} -- cgit v1.2.3-70-g09d2