|
|
@ -188,6 +188,12 @@ func main() {
|
|
|
|
Description: "Get the schedule for the following weeks.",
|
|
|
|
Description: "Get the schedule for the following weeks.",
|
|
|
|
Type: discordgo.ChatApplicationCommand,
|
|
|
|
Type: discordgo.ChatApplicationCommand,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name: "send-schedule",
|
|
|
|
|
|
|
|
Description: "Trigger the scheduled message. Admins only",
|
|
|
|
|
|
|
|
Type: discordgo.ChatApplicationCommand,
|
|
|
|
|
|
|
|
DefaultMemberPermissions: new(int64), // default 0 == admins only
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name: "absent",
|
|
|
|
Name: "absent",
|
|
|
|
Description: "Mark yourself as absent for a session",
|
|
|
|
Description: "Mark yourself as absent for a session",
|
|
|
@ -561,6 +567,18 @@ func main() {
|
|
|
|
log.Error().Err(err).Msg("failed to respond to interaction")
|
|
|
|
log.Error().Err(err).Msg("failed to respond to interaction")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
"send-schedule": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
|
|
|
|
|
|
notifier.Send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
|
|
|
|
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
|
|
|
|
|
|
Data: &discordgo.InteractionResponseData{
|
|
|
|
|
|
|
|
Content: "Done.",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}); err != nil {
|
|
|
|
|
|
|
|
log.Error().Err(err).Msg("failed to respond to interaction")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
"absent": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
|
|
"absent": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
|
|
var rawDate string
|
|
|
|
var rawDate string
|
|
|
|
if len(i.ApplicationCommandData().Options) == 0 {
|
|
|
|
if len(i.ApplicationCommandData().Options) == 0 {
|
|
|
@ -661,13 +679,28 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var msg string
|
|
|
|
var msg string
|
|
|
|
|
|
|
|
var components []discordgo.MessageComponent
|
|
|
|
if len(absentees) == 0 {
|
|
|
|
if len(absentees) == 0 {
|
|
|
|
msg = "Everybody can make it next Monday, see you then!"
|
|
|
|
msg = "Everybody can make it next Monday, see you then!"
|
|
|
|
|
|
|
|
components = []discordgo.MessageComponent{
|
|
|
|
|
|
|
|
discordgo.ActionsRow{
|
|
|
|
|
|
|
|
Components: []discordgo.MessageComponent{
|
|
|
|
|
|
|
|
discordgo.Button{
|
|
|
|
|
|
|
|
CustomID: "schedule-response",
|
|
|
|
|
|
|
|
Label: "I Can't Make It",
|
|
|
|
|
|
|
|
Style: discordgo.DangerButton,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
msg = fmt.Sprintf("%s can't make it next Monday. :sad:", themis.FormatStringSlice(absentees))
|
|
|
|
msg = fmt.Sprintf("%s can't make it next Monday. :sad:", themis.FormatStringSlice(absentees))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_, err = discord.ChannelMessageSend(channelId, msg)
|
|
|
|
_, err = discord.ChannelMessageSendComplex(channelId, &discordgo.MessageSend{
|
|
|
|
|
|
|
|
Content: msg,
|
|
|
|
|
|
|
|
Components: components,
|
|
|
|
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("failed to send scheduled notification")
|
|
|
|
log.Error().Err(err).Msg("failed to send scheduled notification")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -743,6 +776,32 @@ func registerHandlers(sess *discordgo.Session, handlers map[string]Handler) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case discordgo.InteractionMessageComponent:
|
|
|
|
|
|
|
|
switch i.MessageComponentData().CustomID {
|
|
|
|
|
|
|
|
case "schedule-response":
|
|
|
|
|
|
|
|
userId := i.Member.User.ID
|
|
|
|
|
|
|
|
if err := store.AddAbsence(context.TODO(), themis.NextMonday(), userId); err != nil {
|
|
|
|
|
|
|
|
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
|
|
|
|
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
|
|
|
|
|
|
Data: &discordgo.InteractionResponseData{
|
|
|
|
|
|
|
|
Content: "something went wrong recording your absence, check logs for more info.",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}); err != nil {
|
|
|
|
|
|
|
|
log.Error().Err(err).Msg("failed to respond to interaction")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
|
|
|
|
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
|
|
|
|
|
|
Data: &discordgo.InteractionResponseData{
|
|
|
|
|
|
|
|
Content: fmt.Sprintf("Looks like <@%s> can't make it after all.", userId),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error().Err(err).Msg("failed to respond to interaction")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|