Begin switching over to modal-based dynamic fields

This commit is contained in:
2023-12-17 06:05:27 -06:00
parent 5b4da7b0c3
commit 8597308f7c
2 changed files with 117 additions and 36 deletions

62
form.go Normal file
View File

@@ -0,0 +1,62 @@
package main
import "github.com/bwmarrin/discordgo"
// FormToComponents converts the form requested into usable modal components.
func FormToComponents(form GetFormResult) []discordgo.MessageComponent {
components := make([]discordgo.MessageComponent, 0, 3)
for _, field := range form.fields {
var component discordgo.TextInput
switch field.id {
case "vehicleApt":
component = discordgo.TextInput{
CustomID: "vehicleApt",
Label: "Apartment Number",
Style: discordgo.TextInputShort,
Required: true,
MinLength: 1,
MaxLength: 5,
}
case "vehicleMake":
component = discordgo.TextInput{
CustomID: "vehicleMake",
Label: "Make",
Placeholder: "Honda",
Style: discordgo.TextInputShort,
Required: true,
MinLength: 4,
MaxLength: 15,
}
case "vehicleModel":
component = discordgo.TextInput{
CustomID: "vehicleModel",
Label: "Model",
Style: discordgo.TextInputShort,
Placeholder: "Accord",
Required: true,
MinLength: 1,
MaxLength: 16,
}
case "vehicleLicensePlate":
component = discordgo.TextInput{
CustomID: "vehicleLicensePlate",
Label: "License Plate",
Placeholder: "ABC123",
Style: discordgo.TextInputShort,
Required: true,
MinLength: 1,
MaxLength: 9,
}
components = append(components, discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
component,
},
})
}
}
return components
}