Fix #2: ical calendar: take 'cancelled' status into account #4

Closed
Sybren A. Stüvel wants to merge 3 commits from fix/2-handle-cancelled-events into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit 4cc88710e9 - Show all commits

View File

@ -5,6 +5,7 @@ package chatbot
import (
"context"
"fmt"
"log/slog"
"strings"
"time"
@ -49,21 +50,35 @@ func (pn *PeriodicNotifier) Run(ctx context.Context, channel chan<- time.Time) {
select {
case <-ctx.Done():
return
case <-time.After(1 * time.Minute):
pn.checkAndNotify(channel)
case <-time.After(20 * time.Second):
pn.checkAndNotify(log, channel)
}
}
}
func (pn *PeriodicNotifier) checkAndNotify(channel chan<- time.Time) {
nextMeetingTime := pn.meetingTimeSource.NextMeetingTime().UTC()
func (pn *PeriodicNotifier) checkAndNotify(log *slog.Logger, channel chan<- time.Time) {
now := pn.clock.Now().UTC()
if pn.lastCheckTime.IsZero() {
// Never checked before, so just remember that this was the first time, and
// don't notify. We should only notify about stuff that happens while we're
// running, otherwise a restart of the bot will always trigger a notification.
pn.lastCheckTime = now
return
}
nextMeetingTime := pn.meetingTimeSource.NextMeetingTime().UTC()
shouldNotify := false
for _, duration := range pn.durations {
notifTime := nextMeetingTime.Add(-duration)
if pn.lastCheckTime.Before(notifTime) && (now == notifTime || now.After(notifTime)) {
log.Info("periodic notifier: notification should get sent",
"lastCheck", pn.lastCheckTime,
"notifTime", notifTime,
"timeUntilMeeting", duration,
)
shouldNotify = true
break
}
@ -79,11 +94,19 @@ func (pn *PeriodicNotifier) checkAndNotify(channel chan<- time.Time) {
}
func SendMeetingTimeNotification(ctx context.Context, client *mautrix.Client, roomID id.RoomID, timeOfMeeting time.Time) {
timeUntilMeeting := time.Until(timeOfMeeting).Round(time.Minute)
log := GetBotLog(ctx)
// The main info: how long until the next meeting.
hours := int(timeUntilMeeting.Truncate(time.Hour).Hours())
minutes := int(timeUntilMeeting.Truncate(time.Minute).Minutes()) % 60
timeUntilMeeting := time.Until(timeOfMeeting)
hours := int(timeUntilMeeting.Round(time.Minute).Truncate(time.Hour).Hours())
minutes := int(timeUntilMeeting.Round(time.Minute).Minutes()) % 60
log.Info("sending meeting time notification",
"meetingTime", timeOfMeeting.UTC(),
"timeUntilMeeting", timeUntilMeeting,
"hours", hours,
"minutes", minutes,
)
firstLine := "The next module meeting will be in **"
switch {