|
|
|
@ -524,33 +524,30 @@ func main() {
|
|
|
|
|
cancel()
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return
|
|
|
|
|
case <-notifChan:
|
|
|
|
|
absentees, err := store.GetAbsentees(ctx, themis.NextMonday())
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error().Err(err).Msg("failed to get absentees for next session")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
go notifier.NotifyFunc(ctx, func() {
|
|
|
|
|
absentees, err := store.GetAbsentees(ctx, themis.NextMonday())
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error().Err(err).Msg("failed to get absentees for next session")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var msg string
|
|
|
|
|
if len(absentees) == 0 {
|
|
|
|
|
msg = "Everybody can make it next Monday, see you then!"
|
|
|
|
|
} else {
|
|
|
|
|
msg = fmt.Sprintf("%s can't make it next Monday.", strings.Join(absentees, ", "))
|
|
|
|
|
}
|
|
|
|
|
for i, a := range absentees {
|
|
|
|
|
a = fmt.Sprintf("<@%s>", a)
|
|
|
|
|
absentees[i] = a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = discord.ChannelMessageSend(channelId, msg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error().Err(err).Msg("failed to send scheduled notification")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
time.Sleep(5 * time.Minute)
|
|
|
|
|
var msg string
|
|
|
|
|
if len(absentees) == 0 {
|
|
|
|
|
msg = "Everybody can make it next Monday, see you then!"
|
|
|
|
|
} else {
|
|
|
|
|
msg = fmt.Sprintf("%s can't make it next Monday.", themis.FormatStringSlice(absentees))
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
_, err = discord.ChannelMessageSend(channelId, msg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error().Err(err).Msg("failed to send scheduled notification")
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
<-ctx.Done()
|
|
|
|
|
log.Info().Msg("context cancelled, exiting")
|
|
|
|
|