Embed commit id into footer at compile time, use switch for autocomplete focus flow

This commit is contained in:
2023-12-12 02:07:49 -06:00
parent bd461217a0
commit 933c1c6892
2 changed files with 32 additions and 6 deletions

View File

@@ -1,7 +1,6 @@
package main
import (
"fmt"
"strconv"
"time"
@@ -49,7 +48,7 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I
Embeds: []*discordgo.MessageEmbed{
{
Footer: &discordgo.MessageEmbedFooter{
Text: fmt.Sprintf("Fetched at %s", time.Now().Format("Monday, January 2, 2006 at 3:04:05PM")),
Text: GetFooterText(),
},
Description: "",
Fields: []*discordgo.MessageEmbedField{},
@@ -60,15 +59,20 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I
})
case discordgo.InteractionApplicationCommandAutocomplete:
data := interaction.ApplicationCommandData()
var choices []*discordgo.ApplicationCommandOptionChoice
if data.Options[0].Focused {
LocationOption := data.Options[0]
MakeOption := data.Options[1]
ModelOption := data.Options[2]
switch {
case LocationOption.Focused:
// Seed value is based on the user ID + a 15 minute interval)
user_id, _ := strconv.Atoi(interaction.Member.User.ID)
seed_value := int64(user_id) + (time.Now().Unix() / 15 * 60)
locations := FilterLocations(GetLocations(), data.Options[0].StringValue(), 25, seed_value)
// Convert the locations to choices
choices = make([]*discordgo.ApplicationCommandOptionChoice, len(locations))
for i, location := range locations {
choices[i] = &discordgo.ApplicationCommandOptionChoice{
@@ -76,8 +80,9 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I
Value: strconv.Itoa(int(location.id)),
}
}
} else {
choices = []*discordgo.ApplicationCommandOptionChoice{}
case MakeOption.Focused:
case ModelOption.Focused:
}
err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{

View File

@@ -7,7 +7,9 @@ import (
"math/rand"
"net/http"
"reflect"
"runtime/debug"
"strings"
"time"
)
const baseURL = "https://www.register2park.com"
@@ -138,3 +140,22 @@ func FilterLocations(all_locations []Location, query string, limit int, seed_val
return filtered_locations
}
// The commit ID from the Git repository. Only valid at build time, but is compiled into the binary.
var CommitId = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return strings.Repeat("gubed", 8) // 40 characters
}()
func GetFooterText() string {
return fmt.Sprintf("Fetched at %s @%s",
time.Now().Format("Monday, January 2, 2006 at 3:04:05PM"),
strings.ToLower(CommitId[:7]))
}