From d18ba1fa8b89098e9f0ece8b9991130fb8d29edd Mon Sep 17 00:00:00 2001 From: Khinshan Khan Date: Sun, 9 Mar 2025 11:11:54 -0400 Subject: [PATCH] immediately send first message and optimize loop --- cmd/bot/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/bot/main.go b/cmd/bot/main.go index 474f1eb..54c1a46 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -118,10 +118,9 @@ func readyHandler(s *discordgo.Session, r *discordgo.Ready) { // startScheduler handles sending messages at intervals func startScheduler(s *discordgo.Session, channelID string) { - for { - randomDuration := time.Duration(rand.Intn(SendMessageIntervalMin)+(SendMessageIntervalMax-SendMessageIntervalMin)) * SendMessageUnit - log.Printf("[!] Next message in %v", randomDuration) + randomDuration := 0 * time.Second + for { // Wait for the randomized time before sending a message time.Sleep(randomDuration) sendMessage(praises[praiseIndex%len(praises)], s, channelID) @@ -134,6 +133,9 @@ func startScheduler(s *discordgo.Session, channelID string) { go deleteMessageAfterDelay(discordMessage, s, channelID) } + + randomDuration = time.Duration(rand.Intn(SendMessageIntervalMin)+(SendMessageIntervalMax-SendMessageIntervalMin)) * SendMessageUnit + log.Printf("[!] Next message in %v", randomDuration) } }