fmt

b3afa38 · gmorell · 2026-01-18 22:40

7 files +84 -68

Files changed

modified src/data.rs
+2 −2
@@ -383,7 +383,7 @@ impl TierOps {
383 383 db: &DatabaseConnection,
384 384 ppl_id: i32,
385 385 tier: String,
386 − sig_date_delta: Option<u32>
386 + sig_date_delta: Option<u32>,
387 387 ) -> Result<(), PplError> {
388 388 let t = tier::ActiveModel {
389 389 id: Default::default(),
@@ -535,7 +535,7 @@ impl TierDefaultOps {
535 535 enabled: bool,
536 536 color: String,
537 537 symbol: String,
538 − sig_date_delta: Option<u32>
538 + sig_date_delta: Option<u32>,
539 539 ) -> Result<(), PplError> {
540 540 let t = tier_defaults::ActiveModel {
541 541 id: Default::default(),
modified src/main.rs
+77 −41
@@ -192,10 +192,10 @@ async fn main() -> Result<(), PplError> {
192 192 }
193 193
194 194 enum MotdRemindEnum {
195 − OnlyOnce, // Default, Only the first time the motd is run that day
196 − OnceHourly, // Only once per hour, resetting at the top of the hour
195 + OnlyOnce, // Default, Only the first time the motd is run that day
196 + OnceHourly, // Only once per hour, resetting at the top of the hour
197 197 Randomly(u8), // Will show this motd person randomly u8% every run
198 − Always, // Will always show this person's upcoming
198 + Always, // Will always show this person's upcoming
199 199 }
200 200
201 201 async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
@@ -216,7 +216,11 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
216 216 .all(db)
217 217 .await?;
218 218
219 − debug!("DEBUG: Person '{}' has {} sigdates", person.name, sigdates.len());
219 + debug!(
220 + "DEBUG: Person '{}' has {} sigdates",
221 + person.name,
222 + sigdates.len()
223 + );
220 224
221 225 // Get all tiers for this person
222 226 let person_tiers = Tier::find()
@@ -224,7 +228,11 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
224 228 .all(db)
225 229 .await?;
226 230
227 − debug!("DEBUG: Person '{}' has {} tiers", person.name, person_tiers.len());
231 + debug!(
232 + "DEBUG: Person '{}' has {} tiers",
233 + person.name,
234 + person_tiers.len()
235 + );
228 236
229 237 // Determine the remind enum for this person (default to OnlyOnce if null)
230 238 // Also get the tier color and symbol for display
@@ -250,33 +258,42 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
250 258
251 259 // Check if we should show this person based on remind_enum (default OnlyOnce)
252 260 // If remind_enum is null or "OnlyOnce", check if we've shown them today
253 − let should_show = if remind_enum_value.is_none() || remind_enum_value.as_deref() == Some("OnlyOnce") {
254 − // Check meta field for last_reminded date
255 − if let Some(meta_json) = &person.meta {
256 − if let Some(last_reminded) = meta_json.get("last_reminded") {
257 − if let Some(last_reminded_str) = last_reminded.as_str() {
258 − if let Ok(last_reminded_date) = NaiveDate::parse_from_str(last_reminded_str, "%Y-%m-%d") {
259 − debug!("DEBUG: Person '{}' was last reminded on {}", person.name, last_reminded_date);
260 − // Only show if last reminded was before today
261 − last_reminded_date < today
261 + let should_show =
262 + if remind_enum_value.is_none() || remind_enum_value.as_deref() == Some("OnlyOnce") {
263 + // Check meta field for last_reminded date
264 + if let Some(meta_json) = &person.meta {
265 + if let Some(last_reminded) = meta_json.get("last_reminded") {
266 + if let Some(last_reminded_str) = last_reminded.as_str() {
267 + if let Ok(last_reminded_date) =
268 + NaiveDate::parse_from_str(last_reminded_str, "%Y-%m-%d")
269 + {
270 + debug!(
271 + "DEBUG: Person '{}' was last reminded on {}",
272 + person.name, last_reminded_date
273 + );
274 + // Only show if last reminded was before today
275 + last_reminded_date < today
276 + } else {
277 + true // Invalid date format, show anyway
278 + }
262 279 } else {
263 − true // Invalid date format, show anyway
280 + true // Not a string, show anyway
264 281 }
265 282 } else {
266 − true // Not a string, show anyway
283 + true // No last_reminded field, show
267 284 }
268 285 } else {
269 − true // No last_reminded field, show
286 + true // No meta, show
270 287 }
271 288 } else {
272 − true // No meta, show
273 − }
274 − } else {
275 − true // Other remind modes not yet implemented, show for now
276 − };
289 + true // Other remind modes not yet implemented, show for now
290 + };
277 291
278 292 if !should_show {
279 − debug!("DEBUG: Skipping person '{}' - already shown today", person.name);
293 + debug!(
294 + "DEBUG: Skipping person '{}' - already shown today",
295 + person.name
296 + );
280 297 continue;
281 298 }
282 299
@@ -295,12 +312,18 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
295 312 debug!("DEBUG: Found {} date trait defaults", trait_defaults.len());
296 313
297 314 for sigdate in sigdates {
298 − debug!("DEBUG: Processing sigdate: {} on {}", sigdate.event, sigdate.date);
315 + debug!(
316 + "DEBUG: Processing sigdate: {} on {}",
317 + sigdate.event, sigdate.date
318 + );
299 319 let mut tier_delta: Option<u32> = None;
300 320
301 321 // First check person's assigned tiers
302 322 for tier in &person_tiers {
303 − debug!("DEBUG: Checking tier '{}' with delta {:?}", tier.name, tier.sig_date_delta);
323 + debug!(
324 + "DEBUG: Checking tier '{}' with delta {:?}",
325 + tier.name, tier.sig_date_delta
326 + );
304 327 if let Some(delta) = tier.sig_date_delta {
305 328 tier_delta = Some(delta);
306 329 break;
@@ -310,7 +333,10 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
310 333 // If no tier delta found, check tier_defaults
311 334 if tier_delta.is_none() {
312 335 for tier_default in &tier_defaults {
313 − debug!("DEBUG: Checking tier_default '{}' with delta {:?}", tier_default.key, tier_default.sig_date_delta);
336 + debug!(
337 + "DEBUG: Checking tier_default '{}' with delta {:?}",
338 + tier_default.key, tier_default.sig_date_delta
339 + );
314 340 if let Some(delta) = tier_default.sig_date_delta {
315 341 tier_delta = Some(delta);
316 342 break;
@@ -321,15 +347,15 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
321 347 // If we have a tier delta, check if we're within the reminder window for this year's anniversary
322 348 if let Some(delta) = tier_delta {
323 349 // Calculate this year's anniversary
324 − let this_year_anniversary = NaiveDate::from_ymd_opt(
325 − today.year(),
326 − sigdate.date.month(),
327 − sigdate.date.day()
328 − );
350 + let this_year_anniversary =
351 + NaiveDate::from_ymd_opt(today.year(), sigdate.date.month(), sigdate.date.day());
329 352
330 353 if let Some(anniversary) = this_year_anniversary {
331 354 let days_until = (anniversary - today).num_days();
332 − debug!("DEBUG: This year's anniversary is {}, days until: {}", anniversary, days_until);
355 + debug!(
356 + "DEBUG: This year's anniversary is {}, days until: {}",
357 + anniversary, days_until
358 + );
333 359
334 360 // Show if the anniversary is upcoming and within the delta window
335 361 if days_until >= 0 && days_until <= delta as i64 {
@@ -368,8 +394,7 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
368 394 };
369 395
370 396 // Find matching trait_default for this sigdate event
371 − let trait_info = trait_defaults.iter()
372 − .find(|t| t.key == sigdate.event);
397 + let trait_info = trait_defaults.iter().find(|t| t.key == sigdate.event);
373 398
374 399 if let Some(trait_def) = trait_info {
375 400 println!(
@@ -397,11 +422,14 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
397 422 let next_year_anniversary = NaiveDate::from_ymd_opt(
398 423 today.year() + 1,
399 424 sigdate.date.month(),
400 − sigdate.date.day()
425 + sigdate.date.day(),
401 426 );
402 427 if let Some(next_anniversary) = next_year_anniversary {
403 428 let days_until_next = (next_anniversary - today).num_days();
404 − debug!("DEBUG: Next year's anniversary is {}, days until: {}", next_anniversary, days_until_next);
429 + debug!(
430 + "DEBUG: Next year's anniversary is {}, days until: {}",
431 + next_anniversary, days_until_next
432 + );
405 433
406 434 if days_until_next >= 0 && days_until_next <= delta as i64 {
407 435 let years_since = (today.year() + 1) - sigdate.date.year();
@@ -439,8 +467,8 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
439 467 };
440 468
441 469 // Find matching trait_default for this sigdate event
442 − let trait_info = trait_defaults.iter()
443 − .find(|t| t.key == sigdate.event);
470 + let trait_info =
471 + trait_defaults.iter().find(|t| t.key == sigdate.event);
444 472
445 473 if let Some(trait_def) = trait_info {
446 474 println!(
@@ -468,10 +496,16 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
468 496 }
469 497 }
470 498 } else {
471 − debug!("DEBUG: Days until this year ({}) is outside delta window (0 to {})", days_until, delta);
499 + debug!(
500 + "DEBUG: Days until this year ({}) is outside delta window (0 to {})",
501 + days_until, delta
502 + );
472 503 }
473 504 } else {
474 − debug!("DEBUG: Could not calculate anniversary for {}", sigdate.date);
505 + debug!(
506 + "DEBUG: Could not calculate anniversary for {}",
507 + sigdate.date
508 + );
475 509 }
476 510 } else {
477 511 debug!("DEBUG: No tier delta found for this sigdate");
@@ -479,7 +513,9 @@ async fn motd(db: &DatabaseConnection) -> Result<(), PplError> {
479 513 }
480 514
481 515 // Update person's meta field with last_reminded if we showed them and remind_enum is OnlyOnce
482 − if showed_sigdate && (remind_enum_value.is_none() || remind_enum_value.as_deref() == Some("OnlyOnce")) {
516 + if showed_sigdate
517 + && (remind_enum_value.is_none() || remind_enum_value.as_deref() == Some("OnlyOnce"))
518 + {
483 519 use sea_orm::ActiveValue::Set;
484 520
485 521 let today_str = today.format("%Y-%m-%d").to_string();
modified src/migrator/m20260116_000010_add_sig_date_delta_to_tier.rs
+2 −10
@@ -17,11 +17,7 @@ impl MigrationTrait for Migration {
17 17 .alter_table(
18 18 Table::alter()
19 19 .table(Tier::Table)
20 − .add_column(
21 − ColumnDef::new(Tier::SigDateDelta)
22 − .unsigned()
23 − .null(),
24 − )
20 + .add_column(ColumnDef::new(Tier::SigDateDelta).unsigned().null())
25 21 .to_owned(),
26 22 )
27 23 .await?;
@@ -30,11 +26,7 @@ impl MigrationTrait for Migration {
30 26 .alter_table(
31 27 Table::alter()
32 28 .table(Tier::Table)
33 − .add_column(
34 − ColumnDef::new(Tier::SigRemindEnum)
35 − .string()
36 − .null(),
37 − )
29 + .add_column(ColumnDef::new(Tier::SigRemindEnum).string().null())
38 30 .to_owned(),
39 31 )
40 32 .await
modified src/migrator/m20260116_000011_add_sig_date_delta_to_tier_defaults.rs
+2 −10
@@ -17,11 +17,7 @@ impl MigrationTrait for Migration {
17 17 .alter_table(
18 18 Table::alter()
19 19 .table(TierDefaults::Table)
20 − .add_column(
21 − ColumnDef::new(TierDefaults::SigDateDelta)
22 − .unsigned()
23 − .null(),
24 − )
20 + .add_column(ColumnDef::new(TierDefaults::SigDateDelta).unsigned().null())
25 21 .to_owned(),
26 22 )
27 23 .await?;
@@ -30,11 +26,7 @@ impl MigrationTrait for Migration {
30 26 .alter_table(
31 27 Table::alter()
32 28 .table(TierDefaults::Table)
33 − .add_column(
34 − ColumnDef::new(TierDefaults::SigRemindEnum)
35 − .string()
36 − .null(),
37 − )
29 + .add_column(ColumnDef::new(TierDefaults::SigRemindEnum).string().null())
38 30 .to_owned(),
39 31 )
40 32 .await
modified src/migrator/m20260116_000012_add_meta_to_ppl.rs
+1 −5
@@ -17,11 +17,7 @@ impl MigrationTrait for Migration {
17 17 .alter_table(
18 18 Table::alter()
19 19 .table(Ppl::Table)
20 − .add_column(
21 − ColumnDef::new(Ppl::Meta)
22 − .json_binary()
23 − .null(),
24 − )
20 + .add_column(ColumnDef::new(Ppl::Meta).json_binary().null())
25 21 .to_owned(),
26 22 )
27 23 .await

Parents: 5624b4a