mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-10 16:08:13 -06:00
Defer idle connection closing, seed random location selection with user ID & moving interval
This commit is contained in:
12
main.go
12
main.go
@@ -76,10 +76,12 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I
|
|||||||
var choices []*discordgo.ApplicationCommandOptionChoice
|
var choices []*discordgo.ApplicationCommandOptionChoice
|
||||||
|
|
||||||
if data.Options[0].Focused {
|
if data.Options[0].Focused {
|
||||||
locations := GetLocations()
|
// Seed value is based on the user ID + a 15 minute interval)
|
||||||
log.Printf("%d location%s provided", len(locations), Plural(len(locations)))
|
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)
|
||||||
|
|
||||||
choices = make([]*discordgo.ApplicationCommandOptionChoice, min(len(locations), 25))
|
choices = make([]*discordgo.ApplicationCommandOptionChoice, len(locations))
|
||||||
for i, location := range locations {
|
for i, location := range locations {
|
||||||
choices[i] = &discordgo.ApplicationCommandOptionChoice{
|
choices[i] = &discordgo.ApplicationCommandOptionChoice{
|
||||||
Name: location.name,
|
Name: location.name,
|
||||||
@@ -154,6 +156,8 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Cannot open the session: %v", err)
|
log.Fatalf("Cannot open the session: %v", err)
|
||||||
}
|
}
|
||||||
|
defer session.Close()
|
||||||
|
defer client.CloseIdleConnections()
|
||||||
|
|
||||||
session.AddHandler(func(internalSession *discordgo.Session, interaction *discordgo.InteractionCreate) {
|
session.AddHandler(func(internalSession *discordgo.Session, interaction *discordgo.InteractionCreate) {
|
||||||
if handler, ok := commandHandlers[interaction.ApplicationCommandData().Name]; ok {
|
if handler, ok := commandHandlers[interaction.ApplicationCommandData().Name]; ok {
|
||||||
@@ -171,8 +175,6 @@ func main() {
|
|||||||
registeredCommands[definitionIndex] = command
|
registeredCommands[definitionIndex] = command
|
||||||
}
|
}
|
||||||
|
|
||||||
defer session.Close()
|
|
||||||
|
|
||||||
tryReload("")
|
tryReload("")
|
||||||
|
|
||||||
stop := make(chan os.Signal, 1)
|
stop := make(chan os.Signal, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user