From 937c436023a9f8b0504a6fb700bfeaedc6c7d5c9 Mon Sep 17 00:00:00 2001 From: Michael McCarty Date: Thu, 2 Apr 2026 13:02:05 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feat:=20pass=20encrypted=5Fe=5Fid=20co?= =?UTF-8?q?op=20status=20calls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/boost/boost_menu.go | 2 +- src/boost/boost_reactions.go | 8 ++++---- src/boost/boost_speedrun.go | 2 +- src/boost/contract_report.go | 3 ++- src/boost/estimate_scores.go | 4 +++- src/boost/stones.go | 8 +++++--- src/boost/stones_pages.go | 4 +++- src/boost/teamwork.go | 8 +++++--- src/boost/teamwork_pages.go | 4 +++- src/track/track_update.go | 8 +++++--- 10 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/boost/boost_menu.go b/src/boost/boost_menu.go index 20ae6350..cb9dea41 100644 --- a/src/boost/boost_menu.go +++ b/src/boost/boost_menu.go @@ -143,7 +143,7 @@ func HandleMenuReactions(s *discordgo.Session, i *discordgo.InteractionCreate) { }, }) contract.EstimateUpdateTime = time.Now() - go updateEstimatedTime(s, i.ChannelID, contract, false) + go updateEstimatedTime(s, i.ChannelID, contract, false, i.Member.User.ID) case "want": message := "**%s** wants at least 1 more token." contract.Boosters[i.Member.User.ID].TokenRequestFlag = !contract.Boosters[i.Member.User.ID].TokenRequestFlag diff --git a/src/boost/boost_reactions.go b/src/boost/boost_reactions.go index 78db4b06..198275e8 100644 --- a/src/boost/boost_reactions.go +++ b/src/boost/boost_reactions.go @@ -170,7 +170,7 @@ func ReactionAdd(s *discordgo.Session, r *discordgo.MessageReaction) string { } else { log.Print("Updating estimated time") contract.EstimateUpdateTime = time.Now() - go updateEstimatedTime(s, r.ChannelID, contract, true) + go updateEstimatedTime(s, r.ChannelID, contract, true, r.UserID) } } case "🐓": @@ -245,9 +245,9 @@ func ReactionAdd(s *discordgo.Session, r *discordgo.MessageReaction) string { return returnVal } -func updateEstimatedTime(s *discordgo.Session, channelID string, contract *Contract, displayMsg bool) { +func updateEstimatedTime(s *discordgo.Session, channelID string, contract *Contract, displayMsg bool, userID string) { if !displayMsg { - startTime, contractDurationSeconds, err := track.DownloadCoopStatusTracker(contract.ContractID, contract.CoopID) + startTime, contractDurationSeconds, err := track.DownloadCoopStatusTracker(contract.ContractID, contract.CoopID, userID) if err == nil { contract.StartTime = startTime contract.EstimatedDuration = time.Duration(contractDurationSeconds) * time.Second @@ -260,7 +260,7 @@ func updateEstimatedTime(s *discordgo.Session, channelID string, contract *Contr data.Content = "⏱️ reaction received, updating contract duration." data.Flags = discordgo.MessageFlagsEphemeral msg, msgErr := s.ChannelMessageSendComplex(channelID, &data) - startTime, contractDurationSeconds, err := track.DownloadCoopStatusTracker(contract.ContractID, contract.CoopID) + startTime, contractDurationSeconds, err := track.DownloadCoopStatusTracker(contract.ContractID, contract.CoopID, userID) if err == nil { if msgErr == nil { _ = s.ChannelMessageDelete(msg.ChannelID, msg.ID) diff --git a/src/boost/boost_speedrun.go b/src/boost/boost_speedrun.go index e1147a91..f08f938f 100644 --- a/src/boost/boost_speedrun.go +++ b/src/boost/boost_speedrun.go @@ -377,7 +377,7 @@ func speedrunReactions(s *discordgo.Session, r *discordgo.MessageReaction, contr } else { log.Print("Updating estimated time") contract.EstimateUpdateTime = time.Now() - go updateEstimatedTime(s, r.ChannelID, contract, true) + go updateEstimatedTime(s, r.ChannelID, contract, true, r.UserID) } } } diff --git a/src/boost/contract_report.go b/src/boost/contract_report.go index 846615be..776bda67 100644 --- a/src/boost/contract_report.go +++ b/src/boost/contract_report.go @@ -452,7 +452,8 @@ func ContractReport( // Get coop status; validate response // Using GetCoopStatusForCompletedContracts to ensure we cache completed contract data locally - coopStatus, nowTime, _, err := ei.GetCoopStatusForCompletedContracts(contractID, coopID, "") + callerEIID := farmerstate.GetMiscSettingString(callerUserID, "encrypted_ei_id") + coopStatus, nowTime, _, err := ei.GetCoopStatusForCompletedContracts(contractID, coopID, callerEIID) if err != nil { return fmt.Errorf("%w: %v", ErrCoopStatusFetch, err) } diff --git a/src/boost/estimate_scores.go b/src/boost/estimate_scores.go index 52336874..773e36dc 100644 --- a/src/boost/estimate_scores.go +++ b/src/boost/estimate_scores.go @@ -235,7 +235,9 @@ func runCsEstimate(s *discordgo.Session, i *discordgo.InteractionCreate, p csEst } // Get coopStatus with the given contractID and coopID - str, fields, contractScore := DownloadCoopStatusTeamwork(contractID, coopID, true) + userID := bottools.GetInteractionUserID(i) + eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id") + str, fields, contractScore := DownloadCoopStatusTeamwork(contractID, coopID, true, eiID) if fields == nil || strings.HasSuffix(str, "no such file or directory") || strings.HasPrefix(str, "No grade found") { _, sendErr := s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{ Flags: p.flags, diff --git a/src/boost/stones.go b/src/boost/stones.go index caa08c78..3c391f40 100644 --- a/src/boost/stones.go +++ b/src/boost/stones.go @@ -150,7 +150,8 @@ func HandleStonesCommand(s *discordgo.Session, i *discordgo.InteractionCreate) { coopID = strings.ToLower(contract.CoopID) } - s1, urls, tiles := DownloadCoopStatusStones(contractID, coopID, details, soloName, useBuffHistory) + eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id") + s1, urls, tiles := DownloadCoopStatusStones(contractID, coopID, details, soloName, useBuffHistory, eiID) contract := FindContractByIDs(contractID, coopID) if contract != nil { @@ -166,6 +167,7 @@ func HandleStonesCommand(s *discordgo.Session, i *discordgo.InteractionCreate) { // Fill in our calling parameters cache.contractID = contractID cache.coopID = coopID + cache.eiID = eiID cache.details = details cache.soloName = soloName cache.private = privateReply @@ -247,11 +249,11 @@ type artifactSet struct { } // DownloadCoopStatusStones will download the coop status for a given contract and coop ID -func DownloadCoopStatusStones(contractID string, coopID string, details bool, soloName string, useBuffHistory bool) (string, string, []*discordgo.MessageEmbedField) { +func DownloadCoopStatusStones(contractID string, coopID string, details bool, soloName string, useBuffHistory bool, eeidOverride string) (string, string, []*discordgo.MessageEmbedField) { var builderURL strings.Builder var field []*discordgo.MessageEmbedField - coopStatus, _, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, "") + coopStatus, _, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, eeidOverride) if err != nil { return err.Error(), "", field } diff --git a/src/boost/stones_pages.go b/src/boost/stones_pages.go index f07a68c1..7b074f62 100644 --- a/src/boost/stones_pages.go +++ b/src/boost/stones_pages.go @@ -81,13 +81,14 @@ func sendStonesPage(s *discordgo.Session, i *discordgo.InteractionCreate, newMes if exists && (refresh || cache.expirationTimestamp.Before(time.Now())) { - s1, urls, tiles := DownloadCoopStatusStones(cache.contractID, cache.coopID, cache.details, cache.soloName, cache.useBuffHistory) + s1, urls, tiles := DownloadCoopStatusStones(cache.contractID, cache.coopID, cache.details, cache.soloName, cache.useBuffHistory, cache.eiID) newCache := buildStonesCache(s1, urls, tiles) newCache.private = cache.private newCache.xid = cache.xid newCache.contractID = cache.contractID newCache.coopID = cache.coopID + newCache.eiID = cache.eiID newCache.details = cache.details newCache.soloName = cache.soloName newCache.useBuffHistory = cache.useBuffHistory @@ -359,6 +360,7 @@ type stonesCache struct { expirationTimestamp time.Time contractID string coopID string + eiID string details bool soloName string useBuffHistory bool diff --git a/src/boost/teamwork.go b/src/boost/teamwork.go index c11e8295..5cd4b200 100644 --- a/src/boost/teamwork.go +++ b/src/boost/teamwork.go @@ -172,8 +172,9 @@ func HandleTeamworkEvalCommand(s *discordgo.Session, i *discordgo.InteractionCre coopID = strings.ToLower(contract.CoopID) } + eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id") var str string - str, fields, _ := DownloadCoopStatusTeamwork(contractID, coopID, true) + str, fields, _ := DownloadCoopStatusTeamwork(contractID, coopID, true, eiID) if fields == nil || strings.HasSuffix(str, "no such file or directory") || strings.HasPrefix(str, "No grade found") { // Trim output to 3500 characters if needed trimmedStr := str @@ -198,6 +199,7 @@ func HandleTeamworkEvalCommand(s *discordgo.Session, i *discordgo.InteractionCre // Fill in our calling parameters cache.contractID = contractID cache.coopID = coopID + cache.eiID = eiID cache.public = publicReply cache.showScores = scoresFirst if eggign != "" { @@ -224,7 +226,7 @@ func HandleTeamworkEvalCommand(s *discordgo.Session, i *discordgo.InteractionCre } // DownloadCoopStatusTeamwork will download the coop status for a given contract and coop ID -func DownloadCoopStatusTeamwork(contractID string, coopID string, setContractEstimate bool) (string, map[string][]TeamworkOutputData, ContractScore) { +func DownloadCoopStatusTeamwork(contractID string, coopID string, setContractEstimate bool, eeidOverride string) (string, map[string][]TeamworkOutputData, ContractScore) { var dataTimestampStr string var nowTime time.Time @@ -275,7 +277,7 @@ func DownloadCoopStatusTeamwork(contractID string, coopID string, setContractEst return fmt.Sprintf("Filenames:\n%s", strings.Join(fileNames, "\n")), nil, ContractScore{} } - coopStatus, nowTime, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, "") + coopStatus, nowTime, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, eeidOverride) if err != nil { return err.Error(), nil, ContractScore{} } diff --git a/src/boost/teamwork_pages.go b/src/boost/teamwork_pages.go index 644d32e8..c74fcd0a 100644 --- a/src/boost/teamwork_pages.go +++ b/src/boost/teamwork_pages.go @@ -24,6 +24,7 @@ type teamworkCache struct { expirationTimestamp time.Time contractID string coopID string + eiID string public bool names []string fields map[string][]TeamworkOutputData @@ -91,7 +92,7 @@ func sendTeamworkPage(s *discordgo.Session, i *discordgo.InteractionCreate, newM if exists && (refresh || cache.expirationTimestamp.Before(time.Now())) { - s1, fields, _ := DownloadCoopStatusTeamwork(cache.contractID, cache.coopID, true) + s1, fields, _ := DownloadCoopStatusTeamwork(cache.contractID, cache.coopID, true, cache.eiID) newCache := buildTeamworkCache(s1, fields) newCache.public = cache.public @@ -99,6 +100,7 @@ func sendTeamworkPage(s *discordgo.Session, i *discordgo.InteractionCreate, newM newCache.xid = cache.xid newCache.contractID = cache.contractID newCache.coopID = cache.coopID + newCache.eiID = cache.eiID newCache.page = cache.page newCache.showScores = cache.showScores if refresh { diff --git a/src/track/track_update.go b/src/track/track_update.go index bc0acce9..f2649ef5 100644 --- a/src/track/track_update.go +++ b/src/track/track_update.go @@ -7,6 +7,7 @@ import ( "github.com/bwmarrin/discordgo" "github.com/mkmccarty/TokenTimeBoostBot/src/ei" + "github.com/mkmccarty/TokenTimeBoostBot/src/farmerstate" ) // HandleTrackerRefresh will call the API and update the start time and duration @@ -37,7 +38,7 @@ func HandleTrackerRefresh(s *discordgo.Session, i *discordgo.InteractionCreate) // Update the tracker with new values t, err := getTrack(userID, name) if err == nil { - startTime, contractDurationSeconds, err := DownloadCoopStatusTracker(t.ContractID, t.CoopID) + startTime, contractDurationSeconds, err := DownloadCoopStatusTracker(t.ContractID, t.CoopID, userID) if err != nil { errorStr := fmt.Sprintf("Error: %s, check your coop-id", err) _, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{ @@ -60,7 +61,7 @@ func HandleTrackerRefresh(s *discordgo.Session, i *discordgo.InteractionCreate) } // DownloadCoopStatusTracker will download the coop status for a given contract and coop ID -func DownloadCoopStatusTracker(contractID string, coopID string) (time.Time, float64, error) { +func DownloadCoopStatusTracker(contractID string, coopID string, userID string) (time.Time, float64, error) { nowTime := time.Now() eiContract := ei.EggIncContractsAll[contractID] @@ -68,7 +69,8 @@ func DownloadCoopStatusTracker(contractID string, coopID string) (time.Time, flo return time.Time{}, 0, fmt.Errorf("invalid contract ID") } - coopStatus, _, _, err := ei.GetCoopStatus(contractID, coopID, "") + eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id") + coopStatus, _, _, err := ei.GetCoopStatus(contractID, coopID, eiID) if err != nil { return time.Time{}, 0, err }