mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-07 20:08:02 -06:00
Setup StoreCode operations in command
This commit is contained in:
13
commands.go
13
commands.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -34,13 +35,19 @@ func CodeCommandHandler(session *discordgo.Session, interaction *discordgo.Inter
|
|||||||
case discordgo.InteractionApplicationCommand:
|
case discordgo.InteractionApplicationCommand:
|
||||||
data := interaction.ApplicationCommandData()
|
data := interaction.ApplicationCommandData()
|
||||||
|
|
||||||
location := data.Options[0].IntValue()
|
location_id, _ := strconv.Atoi(data.Options[0].StringValue())
|
||||||
code := data.Options[1].StringValue()
|
code := data.Options[1].StringValue()
|
||||||
user_id, _ := strconv.Atoi(interaction.Member.User.ID)
|
user_id, _ := strconv.Atoi(interaction.Member.User.ID)
|
||||||
|
|
||||||
// TODO: Validate that the location exists
|
// TODO: Validate that the location exists
|
||||||
// TODO: Validate that the code has no invalid characters
|
// TODO: Validate that the code has no invalid characters
|
||||||
StoreCode(code, location, user_id)
|
already_set := StoreCode(code, int64(location_id), user_id)
|
||||||
|
responseText := "Your guest code at %d has been set."
|
||||||
|
if already_set {
|
||||||
|
responseText = "Your guest code %d has been updated."
|
||||||
|
}
|
||||||
|
|
||||||
|
location := cachedLocationsMap[uint(location_id)]
|
||||||
|
|
||||||
session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
@@ -50,7 +57,7 @@ func CodeCommandHandler(session *discordgo.Session, interaction *discordgo.Inter
|
|||||||
Footer: &discordgo.MessageEmbedFooter{
|
Footer: &discordgo.MessageEmbedFooter{
|
||||||
Text: GetFooterText(),
|
Text: GetFooterText(),
|
||||||
},
|
},
|
||||||
Description: "Your guest code has been registered.",
|
Description: fmt.Sprintf(responseText, location.name),
|
||||||
Fields: []*discordgo.MessageEmbedField{},
|
Fields: []*discordgo.MessageEmbedField{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user