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
62 changes: 20 additions & 42 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"log"
"math/rand"
_ "net/http/pprof"
"os"
"os/signal"
Expand All @@ -21,6 +20,7 @@ import (
"github.com/mkmccarty/TokenTimeBoostBot/src/boost"
"github.com/mkmccarty/TokenTimeBoostBot/src/bottools"
"github.com/mkmccarty/TokenTimeBoostBot/src/config"
"github.com/mkmccarty/TokenTimeBoostBot/src/ei"
"github.com/mkmccarty/TokenTimeBoostBot/src/events"
"github.com/mkmccarty/TokenTimeBoostBot/src/farmerstate"
"github.com/mkmccarty/TokenTimeBoostBot/src/menno"
Expand All @@ -32,6 +32,7 @@ import (
)

const configFileName = "./.config.json"
const statusMessagesFileName = "./ttbb-data/status-messages.json"

// Admin Slash Command Constants
// const boostBotHomeGuild string = "766330702689992720"
Expand Down Expand Up @@ -137,6 +138,9 @@ func init() {
// For the daemon Log
fmt.Printf("Starting Discord Bot: %s (%s) at %s\n", version.Release, Version, time.Now().Format(time.RFC3339))

// Load status messages
ei.LoadStatusMessages(statusMessagesFileName)

// Read application parameters
flag.Parse()

Expand Down Expand Up @@ -1076,12 +1080,16 @@ func main() {
}
log.Println("event:", event)
if event.Has(fsnotify.Write) {
if event.Name == configFileName {
switch event.Name {
case configFileName:
log.Println("modified file:", event.Name)
err := config.ReadConfig(event.Name)
if err != nil {
log.Println(err.Error())
}
case statusMessagesFileName:
log.Println("modified file:", event.Name)
ei.LoadStatusMessages(event.Name)
}
}
case err, ok := <-watcher.Errors:
Expand All @@ -1098,6 +1106,11 @@ func main() {
log.Fatal(err)
}

err = watcher.Add(statusMessagesFileName)
if err != nil {
log.Printf("Warning: Could not watch status messages file: %v", err)
}

stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)
log.Println("Press Ctrl+C to exit")
Expand Down Expand Up @@ -1141,48 +1154,13 @@ func startHeartbeat(filepath string, interval time.Duration) {
}
counter++
if counter%2 == 1 {
// 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",
"Browsing contracts",
"Boosting production",
"Consuming artifacts",
"Petting chickens",
"Adjusting Shells",
"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",
"Cuddling my chickens",
"Waiting for faster missions",
"Crafting deflectors",
"Organizing contract signups",
"Planning my virtue shift",
"Complaining about token luck",
"Causing confusion & delay",
"Laying eggs",
"Blaming Tbone",
"Just another Tbone alt",
// Get a random status message
activityName, err := ei.GetRandomStatusMessage()
if err != nil {
log.Printf("Error getting status message: %v", err)
activityName = "Egg, Inc."
}

// Randomly choose between showing contract count or a funny phrase
activityName := funnyPhrases[rand.Intn(len(funnyPhrases))]

err = s.UpdateStatusComplex(discordgo.UpdateStatusData{
AFK: false,
Activities: []*discordgo.Activity{
Expand Down
58 changes: 58 additions & 0 deletions src/ei/status_messages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ei

import (
"encoding/json"
"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.

The import uses math/rand (v1) while the rest of the codebase has migrated to math/rand/v2. This is inconsistent with the pattern used in src/tasks/tasks.go (line 7), src/boost/boost.go (line 10), src/boost/boost_admin.go (line 9), src/boost/contract.go (line 7), and src/boost/roles.go (line 7), which all use math/rand/v2.

Using the v2 API is recommended for Go 1.22+ as it provides better random number generation and doesn't require manual seeding. Change the import to use math/rand/v2 for consistency with the rest of the codebase.

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

Copilot uses AI. Check for mistakes.
"os"
"sync"
)

// StatusMessagesFile is a struct to hold the status messages
type StatusMessagesFile struct {
StatusMessages []string `json:"status_messages"`
}

// StatusMessages is a list of status messages
var StatusMessages []string
var statusMessagesMutex sync.RWMutex

// LoadStatusMessages loads status messages from a JSON file
func LoadStatusMessages(filename string) {
file, err := os.Open(filename)
if err != nil {
log.Printf("Failed to open status messages file: %v", err)
return
}
defer func() {
if err := file.Close(); err != nil {
log.Printf("Failed to close: %v", err)
}
}()

var messagesLoaded StatusMessagesFile
decoder := json.NewDecoder(file)
if err := decoder.Decode(&messagesLoaded); err != nil {
log.Printf("Failed to decode status messages: %v", err)
return
Comment on lines +25 to +38
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 handling in LoadStatusMessages differs from the similar LoadTokenComplaints function in the same package (src/ei/token_complaints.go, line 28). LoadTokenComplaints uses log.Fatal when the file cannot be opened, which ensures the application doesn't continue with missing data during startup. LoadStatusMessages logs the error and returns, which could result in an empty StatusMessages slice.

Since both functions are called during initialization (main.go line 142 and tasks.go line 366), consider using log.Fatal for consistency, or document why the different behavior is intentional. If status messages are optional, this should be clearly indicated.

Suggested change
log.Printf("Failed to open status messages file: %v", err)
return
}
defer func() {
if err := file.Close(); err != nil {
log.Printf("Failed to close: %v", err)
}
}()
var messagesLoaded StatusMessagesFile
decoder := json.NewDecoder(file)
if err := decoder.Decode(&messagesLoaded); err != nil {
log.Printf("Failed to decode status messages: %v", err)
return
log.Fatalf("Failed to open status messages file %q: %v", filename, err)
}
defer func() {
if err := file.Close(); err != nil {
log.Printf("Failed to close status messages file %q: %v", filename, err)
}
}()
var messagesLoaded StatusMessagesFile
decoder := json.NewDecoder(file)
if err := decoder.Decode(&messagesLoaded); err != nil {
log.Fatalf("Failed to decode status messages from file %q: %v", filename, err)

Copilot uses AI. Check for mistakes.
}

statusMessagesMutex.Lock()
StatusMessages = messagesLoaded.StatusMessages
statusMessagesMutex.Unlock()

log.Printf("Loaded %d status messages", len(messagesLoaded.StatusMessages))
}

// GetRandomStatusMessage returns a random status message
func GetRandomStatusMessage() (string, error) {
statusMessagesMutex.RLock()
defer statusMessagesMutex.RUnlock()

if len(StatusMessages) == 0 {
return "", fmt.Errorf("StatusMessages is empty")
}

return StatusMessages[rand.Intn(len(StatusMessages))], nil
}
9 changes: 9 additions & 0 deletions src/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const eggIncEiResearchesFile string = "ttbb-data/ei-researches.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"

const eggIncStatusMessagesURL string = "https://raw.githubusercontent.com/mkmccarty/TokenTimeBoostBot/refs/heads/main/data/status-messages.json"
const eggIncStatusMessagesFile string = "ttbb-data/status-messages.json"

var lastContractUpdate time.Time
var lastEventUpdate time.Time

Expand Down Expand Up @@ -313,6 +316,8 @@ func downloadEggIncData(url string, filename string) bool {
ei.LoadResearchData(filename)
case eggIncTokenComplaintsFile:
ei.LoadTokenComplaints(filename)
case eggIncStatusMessagesFile:
ei.LoadStatusMessages(filename)
}
/*else if filename == eggIncEiAfxConfigFile {
ei.LoadConfig(filename)
Expand Down Expand Up @@ -357,6 +362,10 @@ func ExecuteCronJob(s *discordgo.Session) {
ei.LoadTokenComplaints(eggIncTokenComplaintsFile)
}

if !downloadEggIncData(eggIncStatusMessagesURL, eggIncStatusMessagesFile) {
ei.LoadStatusMessages(eggIncStatusMessagesFile)
}

events.GetPeriodicalsFromAPI(s)

/*
Expand Down
Loading