Setup StoreCode operations in command

This commit is contained in:
2023-12-12 03:11:21 -06:00
parent 4da78a9bab
commit c34f390051

View File

@@ -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{},
}, },
}, },