correct plenum bot config folders

This commit is contained in:
murmeldin 2025-02-09 00:49:39 +01:00
parent 8a6c6cda9a
commit 8df8d6eee6
7 changed files with 63 additions and 102 deletions

View file

@ -1,25 +0,0 @@
{pkgs ? import <nixpkgs> {}}: let
rust-toolchain = pkgs.symlinkJoin {
name = "rust-toolchain";
paths = with pkgs; [rustc cargo rustPlatform.rustcSrc rustfmt clippy];
};
in
pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [
rust-toolchain
pkg-config
xe
xz
cargo-tarpaulin
openssl
sqlite
gcc
gnumake
# dotnet-sdk_8
];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}

View file

@ -1,4 +1,5 @@
use crate::config_spec::{CfgField, CfgGroup}; use crate::config_spec::{CfgField, CfgGroup};
use crate::key_value::KeyValueStore;
use ollama_rs; use ollama_rs;
use ollama_rs::generation::completion::request::GenerationRequest; use ollama_rs::generation::completion::request::GenerationRequest;
use regex::Regex; use regex::Regex;
@ -152,6 +153,13 @@ impl HedgeDoc {
Err(format!("Failed to import note: {}", res.status()).into()) Err(format!("Failed to import note: {}", res.status()).into())
} }
} }
pub fn rotate(config: &KeyValueStore, is_dry_run: bool) -> Result<String, Box<dyn Error>> {
let hold_pad_id = &config["hedgedoc-next-id"];
config.set("hedgedoc-last-id", hold_pad_id);
let new_id = HedgeDoc::new(&config.get("hedgedoc-server-url").unwrap(), is_dry_run).create_pad()?;
config.set("hedgedoc-next-id", &new_id);
Ok(new_id)
} }
pub fn extract_metadata(pad_content: String) -> String { pub fn extract_metadata(pad_content: String) -> String {
@ -167,9 +175,9 @@ pub fn strip_metadata(pad_content: String) -> String {
content_without_comments.trim().to_string() content_without_comments.trim().to_string()
} }
pub fn summarize(pad_content: String) -> String { pub fn summarize(&self, pad_content: String) -> String {
// 1. remove HTML comments // 1. remove HTML comments
let pad_content = strip_metadata(pad_content); let pad_content = Self::strip_metadata(pad_content);
// 2. accumulate topic lines // 2. accumulate topic lines
let re_header = Regex::new(r"^\s*##(#*) TOP ([\d.]+\s*.*?)\s*#*$").unwrap(); let re_header = Regex::new(r"^\s*##(#*) TOP ([\d.]+\s*.*?)\s*#*$").unwrap();
let mut result: Vec<String> = Vec::new(); let mut result: Vec<String> = Vec::new();
@ -198,9 +206,10 @@ pub fn summarize_with_ollama(
Err(err) => return Err(err.into()), Err(err) => return Err(err.into()),
} }
} }
}
/// For the config, make a new pad ID (by actually making a pad.) /// For the config, make a new pad ID (by actually making a pad.)
fn make_pad_id( pub fn make_pad_id(
_key: &str, config: &crate::key_value::KeyValueStore, is_dry_run: bool, _key: &str, config: &crate::key_value::KeyValueStore, is_dry_run: bool,
) -> Result<String, Box<dyn Error>> { ) -> Result<String, Box<dyn Error>> {
HedgeDoc::new(&config.get("hedgedoc-server-url").unwrap(), is_dry_run).create_pad() HedgeDoc::new(&config.get("hedgedoc-server-url").unwrap(), is_dry_run).create_pad()

View file

@ -263,21 +263,6 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
} }
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 {
kv.set("aktuelles-plenumspad", &next_plenum_pad)
.expect("Fehler beim Beschreiben der Datenbank mit neuem Plenumslink!"); // Beispiel: aktuelles-plenumspad: Ok(Some("eCH24zXGS9S8Stg5xI3aRg"))
kv.set("zukünftiges-plenumspad", future_pad_id)
.expect("Fehler beim Beschreiben der Datenbank mit neuem Plenumslink!");
// Beispiel: aktuelles-plenumspad: Ok(Some("eCH24zXGS9S8Stg5xI3aRg"))
} else {
kv.set("zukünftiges-plenumspad", future_pad_id)
.expect("Fehler beim Beschreiben der Datenbank mit neuem Plenumslink!");
// Beispiel: aktuelles-plenumspad: Ok(Some("eCH24zXGS9S8Stg5xI3aRg"))
}
}
/* ***** formatting helpers ***** */ /* ***** formatting helpers ***** */
fn relative_date(ttp: i64) -> String { fn relative_date(ttp: i64) -> String {
@ -497,6 +482,8 @@ fn do_protocol(
); );
let _message_id = send_email(&subject, &body, email, config)?; let _message_id = send_email(&subject, &body, email, config)?;
mediawiki::pad_ins_wiki(pad_content, wiki, plenum_day)?; mediawiki::pad_ins_wiki(pad_content, wiki, plenum_day)?;
let new_id = hedgedoc::rotate(config, is_dry_run())?;
println!("Generated new pad with id '{}'", new_id);
config.set("state-name", &ProgramState::Logged.to_string()).ok(); config.set("state-name", &ProgramState::Logged.to_string()).ok();
} else { } else {
verboseln!("There were no TOPs on this Plenum"); verboseln!("There were no TOPs on this Plenum");

View file

@ -3,7 +3,6 @@ Description=CCCB Plenum-Bot
After=network-online.target After=network-online.target
[Service] [Service]
WorkingDirectory=/home/$User/plenum-bot WorkingDirectory=%h
ExecStart=./util/run_release.sh ExecStart=.cargo/bin/Plenum-Bot -f .config/Plenum-Bot.sqlite
Type=simple Type=simple
User=root

View file

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
# This script is being ran every time the systemd job is triggered # This script can be run in order to change the Plenum-Bot config
u=$USER $HOME/.cargo/bin/Plenum-Bot -f .config/Plenum-Bot.sqlite -c
../target/release/Plenum-Bot -f /home/$u/.config/plenum-bot/config.sqlite -c

View file

@ -1,7 +0,0 @@
#!/bin/sh
# This script is being ran every time the systemd job is triggered
u=$USER
../target/release/Plenum-Bot -f /home/$u/.config/plenum-bot/config.sqlite

View file

@ -3,9 +3,9 @@
# This script can be run to update or newly install # This script can be run to update or newly install
# the systemd services needed for # the systemd services needed for
sudo -i sudo -i
cat ../systemd/plenumbot.service > /etc/systemd/system/plenumsbot.service cat ../systemd/plenumbot.service > $HOME/.config/systemd/user/Plenum-Bot.service
cat ../systemd/plenumbot.timer > /etc/systemd/system/plenumsbot.timer cat ../systemd/plenumbot.timer > $HOME/.config/systemd/user/Plenum-Bot.timer
chmod 755 /etc/systemd/system/plenumsbot.timer chmod 755 $HOME/.config/systemd/user/Plenum-Bot.timer
chmod 755 /etc/systemd/system/plenumsbot.service chmod 755 $HOME/.config/systemd/user/Plenum-Bot.service
systemctl daemon-reload systemctl daemon-reload --user