motd: add --all and --days to show what the rules hide

9acf634 · Gabriel Morell · 2026-10-19 16:11

3 files +52 -17
Message
{commit_body(@commit)}

Files changed

modified README.md
+5 −0
@@ -45,6 +45,11 @@ Any of these can be overridden for one person with `--person` (name, nick or id)
45 45 `ppl tiers set Family 3 -p Anji`, `ppl tiers remind Family always -p Anji`; `ppl tiers clear Family -p Anji`
46 46 goes back to the tier defaults and `ppl tiers -p Anji` shows what applies.
47 47
48 +To see everything the remind modes are hiding, run `ppl motd --all`: it ignores the modes and dates
49 +with reminders off, and doesn't count as having shown anything, so the next plain `ppl motd` still
50 +reminds as usual. `--days 30` looks 30 days ahead for everyone and every calendar instead of their
51 +windows, including people in no tier.
52 +
48 53 In the TUI the same keys work on the tiers tab (defaults) and on a selected tier while editing a person (overrides):
49 54 `m` cycles the mode, `+`/`-` change the window, `[`/`]` change the random %, `x` clears.
50 55
modified src/main.rs
+47 −17
@@ -102,7 +102,15 @@ enum Commands {
102 102 /// Calendar of upcoming events
103 103 Calendar,
104 104 /// Show MOTD Version
105 − MOTD,
105 + MOTD {
106 + /// Show what the remind modes would hide (already shown, never, random, reminders
107 + /// off), without counting as having been shown
108 + #[arg(long, short)]
109 + all: bool,
110 + /// Look this many days ahead for everyone and every calendar, instead of their windows
111 + #[arg(long, short)]
112 + days: Option<u32>,
113 + },
106 114 /// Add `ppl motd` to your shell's rc file (bash, zsh, fish)
107 115 Shell(ShellArgs),
108 116 /// Add ppl
@@ -150,9 +158,13 @@ async fn main() -> Result<(), PplError> {
150 158 println!("ppl");
151 159 // show().expect("failed2draw")
152 160 }
153 − Some(Commands::MOTD) => {
154 − motd(&db).await?;
155 − motd_holidays(&db).await?;
161 + Some(Commands::MOTD { all, days }) => {
162 + let opts = MotdOpts {
163 + all: *all,
164 + days: *days,
165 + };
166 + motd(&db, opts).await?;
167 + motd_holidays(&db, opts).await?;
156 168 }
157 169 Some(Commands::Shell(args)) => {
158 170 do_shell(args)?;
@@ -230,6 +242,15 @@ async fn main() -> Result<(), PplError> {
230 242 Ok(())
231 243 }
232 244
245 +/// `ppl motd --all --days N`
246 +#[derive(Clone, Copy)]
247 +struct MotdOpts {
248 + /// Ignore remind modes and reminders that are off, and don't record anything as shown
249 + all: bool,
250 + /// Replaces every reminder window
251 + days: Option<u32>,
252 +}
253 +
233 254 /// Whether a remind mode lets something show now, given when it was last shown
234 255 fn should_show(
235 256 remind: MotdRemindEnum,
@@ -256,7 +277,7 @@ fn should_show(
256 277 }
257 278
258 279 /// Upcoming holidays from the calendars that are on, each calendar with its own window and mode
259 −async fn motd_holidays(db: &DatabaseConnection) -> Result<(), PplError> {
280 +async fn motd_holidays(db: &DatabaseConnection, opts: MotdOpts) -> Result<(), PplError> {
260 281 use chrono::{Datelike, Local};
261 282 use colored::Colorize;
262 283
@@ -283,13 +304,15 @@ async fn motd_holidays(db: &DatabaseConnection) -> Result<(), PplError> {
283 304 .map(|v| v.to_string())
284 305 };
285 306 let mode = reminder.mode();
286 − if !should_show(
287 − mode,
288 − meta_str("last_reminded"),
289 − meta_str("last_reminded_hour"),
290 − today,
291 − &this_hour,
292 − ) {
307 + if !opts.all
308 + && !should_show(
309 + mode,
310 + meta_str("last_reminded"),
311 + meta_str("last_reminded_hour"),
312 + today,
313 + &this_hour,
314 + )
315 + {
293 316 debug!(
294 317 "DEBUG: Skipping calendar '{}' - remind mode {}",
295 318 def.key, mode
@@ -299,7 +322,7 @@ async fn motd_holidays(db: &DatabaseConnection) -> Result<(), PplError> {
299 322 let mut any = false;
300 323 for h in upcoming.iter().filter(|h| h.calendar.key == def.key) {
301 324 let days = (h.date - today).num_days();
302 − if days < 0 || days > reminder.window() as i64 {
325 + if days < 0 || days > opts.days.unwrap_or(reminder.window()) as i64 {
303 326 continue;
304 327 }
305 328 // The same day from two calendars, like Good Friday in a state and in Christian
@@ -319,7 +342,8 @@ async fn motd_holidays(db: &DatabaseConnection) -> Result<(), PplError> {
319 342 lines.push((h.date, format!("{} {} ({})", mark, when, def.name)));
320 343 any = true;
321 344 }
322 − if any && matches!(mode, MotdRemindEnum::OnlyOnce | MotdRemindEnum::OnceHourly) {
345 + if any && !opts.all && matches!(mode, MotdRemindEnum::OnlyOnce | MotdRemindEnum::OnceHourly)
346 + {
323 347 if let Some(row) = row {
324 348 let day = today.format("%Y-%m-%d").to_string();
325 349 if let Err(e) = CalendarOps::mark_reminded(db, row, &day, &this_hour).await {
@@ -335,7 +359,7 @@ async fn motd_holidays(db: &DatabaseConnection) -> Result<(), PplError> {
335 359 Ok(())
336 360 }
337 361
338 −async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
362 +async fn motd(db: &DatabaseConnection, opts: MotdOpts) -> Result<(), PplError> {
339 363 use chrono::{Datelike, Local, NaiveDate};
340 364
341 365 let today = Local::now().date_naive();
@@ -435,7 +459,7 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
435 459 &this_hour,
436 460 );
437 461
438 − if !should_show {
462 + if !should_show && !opts.all {
439 463 debug!(
440 464 "DEBUG: Skipping person '{}' - remind mode {}",
441 465 person.name, remind
@@ -451,7 +475,7 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
451 475 "DEBUG: Processing sigdate: {} on {}",
452 476 sigdate.event, sigdate.date
453 477 );
454 − if !sigdate.do_remind {
478 + if !sigdate.do_remind && !opts.all {
455 479 debug!("DEBUG: Skipping sigdate - reminders are off for it");
456 480 continue;
457 481 }
@@ -486,6 +510,11 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
486 510 }
487 511 }
488 512
513 + // --days looks the same distance ahead for everyone, even people in no tier
514 + if opts.days.is_some() {
515 + tier_delta = opts.days;
516 + }
517 +
489 518 // If we have a tier delta, check if we're within the reminder window for this year's anniversary
490 519 if let Some(delta) = tier_delta {
491 520 // Calculate this year's anniversary
@@ -651,6 +680,7 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
651 680
652 681 // Record when we showed them, so OnlyOnce and OnceHourly can skip them next time
653 682 if showed_sigdate
683 + && !opts.all
654 684 && matches!(
655 685 remind,
656 686 MotdRemindEnum::OnlyOnce | MotdRemindEnum::OnceHourly

Parents: 1457011