Remove reload func name arg, add log/comment

This commit is contained in:
2023-12-15 06:44:39 -06:00
parent b5ee5bec0c
commit b3b19a8a99
2 changed files with 8 additions and 4 deletions

6
api.go
View File

@@ -43,7 +43,7 @@ func onResponse(res *http.Response) {
// Reloads the current session and completes the initial connection process that procedes bot operations. // Reloads the current session and completes the initial connection process that procedes bot operations.
// This should be done regularly, such as after 10 requests or 15 minutes. // This should be done regularly, such as after 10 requests or 15 minutes.
func reload(name string) { func reload() {
// Ring the doorbell // Ring the doorbell
req := BuildRequest("GET", "/", nil) req := BuildRequest("GET", "/", nil)
onRequest(req) onRequest(req)
@@ -74,7 +74,7 @@ func reload(name string) {
// Attempts to reload the current session based on a given location's name. // Attempts to reload the current session based on a given location's name.
// This uses the current request counter and last reload time to determine if a reload is necessary. // This uses the current request counter and last reload time to determine if a reload is necessary.
func tryReload(name string) { func tryReload() {
currentTime := time.Now().Unix() currentTime := time.Now().Unix()
lastReloadDiff := currentTime - lastReload lastReloadDiff := currentTime - lastReload
@@ -86,7 +86,7 @@ func tryReload(name string) {
return return
} }
reload(name) reload()
lastReload = currentTime lastReload = currentTime
requestCounter = 0 requestCounter = 0
} }

View File

@@ -53,6 +53,8 @@ func Bot() {
if err != nil { if err != nil {
log.Fatalf("Cannot open the session: %v", err) log.Fatalf("Cannot open the session: %v", err)
} }
// Make sure sessions and HTTP clients are closed
defer session.Close() defer session.Close()
defer client.CloseIdleConnections() // HTTP client defer client.CloseIdleConnections() // HTTP client
@@ -72,6 +74,8 @@ func Bot() {
registeredCommands := make([]*discordgo.ApplicationCommand, len(commandDefinitions)) registeredCommands := make([]*discordgo.ApplicationCommand, len(commandDefinitions))
for definitionIndex, commandDefinition := range commandDefinitions { for definitionIndex, commandDefinition := range commandDefinitions {
command, err := session.ApplicationCommandCreate(session.State.User.ID, os.Getenv("BOT_TARGET_GUILD"), commandDefinition) command, err := session.ApplicationCommandCreate(session.State.User.ID, os.Getenv("BOT_TARGET_GUILD"), commandDefinition)
log.Debugf("Registering '%v' command (%v)", commandDefinition.Name, command.ID)
if err != nil { if err != nil {
log.Panicf("Failed while registering '%v' command: %v", commandDefinition.Name, err) log.Panicf("Failed while registering '%v' command: %v", commandDefinition.Name, err)
} }
@@ -79,7 +83,7 @@ func Bot() {
} }
// Load the session // Load the session
tryReload("") tryReload()
// Wait here until CTRL-C or other term signal is received. // Wait here until CTRL-C or other term signal is received.
log.Println("Press Ctrl+C to exit") log.Println("Press Ctrl+C to exit")