Use SubmissionContexts global to inform RegisterVehicle call params

This commit is contained in:
2024-02-28 04:11:15 -06:00
parent 43f1ca8fa2
commit ed931d0df8
+34 -4
View File
@@ -1,6 +1,8 @@
package main package main
import ( import (
"strconv"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/samber/lo" "github.com/samber/lo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -28,12 +30,40 @@ func RegisterModalHandler(session *discordgo.Session, interaction *discordgo.Int
return inner.CustomID, inner return inner.CustomID, inner
}) })
email := dataByCustomID["email"].(*discordgo.TextInput).Value log.Infof("dataByCustomID: %+v", dataByCustomID)
log.Infof("Email: %s", email) // email := dataByCustomID["email"].(*discordgo.TextInput).Value
// Collect the form parameters provided by the user
formParams := map[string]string{}
for fieldName, component := range dataByCustomID {
// Email is a special case, it's not part of the form
if fieldName == "email" {
continue
}
formParams[fieldName] = component.(*discordgo.TextInput).Value
}
// The ID of the original interaction is used as the identifier for the registration context (uint64)
registerIdentifier, parseErr := strconv.ParseUint(interaction.ID, 10, 64)
if parseErr != nil {
HandleError(session, interaction, parseErr, "Error occurred while parsing interaction message identifier")
}
// Get the context that we stored prior to emitting the modal
context := SubmissionContexts.GetValue(registerIdentifier).(*RegisterContext)
// Register the vehicle
result, err := RegisterVehicle(formParams, context.propertyId, context.residentId, context.hiddenKeys)
if err != nil {
HandleError(session, interaction, err, "Failed to register vehicle")
return
}
log.Infof("RegisterVehicle result: %+v", result)
// TODO: Submit registration request to API
// TODO: Edit response to indicate success/failure // TODO: Edit response to indicate success/failure
// TODO: On success, provide a button to submit email confirmation
// TODO: Validate license plate // TODO: Validate license plate
// session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{ // session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{