package loop import ( "fmt" "log/slog" "time" "git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model" ) // weekdaysCN 把 time.Weekday(0=周日)映射为中文星期标签。 var weekdaysCN = [...]string{"周日", "周一", "周二", "周三", "周四", "周五", "周六"} // loadTimezone 把配置的 IANA 时区解析为 *time.Location,供每轮 // 时间注入使用。空名(或加载失败的名字)返回 nil, // 从而完全关闭注入(向后兼容,优雅降级)。 func loadTimezone(name string, log *slog.Logger) (*time.Location, string) { if name == "" { return nil, "" } loc, err := time.LoadLocation(name) if err != nil { log.Warn("timezone load failed; time injection disabled", "tz", name, "error", err) return nil, "" } return loc, name } // currentTimeBlock 渲染一条每轮「当前时间」系统消息,使模型 // 每轮都知道墙上时钟时间(而非首轮快照)。它仅在配置了 // 时区时由 assembleContext 调用。它只提供原始时钟 —— // 是否「夜深该睡了」是人格提示词的职责,不是这里的 // 硬编码规则。 func (l *Loop) currentTimeBlock() model.Message { now := time.Now().In(l.timeLocation) text := fmt.Sprintf("当前时间:%s %s,时区 %s", now.Format("2006-01-02 15:04"), weekdaysCN[now.Weekday()], l.timeZoneName, ) return model.TextMessage(model.RoleSystem, text) }