diff --git a/example.json b/example.json index 0876118..a25b06b 100644 --- a/example.json +++ b/example.json @@ -11,11 +11,7 @@ }, "environment": { "luck_today": 0.9, - "luck_history": [ - 0.9, - 0.9, - 0.9 - ], + "luck_history": [0.9, 0.9, 0.9], "level": 1 }, "messaging": { @@ -25,7 +21,9 @@ "templates": [ "おはよう!今日もがんばろう!", "ねえ、話したいことがあるの。" - ] + ], + "sent_today": false, + "last_sent_date": null }, "last_interaction": "2025-05-21T23:15:00Z", "memory": { diff --git a/src/commands/scheduler.rs b/src/commands/scheduler.rs index 78cccaa..8028dee 100644 --- a/src/commands/scheduler.rs +++ b/src/commands/scheduler.rs @@ -19,6 +19,21 @@ fn send_scheduled_message() { return; } + // 日付の比較(1日1回制限) + let today = Local::now().format("%Y-%m-%d").to_string(); + if let Some(last_date) = &user.messaging.last_sent_date { + if last_date != &today { + user.messaging.sent_today = false; + } + } else { + user.messaging.sent_today = false; + } + + if user.messaging.sent_today { + println!("🔁 本日はすでに送信済みです: {}", today); + return; + } + if let Some(schedule_str) = &user.messaging.schedule_time { let now = Local::now(); let target: Vec<&str> = schedule_str.split(':').collect(); @@ -36,12 +51,19 @@ fn send_scheduled_message() { let dummy_context = Context::new(vec![], None, "".to_string()); ask_chat(&dummy_context, msg); user.metrics.intimacy += 0.03; + + // 送信済みのフラグ更新 + user.messaging.sent_today = true; + user.messaging.last_sent_date = Some(today); + save_user_data(&user_path, &user); } } } } } + + pub fn scheduler_cmd() -> Command { Command::new("scheduler") .usage("scheduler [interval_sec]") @@ -96,7 +118,7 @@ pub fn scheduler_cmd() -> Command { user.metrics.energy ); } - + save_user_data(&user_path, &user); thread::sleep(Duration::from_secs(interval)); } diff --git a/src/metrics.rs b/src/metrics.rs index 54c743b..0ef592c 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -42,6 +42,8 @@ pub struct Messaging { pub schedule_time: Option, pub decay_rate: f32, pub templates: Vec, + pub sent_today: bool, // 追加 + pub last_sent_date: Option, // 追加 } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -103,6 +105,8 @@ pub fn load_user_data(path: &Path) -> UserData { "おはよう!今日もがんばろう!".to_string(), "ねえ、話したいことがあるの。".to_string(), ], + sent_today: false, + last_sent_date: None, }, last_interaction: Utc::now(), memory: Memory {