package router import ( "fmt" "strings" "time" ) // CalendarEventFormatter formats calendar events into a Russian reply string. type CalendarEventFormatter struct{} // CalendarEntry — one event to recite. Uncertain marks an event maven did not // read off a calendar server: the work calendar arrives as relayed phone // notifications (Vikunja #126), stored below full confidence, and she says so // rather than reciting a guess as fact. type CalendarEntry struct { Text string Uncertain bool } // Format returns a Russian reply for the given calendar events on the given // date. Every event is treated as certain — use FormatEntries when provenance // differs between them. func (f CalendarEventFormatter) Format(events []string, date time.Time) string { entries := make([]CalendarEntry, len(events)) for i, e := range events { entries[i] = CalendarEntry{Text: e} } return f.FormatEntries(entries, date) } // FormatEntries returns a Russian reply, hedging the entries maven is not sure // about. "похоже" and not "возможно": the notification did arrive, what is // uncertain is whether it describes the meeting correctly. func (CalendarEventFormatter) FormatEntries(entries []CalendarEntry, date time.Time) string { dateStr := date.Format("02.01.2006") if len(entries) == 0 { return fmt.Sprintf("на %s ничего нет.", dateStr) } parts := make([]string, len(entries)) for i, e := range entries { if e.Uncertain { parts[i] = "похоже, " + e.Text continue } parts[i] = e.Text } return fmt.Sprintf("на %s: %s", dateStr, strings.Join(parts, "; ")) }