mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-07 18:07:57 -06:00
Begin switching over to modal-based dynamic fields
This commit is contained in:
62
form.go
Normal file
62
form.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user