diff --git a/PRUNES b/PRUNES deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 42125e0..70a361e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Config vars: If you gave it a toast channel, you can now see some toasts. -`PRUNE` is an administrative convenience for making LOUDBOT bulk-forget shouts. Put the items you'd like to purge as new-line delimited text in the file `PRUNES`, then run `PRUNE`. I need something better here myself so I'll write it soon. I also need a good backup method better than redis dumps. +`PRUNE` is an administrative convenience for making LOUDBOT bulk-forget shouts. Put the items you'd like to purge as new-line delimited text in some file, then run `PRUNE /path/to/file`. I need something better here myself so I'll write it soon. I also need a good backup method better than redis dumps. ## License diff --git a/src/bin/PRUNE.rs b/src/bin/PRUNE.rs index 8efae79..933ba4f 100644 --- a/src/bin/PRUNE.rs +++ b/src/bin/PRUNE.rs @@ -45,8 +45,10 @@ fn main() -> Result<()> { let yellkey = format!("{}:YELLS", redis_prefix); - prune_from_file(&mut rcon, "PRUNES", &yellkey) + for f in std::env::args().skip(1) { + prune_from_file(&mut rcon, &f, &yellkey) .with_context(|| "Trying to write to redis failed utterly.")?; + } Ok(()) } diff --git a/src/bin/SEED.rs b/src/bin/SEED.rs index 1504b7b..f27a37a 100644 --- a/src/bin/SEED.rs +++ b/src/bin/SEED.rs @@ -1,34 +1,35 @@ use anyhow::{Context, Result}; use dotenv::dotenv; -use redis::Commands; use regex::Regex; use std::env; use std::fs::File; use std::io::{ BufRead, BufReader }; use std::path::Path; -type RCount = std::result::Result; - // Message store + other data fn seed_from_file(db: &mut redis::Connection, filename: impl AsRef + std::fmt::Debug + Copy, key: &str, skip_loud_check: bool) -> Result { + let fp = File::open(filename); + if fp.is_err() { + println!("Skipping {:?}; could not open file for reading.", filename); + return Ok(0) + } + let punc = Regex::new(r"[\W\d[[:punct:]]]").unwrap(); - let mut count: u32 = 0; - let file = File::open(filename).expect("no such file"); + let mut pipe = redis::pipe(); + let file = fp.unwrap(); let reader = BufReader::new(file); + for line in reader.lines() { let text = line.unwrap(); - let result = punc.replace_all(&text, ""); if !skip_loud_check && (result.len() < 3 || result.to_uppercase() != result) { continue; } - - let res: RCount = db.sadd(key, text); - match res { - Err(e) => println!("{:?}", e), - Ok(i) => { count += i; }, - } + pipe.sadd(key, text); } + + let result: Vec = pipe.query(db)?; + let count = result.iter().sum(); println!("Added {} items from {:#?}", count, filename); Ok(count) }