cleanup: removed old and unused functions and variables

This commit is contained in:
murmeldin 2025-01-15 14:50:38 +01:00
parent 68e7e1432f
commit c15188ec9d
5 changed files with 41 additions and 108 deletions

View file

@ -124,7 +124,7 @@ impl HedgeDoc {
pub fn create_pad(&self) -> Result<String, Box<dyn Error>> {
if self.is_dry_run {
todo!("NYI: sane dry-run behavior")
todo!("nyi: sane dry-run behavior")
}
let res = self.do_request(&format!("{}/new", self.server_url)).unwrap();
if res.status().is_success() {
@ -136,7 +136,7 @@ impl HedgeDoc {
pub fn import_note(&self, id: Option<&str>, content: String) -> Result<String, Box<dyn Error>> {
if self.is_dry_run {
todo!("NYI: sane dry-run behavior")
todo!("nyi: sane dry-run behavior")
}
let url = match id {
Some(id) => self.format_url(&format!("new/{id}")),

View file

@ -125,24 +125,24 @@ macro_rules! trace_var_ {
};
}
/// Similar to [`todo!`], but non-fatal; `NYI` prints a message to stderr _only once_
/// Similar to [`todo!`], but non-fatal; `nyi` prints a message to stderr _only once_
#[macro_export]
macro_rules! NYI {
macro_rules! nyi {
($msg:expr) => {{
// rely on the non-snake-case warning to get a warning at use sites
fn NYI() {}
NYI();
fn nyi() {}
nyi();
static ONCE: std::sync::Once = std::sync::Once::new();
let location = stdext::debug_name!();
ONCE.call_once(|| {
eprintln!("{}: NYI -- {}", location, $msg);
eprintln!("{}: nyi -- {}", location, $msg);
});
}};
() => {{
static ONCE: std::sync::Once = std::sync::Once::new();
let location = stdext::debug_name!();
ONCE.call_once(|| {
eprintln!("{}: NYI!", location);
eprintln!("{}: nyi!", location);
});
}};
}

View file

@ -13,12 +13,11 @@ use cccron_lib::is_dry_run;
use cccron_lib::key_value::{KeyValueStore as KV, KeyValueStore};
use cccron_lib::matrix::{self, MatrixClient};
use cccron_lib::mediawiki::{self, Mediawiki};
use cccron_lib::NYI;
use cccron_lib::nyi;
use cccron_lib::{trace_var, trace_var_, verboseln};
use chrono::{DateTime, Local, NaiveDate, Utc};
use chrono::{Local, NaiveDate};
use clap::{Arg, Command};
use colored::Colorize;
use regex::Regex;
/* ***** Config Spec ***** */
const CONFIG_SPEC: CfgSpec<'static> = CfgSpec {
@ -264,52 +263,6 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}
fn generate_new_pad_for_following_date(
config: KV, hedgedoc: HedgeDoc, übernächster_plenumtermin: &str,
überübernächster_plenumtermin: &str, kv: &KV,
) -> Result<(), Box<dyn Error>> {
match hedgedoc.create_pad() {
Err(e) => println!("Failed to create pad: {}", e),
Ok(pad_id) => {
println!("Pad created successfully with ID: {}", pad_id);
// Get the most recent plenum template and replace the placeholders:
let template_content: String = match config.get("hedgedoc-template-name") {
Ok(content) => hedgedoc
.download(&content.clone())
.unwrap_or_else(|_| config.get("text-fallback-template").unwrap_or_default()),
Err(_) => config.get("text-fallback-template").unwrap_or_default(),
};
// XXX you don't just use the template as-is…
let template_modified: String = replace_placeholders(
&template_content,
übernächster_plenumtermin,
überübernächster_plenumtermin,
)
.unwrap_or(template_content); // Try regex, if not successful use without regex
match hedgedoc.import_note(Some(&pad_id), template_modified) {
Ok(_) => {
println!("Pad updated successfully with template content.");
rotate(&pad_id, kv);
},
Err(e) => println!("Failed to update pad: {}", e),
}
},
}
Ok(())
}
fn replace_placeholders(
template: &str, übernächster_plenumtermin: &str, überübernächster_plenumtermin: &str,
) -> Result<String, Box<dyn Error>> {
let re_datum = Regex::new(r"\{\{Datum\}\}")?;
let result = re_datum.replace_all(template, übernächster_plenumtermin);
let re_naechstes_plenum = Regex::new(r"\{\{naechstes-plenum\}\}")?;
let result = re_naechstes_plenum.replace_all(&result, überübernächster_plenumtermin);
Ok(result.to_string())
}
fn rotate(future_pad_id: &str, kv: &KV) {
let next_plenum_pad = kv.get("zukünftiges-plenumspad").ok();
if let Some(next_plenum_pad) = next_plenum_pad {
@ -381,7 +334,7 @@ fn do_announcement(
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
_wiki: &Mediawiki,
) -> Result<(), Box<dyn Error>> {
NYI!("trace/verbose annotations");
nyi!("trace/verbose annotations");
// fetch current pad contents & summarize
let (current_pad_id, _pad_content, toc, n_topics) = get_pad_info(config, hedgedoc);
// construct email
@ -400,7 +353,7 @@ fn do_announcement(
"Falls ihr noch Themen ergänzen wollt ist hier der Link zum Pad:\n {}",
hedgedoc.format_url(&current_pad_id)
);
let mut body = format!("{line1}\n\n{line2}");
let body = format!("{line1}\n\n{line2}");
// send it
let message_id = send_email(&subject, &body, email, config)?;
// on success, update state (ignore write errors, they'll be checked later)
@ -424,7 +377,7 @@ fn do_reminder(
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
_wiki: &Mediawiki,
) -> Result<(), Box<dyn Error>> {
NYI!("trace/verbose annotations");
nyi!("trace/verbose annotations");
// fetch current pad contents & summarize
let (current_pad_id, _pad_content, toc, n_topics) = get_pad_info(config, hedgedoc);
let old_toc = config.get("email-state-toc")?;
@ -446,14 +399,14 @@ fn do_reminder(
} else {
format!("Es gab nochmal Änderungen, die aktualisierten Themen für das Plenum sind:\n\n{toc}\n\n")
};
let mut body = if n_topics > 0 {
let body = if n_topics > 0 {
format!(
"{body_prefix}Die vollen Details findet ihr im Pad:\n {}\n\nBis {} um 20:00!",
hedgedoc.format_url(&current_pad_id),
relative_date(ttp)
)
} else {
NYI!("generate link / pad for next plenum & include in this email");
nyi!("generate link / pad for next plenum & include in this email");
"Da es immer noch keine Themen gibt fällt das Plenum aus.\n\n\
(Natürlich könnt ihr im Bedarfsfall immer noch kurzfristig ein Treffen einberufen, aber \
bitte kündigt das so früh wie möglich an, damit insbesondere auch Leute mit längeren \
@ -464,7 +417,7 @@ fn do_reminder(
let _message_id = send_email(&subject, &body, email, config)?;
// on success, update state (ignore write errors, they'll be checked later)
if n_topics == 0 {
NYI!(
nyi!(
"do we skip ahead to ProgramState::Logged here or do we later add a note to the wiki?"
);
// TODO: ADD SOMETHING TO WIKI
@ -485,13 +438,12 @@ fn do_reminder(
Ok(())
}
#[allow(unused_variables)]
fn do_protocol(
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
wiki: &Mediawiki,
) -> Result<(), Box<dyn Error>> {
NYI!("trace/verbose annotations");
let (current_pad_id, pad_content_without_cleanup, toc, n_topics) =
nyi!("trace/verbose annotations");
let (_current_pad_id, pad_content_without_cleanup, toc, n_topics) =
get_pad_info(config, hedgedoc);
let pad_content = hedgedoc::strip_metadata(pad_content_without_cleanup.clone());
let ollama_enabled: bool = match &config["hedgedoc-ollama-summaries-enabled"] {
@ -521,8 +473,9 @@ fn do_protocol(
let subject = format!("Protokoll vom Plenum am {human_date}");
let pad_content = pad_content.replace("[toc]", &toc);
let body = format!(
"Anbei das Protokoll vom {human_date}, ab sofort auch im Wiki zu finden.\n\n\
"Anbei das Protokoll von {} ({human_date}), ab sofort auch im Wiki zu finden. Heute gab es {n_topics} TOPs.\n\n\
Das Pad für das nächste Plenum ist zu finden unter <{}/{}>.\n\nDie Protokolle der letzten Plena findet ihr im wiki unter <{}/index.php?title={}>.\n\n---Protokoll:---\n{}\n-----",
relative_date(ttp),
&config["hedgedoc-server-url"],
&config["hedgedoc-next-id"],
&config["wiki-server-url"],
@ -538,8 +491,9 @@ fn do_protocol(
let subject = format!("Protokoll vom ausgefallenem Plenum am {human_date}");
let pad_content = pad_content.replace("[toc]", &toc);
let body = format!(
"Anbei das Protokoll vom {human_date}, ab sofort auch im Wiki zu finden.\n\n\
"Anbei das Protokoll von {} ({human_date}), ab sofort auch im Wiki zu finden. Heute gab es {n_topics} TOPs.\n\n\
Das Pad für das nächste Plenum ist zu finden unter {}/{}.\n\nDie Protokolle der letzten Plena findet ihr im wiki unter {}/index.php?title={}.\n\n---Protokoll:---{}",
relative_date(ttp),
&config["hedgedoc-server-url"],
&config["hedgedoc-next-id"],
&config["wiki-server-url"],
@ -560,10 +514,10 @@ fn do_protocol(
);
// Send the matrix room message
let human_date = plenum_day.format("%d.%m.%Y");
let pad_content = pad_content.replace("[toc]", &toc);
let message = format!(
"Anbei das Protokoll vom {human_date}, ab sofort auch im Wiki zu finden.\n\n\
"Anbei das Protokoll von {} ({human_date}), ab sofort auch im Wiki zu finden. Heute gab es {n_topics} TOPs.\n\n\
Das Pad für das nächste Plenum ist zu finden unter {}/{}.\n\nDie Protokolle der letzten Plena findet ihr im wiki unter {}/index.php?title={}.\n\n**Hier die Zusammenfassung:**\n\n{}",
relative_date(ttp),
&config["hedgedoc-server-url"],
&config["hedgedoc-next-id"],
&config["wiki-server-url"],
@ -577,17 +531,16 @@ fn do_protocol(
/// General cleanup function. Call as `(999, today, …)` for a complete reset
/// based on today as the base date.
#[allow(unused_must_use)]
fn do_cleanup(
_ttp: i64, _plenum_day: &NaiveDate, config: &KV, _hedgedoc: &HedgeDoc, _email: &SimpleEmail,
_wiki: &Mediawiki,
) -> Result<(), Box<dyn Error>> {
NYI!("trace/verbose annotations");
config.delete("email-state-toc");
config.delete("email-last-message-id");
NYI!("rotate pad links");
NYI!("double-check state for leftovers");
config.set("state-name", &ProgramState::Normal.to_string());
nyi!("trace/verbose annotations");
_ = config.delete("email-state-toc");
_ = config.delete("email-last-message-id");
nyi!("rotate pad links");
nyi!("double-check state for leftovers");
_ = config.set("state-name", &ProgramState::Normal.to_string());
Ok(())
}
@ -745,25 +698,3 @@ fn send_email(
);
email.send_email(full_subject, full_body)
}
fn display_logo(eta: &str) {
let ansi_art_pt1 = r#"

 
  Plenum! Ple-e-e-num!
  Plenum ist wichtig für die Revolution!
 
 🬯🮗🮗🮗🮗🮗🮗  Dies ist der CCCB Plenumsbot
 🬥🮗🮗🮗🮗🮗🮗 
 🬂🬤🬭  Version {VERSION}
 🬂🬂🬂🬂🬂🬂🬂🬂🬂 
 🬔🬈 🬔🬈 🬔🬈 🬴🬗 🬭🬫🬀  ETA.:"#;
let ansi_art_pt2 = r#"
 🬣🬖 🬣🬖 🬣🬖 🬲🬘 
 
 

"#;
let ansi_art = format!("{ansi_art_pt1}{eta}{ansi_art_pt2}");
println!("{}", ansi_art);
}

View file

@ -1,5 +1,4 @@
use std::error::Error;
use std::io::Read;
use lazy_static::lazy_static;
use colored::Colorize;
@ -9,9 +8,10 @@ use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};
use reqwest::blocking::Client;
use serde_json::{json, Value};
use serde_json::Value;
use crate::config_spec::{CfgField, CfgGroup};
#[allow(unused_imports)]
use crate::{trace_var, verboseln};
pub const CONFIG: CfgGroup<'static> = CfgGroup {

View file

@ -5,7 +5,7 @@ use chrono::{Datelike, NaiveDate, Utc};
use colored::Colorize;
use reqwest::blocking::Client;
use serde::Deserialize;
use serde_json::{json, Value};
use serde_json;
use crate::config_spec::{CfgField, CfgGroup};
use crate::{trace_var, verboseln};
@ -81,7 +81,7 @@ pub enum ValidRequestTypes {
pub enum ValidPageEdits {
WithPotentiallyOverriding,
WithoutOverriding,
ModifyPlenumPageAfterwards_WithoutOverriding,
ModifyPlenumPageAfterwardsWithoutOverriding,
}
impl Mediawiki {
@ -255,7 +255,7 @@ impl Mediawiki {
("bot", "true"),
])
},
ValidPageEdits::ModifyPlenumPageAfterwards_WithoutOverriding => {
ValidPageEdits::ModifyPlenumPageAfterwardsWithoutOverriding => {
// This means we *CREATE* a *new Page* and always prevent overwriting
Box::from([
("action", "edit"),
@ -326,7 +326,7 @@ impl Mediawiki {
verboseln!("pos7");
// Update the main plenum page if requested
match update_main_page {
ValidPageEdits::ModifyPlenumPageAfterwards_WithoutOverriding => {
ValidPageEdits::ModifyPlenumPageAfterwardsWithoutOverriding => {
verboseln!("updating main page...");
self.update_plenum_page(page_title)?
},
@ -530,7 +530,7 @@ pub fn pad_ins_wiki(
wiki.new_wiki_page(
&full_page_title,
&pad_converted,
ValidPageEdits::ModifyPlenumPageAfterwards_WithoutOverriding,
ValidPageEdits::ModifyPlenumPageAfterwardsWithoutOverriding,
)?;
verboseln!("Finished successfully with wiki");
@ -560,7 +560,7 @@ fn create_page_title(date: &NaiveDate) -> String {
/// Deserialization must be done this way because the response contains
/// two `\\` characters in both the login and csrf tokens, which breaks the
/// usual deserialization
#[allow(dead_code)]
#[derive(Deserialize)]
struct QueryResponseLogin {
#[allow(dead_code)]
@ -568,11 +568,13 @@ struct QueryResponseLogin {
query: QueryTokensLogin,
}
#[allow(dead_code)]
#[derive(Deserialize)]
struct QueryTokensLogin {
tokens: TokensLogin,
}
#[allow(dead_code)]
#[derive(Deserialize)]
struct TokensLogin {
logintoken: String,