Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 58 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"log"
"math/rand"
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "math/rand/v2" instead of "math/rand" to be consistent with the rest of the codebase. All other files in the project that use random numbers import "math/rand/v2", including src/boost/boost.go, src/boost/boost_admin.go, src/boost/contract.go, src/boost/roles.go, and src/tasks/tasks.go. The v2 package provides better defaults and doesn't require manual seeding.

Suggested change
"math/rand"
"math/rand/v2"

Copilot uses AI. Check for mistakes.
_ "net/http/pprof"
"os"
"os/signal"
Expand Down Expand Up @@ -1029,7 +1030,7 @@ func main() {
AFK: false,
Activities: []*discordgo.Activity{
{
Name: "Egg, Inc.",
Name: "Syncing...",
Type: discordgo.ActivityTypeGame,
},
},
Expand Down Expand Up @@ -1118,10 +1119,6 @@ func getIntentUserID(i *discordgo.InteractionCreate) string {

// Heartbeat function to update the modification time of a file at regular intervals
func startHeartbeat(filepath string, interval time.Duration) {
if config.IsDevBot() {
return

}
go func() {
// Create the file if it doesn't exist
if _, err := os.Stat(filepath); os.IsNotExist(err) {
Expand All @@ -1133,6 +1130,7 @@ func startHeartbeat(filepath string, interval time.Duration) {
_ = f.Close()
}

counter := 0
ticker := time.NewTicker(interval)
for range ticker.C {
currentTime := time.Now()
Expand All @@ -1141,6 +1139,61 @@ func startHeartbeat(filepath string, interval time.Duration) {
if err != nil {
log.Printf("Heartbeat error: %v", err)
}
counter++
if counter%2 == 0 {
// Funny phrases related to Egg, Inc.
funnyPhrases := []string{
"Hatching chickens",
"Shipping eggs",
"Upgrading silos",
"Building habs",
"Swiping drones",
"Launching rockets",
"Counting my Golden Eggs",
"Prestiging",
"Counting chickens",
"Running chickens",
"Tapping silos",
"Researching eggs",
"Cracking contracts",
"Boosting production",
"Consuming artifacts",
"Petting chickens",
"Waiting on my next TE",
"Calculating optimal boosts",
"Watching my Egg, Inc. empire grow",
"Collecting daily rewards",
"Checking for new contracts",
"Optimizing my farm layout",
"Jiggling artifacts",
"Setting completion alarms",
}
Comment on lines +1145 to +1170
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The funnyPhrases slice is recreated on every heartbeat tick (every 2 minutes when counter is even). This is inefficient as it allocates a new slice with 25 strings repeatedly. Consider moving this slice to package-level scope or outside the ticker loop to improve performance and reduce unnecessary allocations.

Copilot uses AI. Check for mistakes.

// Randomly choose between showing contract count or a funny phrase
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Randomly choose between showing contract count or a funny phrase" but the code always shows a funny phrase - there's no logic to show contract count. Either update the comment to match the actual behavior or implement the contract count display logic as the comment suggests.

Suggested change
// Randomly choose between showing contract count or a funny phrase
// Randomly choose a funny status phrase

Copilot uses AI. Check for mistakes.
activityName := funnyPhrases[rand.Intn(len(funnyPhrases))]

err = s.UpdateStatusComplex(discordgo.UpdateStatusData{
AFK: false,
Activities: []*discordgo.Activity{
{
Name: activityName,
Type: discordgo.ActivityTypeGame,
},
},
Status: string(discordgo.StatusOnline),
})
if err != nil {
log.Printf("Heartbeat error: %v", err)
err := s.Close()
if err != nil {
log.Fatalf("Cannot close the session: %v", err)
}
err = s.Open()
if err != nil {
log.Fatalf("Cannot open the session: %v", err)
Comment on lines +1186 to +1193
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error recovery logic here is problematic. When UpdateStatusComplex fails, the code attempts to close and reopen the Discord session using log.Fatalf(), which will terminate the entire application. This is too aggressive for a heartbeat function that runs in a goroutine. If a status update fails, it shouldn't crash the entire bot. Consider either removing this recovery logic entirely and just logging the error, or implementing a more graceful reconnection strategy without using log.Fatalf().

Suggested change
log.Printf("Heartbeat error: %v", err)
err := s.Close()
if err != nil {
log.Fatalf("Cannot close the session: %v", err)
}
err = s.Open()
if err != nil {
log.Fatalf("Cannot open the session: %v", err)
log.Printf("Heartbeat error updating status: %v", err)
if cerr := s.Close(); cerr != nil {
log.Printf("Heartbeat error closing session after status failure: %v", cerr)
}
if oerr := s.Open(); oerr != nil {
log.Printf("Heartbeat error reopening session after status failure: %v", oerr)

Copilot uses AI. Check for mistakes.
}
}
}
}
}()
}
11 changes: 1 addition & 10 deletions src/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ const eggIncEiAfxConfigFile string = "ttbb-data/ei-afx-config.json"
const eggIncEiResearchesURL string = "https://raw.githubusercontent.com/mkmccarty/TokenTimeBoostBot/refs/heads/main/data/ei-researches.json"
const eggIncEiResearchesFile string = "ttbb-data/ei-researches.json"

//const eggIncEiAfxConfigURL string = "https://raw.githubusercontent.com/carpetsage/egg/main/wasmegg/_common/eiafx/eiafx-config.json"
//const eggIncEiAfxConfigFile string = "ttbb-data/eiafx-config.json"

const eggIncTokenComplaintsURL string = "https://raw.githubusercontent.com/mkmccarty/TokenTimeBoostBot/refs/heads/main/data/token-complaints.json"
const eggIncTokenComplaintsFile string = "ttbb-data/token-complaints.json"

Expand Down Expand Up @@ -343,6 +340,7 @@ func ExecuteCronJob(s *discordgo.Session) {
ei.LoadEventData(eggIncEventsFile)
}
downloadEggIncData(eggIncDataSchemaURL, eggIncDataSchemaFile)
downloadEggIncData(eggIncEiAfxConfigURL, eggIncEiAfxConfigFile)

if !downloadEggIncData(eggIncEiAfxDataURL, eggIncEiAfxDataFile) {
err := ei.LoadArtifactsData(eggIncEiAfxDataFile)
Expand All @@ -351,13 +349,6 @@ func ExecuteCronJob(s *discordgo.Session) {
}
}

if !downloadEggIncData(eggIncEiAfxConfigURL, eggIncEiAfxConfigFile) {
err := ei.LoadArtifactsData(eggIncEiAfxConfigFile)
if err != nil {
log.Print(err)
}
}

if !downloadEggIncData(eggIncEiResearchesURL, eggIncEiResearchesFile) {
ei.LoadResearchData(eggIncEiResearchesFile)
}
Expand Down
Loading