From b4ccae581a9f39ff3104afb55ead25dc4fd33b6f Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Sat, 18 Apr 2020 17:12:25 -0600 Subject: [PATCH] improve documentation --- src/bot.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/bot.rs b/src/bot.rs index e941e4e..3c91d3d 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -17,11 +17,15 @@ pub struct MatrixConfig { pub login: toml::Value, } +/// The base config, which is read from and written to by the bot #[derive(Serialize, Deserialize, Debug)] pub struct Config { pub matrix: MatrixConfig, } +/// The actual dicebot structure, which drives the entire operation. +/// +/// This is the core of the dicebot program. pub struct DiceBot { config_path: Option, config: Config, @@ -37,6 +41,7 @@ struct LoginResponse { } impl DiceBot { + /// Create a new dicebot from the given config path and config pub async fn new(config_path: Option, config: Config) -> Result> { let home_server: Url = format!("https://{}", config.matrix.home_server).parse()?; let client = Client::new(); @@ -60,6 +65,7 @@ impl DiceBot { }) } + /// Create a new dicebot, storing the config path to write it out pub async fn from_path>(config_path: P) -> Result> { let config_path = config_path.into(); let config = { @@ -86,6 +92,7 @@ impl DiceBot { url } + /// Sync to the matrix homeserver, acting on events as necessary pub async fn sync(&mut self) -> Result<(), Box> { let mut sync_url = self.url("/_matrix/client/r0/sync", &[("timeout", "30000")]); @@ -106,6 +113,8 @@ impl DiceBot { Ok(()) } + /// Log off of the matrix server, also writing out the config file if one was given in + /// construction pub async fn logout(mut self) -> Result<(), Box> { let logout_url = self.url("/_matrix/client/r0/logout", &[]); self.client.post(logout_url)