1
0

test scheduler send limit

This commit is contained in:
syui 2025-05-22 18:17:47 +09:00
parent 7aa633d3a6
commit 52d0efc086
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
3 changed files with 31 additions and 7 deletions

View File

@ -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": {

View File

@ -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));
}

View File

@ -42,6 +42,8 @@ pub struct Messaging {
pub schedule_time: Option<String>,
pub decay_rate: f32,
pub templates: Vec<String>,
pub sent_today: bool, // 追加
pub last_sent_date: Option<String>, // 追加
}
#[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 {