feat(schedule): 优化日程提示并增加时间感知能力

日程系统现在可以更详细地描述当前活动,包括计划的起止时间、已进行时间和剩余时间,为AI角色提供更强的时间感知和情境感。

主要变更:
- `schedule_manager`的`get_current_activity`现在返回包含活动和时间范围的字典,而不仅仅是活动名称。
- 在`default_generator`中,重构了日程提示的生成逻辑,使其能够计算并展示活动的详细时间信息。
- 修复了多处可能因变量为空(如`msg_content`、`user_nickname`)或事件处理结果为`None`而引发的潜在错误。
- 统一了各处对日程信息的调用方式。
This commit is contained in:
minecraft1024a
2025-10-12 12:57:48 +08:00
committed by Windpicker-owo
parent b7392ffea3
commit 28b56fc0b4
3 changed files with 73 additions and 29 deletions

View File

@@ -147,7 +147,7 @@ class ScheduleManager:
schedule_str += f" - {item.get('time_range', '未知时间')}: {item.get('activity', '未知活动')}\n"
logger.info(schedule_str)
def get_current_activity(self) -> str | None:
def get_current_activity(self) -> dict[str, Any] | None:
if not global_config.planning_system.schedule_enable or not self.today_schedule:
return None
now = datetime.now().time()
@@ -161,7 +161,7 @@ class ScheduleManager:
start_time = datetime.strptime(start_str.strip(), "%H:%M").time()
end_time = datetime.strptime(end_str.strip(), "%H:%M").time()
if (start_time <= now < end_time) or (end_time < start_time and (now >= start_time or now < end_time)):
return activity
return {"activity": activity, "time_range": time_range}
except (ValueError, KeyError, AttributeError) as e:
logger.warning(f"解析日程事件失败: {event}, 错误: {e}")
return None