diff --git a/api.go b/api.go index d6b3975..9446b87 100644 --- a/api.go +++ b/api.go @@ -43,7 +43,7 @@ func onResponse(res *http.Response) { // 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. -func reload(name string) { +func reload() { // Ring the doorbell req := BuildRequest("GET", "/", nil) onRequest(req) @@ -74,7 +74,7 @@ func reload(name string) { // 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. -func tryReload(name string) { +func tryReload() { currentTime := time.Now().Unix() lastReloadDiff := currentTime - lastReload @@ -86,7 +86,7 @@ func tryReload(name string) { return } - reload(name) + reload() lastReload = currentTime requestCounter = 0 } diff --git a/main.go b/main.go index 62c15f8..af72c02 100644 --- a/main.go +++ b/main.go @@ -53,6 +53,8 @@ func Bot() { if err != nil { log.Fatalf("Cannot open the session: %v", err) } + + // Make sure sessions and HTTP clients are closed defer session.Close() defer client.CloseIdleConnections() // HTTP client @@ -72,6 +74,8 @@ func Bot() { registeredCommands := make([]*discordgo.ApplicationCommand, len(commandDefinitions)) for definitionIndex, commandDefinition := range commandDefinitions { 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 { log.Panicf("Failed while registering '%v' command: %v", commandDefinition.Name, err) } @@ -79,7 +83,7 @@ func Bot() { } // Load the session - tryReload("") + tryReload() // Wait here until CTRL-C or other term signal is received. log.Println("Press Ctrl+C to exit")