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": { "environment": {
"luck_today": 0.9, "luck_today": 0.9,
"luck_history": [ "luck_history": [0.9, 0.9, 0.9],
0.9,
0.9,
0.9
],
"level": 1 "level": 1
}, },
"messaging": { "messaging": {
@ -25,7 +21,9 @@
"templates": [ "templates": [
"おはよう!今日もがんばろう!", "おはよう!今日もがんばろう!",
"ねえ、話したいことがあるの。" "ねえ、話したいことがあるの。"
] ],
"sent_today": false,
"last_sent_date": null
}, },
"last_interaction": "2025-05-21T23:15:00Z", "last_interaction": "2025-05-21T23:15:00Z",
"memory": { "memory": {

View File

@ -19,6 +19,21 @@ fn send_scheduled_message() {
return; 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 { if let Some(schedule_str) = &user.messaging.schedule_time {
let now = Local::now(); let now = Local::now();
let target: Vec<&str> = schedule_str.split(':').collect(); 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()); let dummy_context = Context::new(vec![], None, "".to_string());
ask_chat(&dummy_context, msg); ask_chat(&dummy_context, msg);
user.metrics.intimacy += 0.03; user.metrics.intimacy += 0.03;
// 送信済みのフラグ更新
user.messaging.sent_today = true;
user.messaging.last_sent_date = Some(today);
save_user_data(&user_path, &user); save_user_data(&user_path, &user);
} }
} }
} }
} }
} }
pub fn scheduler_cmd() -> Command { pub fn scheduler_cmd() -> Command {
Command::new("scheduler") Command::new("scheduler")
.usage("scheduler [interval_sec]") .usage("scheduler [interval_sec]")

View File

@ -42,6 +42,8 @@ pub struct Messaging {
pub schedule_time: Option<String>, pub schedule_time: Option<String>,
pub decay_rate: f32, pub decay_rate: f32,
pub templates: Vec<String>, pub templates: Vec<String>,
pub sent_today: bool, // 追加
pub last_sent_date: Option<String>, // 追加
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -103,6 +105,8 @@ pub fn load_user_data(path: &Path) -> UserData {
"おはよう!今日もがんばろう!".to_string(), "おはよう!今日もがんばろう!".to_string(),
"ねえ、話したいことがあるの。".to_string(), "ねえ、話したいことがあるの。".to_string(),
], ],
sent_today: false,
last_sent_date: None,
}, },
last_interaction: Utc::now(), last_interaction: Utc::now(),
memory: Memory { memory: Memory {