|
|
|
@ -501,6 +501,7 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
// flush is a special command that triggers a modal confirmation
|
|
|
|
|
"flush": func(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
|
|
|
|
baggage := make(url.Values)
|
|
|
|
|
propagator.Inject(ctx, correlation.UrlValuesCarrier(baggage))
|
|
|
|
@ -581,7 +582,7 @@ func main() {
|
|
|
|
|
},
|
|
|
|
|
"schedule": func(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
|
|
|
|
// get schedule from now to 4 wednesdays into the future
|
|
|
|
|
sched, err := store.GetSchedule(ctx, themis.NextOfWeekday(nil, themis.ScheduledGameDay), themis.NextOfWeekday(nil, themis.ScheduledGameDay).Add(4*7*24*time.Hour))
|
|
|
|
|
sched, err := store.GetSchedule(ctx, themis.NextOfWeekday(themis.ScheduledGameDay, time.Now()), themis.NextOfWeekday(themis.ScheduledGameDay, time.Now()).Add(4*7*24*time.Hour))
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
|
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
|
|
@ -643,7 +644,7 @@ func main() {
|
|
|
|
|
"absent": func(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
|
|
|
|
var rawDate string
|
|
|
|
|
if len(i.ApplicationCommandData().Options) == 0 {
|
|
|
|
|
rawDate = themis.NextOfWeekday(nil, themis.ScheduledGameDay).Format(time.DateOnly)
|
|
|
|
|
rawDate = themis.NextOfWeekday(themis.ScheduledGameDay, time.Now()).Format(time.DateOnly)
|
|
|
|
|
} else {
|
|
|
|
|
rawDate = i.ApplicationCommandData().Options[0].StringValue()
|
|
|
|
|
}
|
|
|
|
@ -739,7 +740,7 @@ func main() {
|
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
|
|
log.Info().Msg("sending weekly reminder")
|
|
|
|
|
absentees, err := store.GetAbsentees(ctx, themis.NextOfWeekday(nil, themis.ScheduledGameDay))
|
|
|
|
|
absentees, err := store.GetAbsentees(ctx, themis.NextOfWeekday(themis.ScheduledGameDay, time.Now()))
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error().Err(err).Msg("failed to get absentees for next session")
|
|
|
|
|
return
|
|
|
|
@ -806,6 +807,7 @@ func touchDbFile(path string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// registerHandlers registers the handlers for the discord session
|
|
|
|
|
func registerHandlers(sess *discordgo.Session, handlers map[string]Handler) {
|
|
|
|
|
sess.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
|
|
|
|
|
log.Info().Str("user_id", fmt.Sprintf("%s#%s", s.State.User.Username, s.State.User.Discriminator)).Msg("logged in")
|
|
|
|
@ -884,7 +886,7 @@ func registerHandlers(sess *discordgo.Session, handlers map[string]Handler) {
|
|
|
|
|
userId := i.Member.User.ID
|
|
|
|
|
log.Info().Ctx(ctx).Str("message_component", "schedule-response").Str("userid", userId).Msg("handling message component interaction")
|
|
|
|
|
|
|
|
|
|
if err := store.AddAbsence(ctx, themis.NextOfWeekday(nil, themis.ScheduledGameDay), userId); err != nil {
|
|
|
|
|
if err := store.AddAbsence(ctx, themis.NextOfWeekday(themis.ScheduledGameDay, time.Now()), userId); err != nil {
|
|
|
|
|
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
|
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
|
|
|
Data: &discordgo.InteractionResponseData{
|
|
|
|
|