mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-10 06:08:12 -06:00
Remove reload func name arg, add log/comment
This commit is contained in:
6
api.go
6
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.
|
// 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
|
||||||
}
|
}
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user