mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-07 07:16:01 -06:00
Embed commit id into footer at compile time, use switch for autocomplete focus flow
This commit is contained in:
17
commands.go
17
commands.go
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I
|
|||||||
Embeds: []*discordgo.MessageEmbed{
|
Embeds: []*discordgo.MessageEmbed{
|
||||||
{
|
{
|
||||||
Footer: &discordgo.MessageEmbedFooter{
|
Footer: &discordgo.MessageEmbedFooter{
|
||||||
Text: fmt.Sprintf("Fetched at %s", time.Now().Format("Monday, January 2, 2006 at 3:04:05PM")),
|
Text: GetFooterText(),
|
||||||
},
|
},
|
||||||
Description: "",
|
Description: "",
|
||||||
Fields: []*discordgo.MessageEmbedField{},
|
Fields: []*discordgo.MessageEmbedField{},
|
||||||
@@ -60,15 +59,20 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I
|
|||||||
})
|
})
|
||||||
case discordgo.InteractionApplicationCommandAutocomplete:
|
case discordgo.InteractionApplicationCommandAutocomplete:
|
||||||
data := interaction.ApplicationCommandData()
|
data := interaction.ApplicationCommandData()
|
||||||
|
|
||||||
var choices []*discordgo.ApplicationCommandOptionChoice
|
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)
|
// Seed value is based on the user ID + a 15 minute interval)
|
||||||
user_id, _ := strconv.Atoi(interaction.Member.User.ID)
|
user_id, _ := strconv.Atoi(interaction.Member.User.ID)
|
||||||
seed_value := int64(user_id) + (time.Now().Unix() / 15 * 60)
|
seed_value := int64(user_id) + (time.Now().Unix() / 15 * 60)
|
||||||
locations := FilterLocations(GetLocations(), data.Options[0].StringValue(), 25, seed_value)
|
locations := FilterLocations(GetLocations(), data.Options[0].StringValue(), 25, seed_value)
|
||||||
|
|
||||||
|
// Convert the locations to choices
|
||||||
choices = make([]*discordgo.ApplicationCommandOptionChoice, len(locations))
|
choices = make([]*discordgo.ApplicationCommandOptionChoice, len(locations))
|
||||||
for i, location := range locations {
|
for i, location := range locations {
|
||||||
choices[i] = &discordgo.ApplicationCommandOptionChoice{
|
choices[i] = &discordgo.ApplicationCommandOptionChoice{
|
||||||
@@ -76,8 +80,9 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I
|
|||||||
Value: strconv.Itoa(int(location.id)),
|
Value: strconv.Itoa(int(location.id)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
case MakeOption.Focused:
|
||||||
choices = []*discordgo.ApplicationCommandOptionChoice{}
|
|
||||||
|
case ModelOption.Focused:
|
||||||
}
|
}
|
||||||
|
|
||||||
err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
||||||
|
|||||||
21
helpers.go
21
helpers.go
@@ -7,7 +7,9 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const baseURL = "https://www.register2park.com"
|
const baseURL = "https://www.register2park.com"
|
||||||
@@ -138,3 +140,22 @@ func FilterLocations(all_locations []Location, query string, limit int, seed_val
|
|||||||
|
|
||||||
return filtered_locations
|
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]))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user