From d152e0da61c808b889435ffa01f9aeca3ac01a8c Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 19 Aug 2024 04:45:20 +0200 Subject: [PATCH] state transition progress - add notes what needs to happen - hedgedoc summary --- src/hedgedoc.rs | 18 ++++++++++++++++++ src/main.rs | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/hedgedoc.rs b/src/hedgedoc.rs index 017cc63..edd8e77 100644 --- a/src/hedgedoc.rs +++ b/src/hedgedoc.rs @@ -1,4 +1,5 @@ use crate::config_spec::{CfgField, CfgGroup}; +use regex::Regex; use reqwest::blocking::Client; use reqwest::blocking::Response; use std::error::Error; @@ -96,6 +97,23 @@ impl HedgeDoc { } } +pub fn summarize(pad_content: String) -> String { + // 1. remove HTML comments + let re_comment = Regex::new(r"(?s)").unwrap(); + let pad_content = re_comment.replace_all(&pad_content, "").to_string(); + // 2. accumulate topic lines + let re_header = Regex::new(r"^\s*##(#*) TOP ([\d.]+\s*.*?)\s*#*$").unwrap(); + let mut result: Vec = Vec::new(); + for line in pad_content.lines() { + if let Some(captures) = re_header.captures(line) { + let indent = " ".repeat(captures.get(1).unwrap().as_str().len()); + let title = captures.get(2).unwrap().as_str(); + result.push(format!("{}{}", indent, title)); + } + } + result.join("\n") +} + /// For the config, make a new pad ID (by actually making a pad.) fn make_pad_id(_key: &str, config: &crate::KV, is_dry_run: bool) -> Result> { HedgeDoc::new(&config.get("hedgedoc-server-url").unwrap(), is_dry_run).create_pad() diff --git a/src/main.rs b/src/main.rs index da267c0..cde2fc7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,6 +253,11 @@ fn main() -> Result<(), Box> { if args.check_mode { return config_spec::interactive_check(&CONFIG_SPEC, config); } + // ensure existence of this is checked early + let _current_pad_id = config + .get("hedgedoc-last-id") + .expect("ID des aktuellen Pads undefiniert. Bitte in der DB eintragen oder generieren."); + trace_var!(_current_pad_id); // get config let hedgedoc = HedgeDoc::new(&config["hedgedoc-server-url"], is_dry_run()); trace_var!(hedgedoc); @@ -337,10 +342,11 @@ fn main() -> Result<(), Box> { let action: &ST = &TRANSITION_LUT[last_state as usize][intended_state as usize]; verboseln!("Notewendige Aktionen: {}", action.to_string().cyan()); + // run action, which is responsible for updating the state as needed action.get()(delta, &plenum_day, &config, &hedgedoc, &email, &wiki)?; - // TODO: cleanup / write new state - + // shutdown + config.set("state-last-run", &today.to_string())?; if config.has_errors() { return Err("There were errors while writing config values.".into()); } else { @@ -676,7 +682,17 @@ fn do_announcement( ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail, wiki: &Mediawiki, ) -> Result<(), Box> { - // use TTP to adjust text if needed (in {ttp} days) + let current_pad_id = &config["hedgedoc-last-id"]; + let pad_content = hedgedoc.download(current_pad_id).expect("Hedgedoc: Download-Fehler"); + let toc = hedgedoc::summarize(pad_content); + verboseln!("Zusammenfassung des aktuellen Plenum-Pads:\n{}", toc.cyan()); + let n_topics = toc.lines().count(); + verboseln!("(Das sind {} Themen.)", n_topics.to_string().cyan()); + // TODO: if + // summary empty: write message variant + // summary not empty: write other message variant + // TODO: set/write state as Announced + // TODO: write summary todo!() } @@ -685,7 +701,13 @@ fn do_reminder( ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail, wiki: &Mediawiki, ) -> Result<(), Box> { - // use TTP to adjust text if needed (tomorrow or today / in {ttp} days) + // TODO: get pad + // TODO: make summary + // TODO: if + // summary empty: write message variant + // summary not empty: make diff, send diff etc. + // TODO: set/write state as Reminded + // TODO: write summary todo!() } @@ -694,7 +716,10 @@ fn do_protocol( ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail, wiki: &Mediawiki, ) -> Result<(), Box> { - // use TTP to adjust text if needed ({-ttp} days ago) + // TODO: get pad + // TODO: write to wiki + // TODO: write to email + // TODO: set state as Logged todo!() } @@ -705,6 +730,8 @@ fn do_cleanup( ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail, wiki: &Mediawiki, ) -> Result<(), Box> { + // TODO: reset any state vars (e.g. summary) + // TODO: set state back to normal todo!() }