Skip to content

Commit c59143e

Browse files
authored
Merge pull request #2304 from mkmccarty/mm-branch-3
✨feat: pass encrypted_e_id coop status calls
2 parents c84a67c + 937c436 commit c59143e

10 files changed

Lines changed: 32 additions & 19 deletions

src/boost/boost_menu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func HandleMenuReactions(s *discordgo.Session, i *discordgo.InteractionCreate) {
143143
},
144144
})
145145
contract.EstimateUpdateTime = time.Now()
146-
go updateEstimatedTime(s, i.ChannelID, contract, false)
146+
go updateEstimatedTime(s, i.ChannelID, contract, false, i.Member.User.ID)
147147
case "want":
148148
message := "**%s** wants at least 1 more token."
149149
contract.Boosters[i.Member.User.ID].TokenRequestFlag = !contract.Boosters[i.Member.User.ID].TokenRequestFlag

src/boost/boost_reactions.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func ReactionAdd(s *discordgo.Session, r *discordgo.MessageReaction) string {
170170
} else {
171171
log.Print("Updating estimated time")
172172
contract.EstimateUpdateTime = time.Now()
173-
go updateEstimatedTime(s, r.ChannelID, contract, true)
173+
go updateEstimatedTime(s, r.ChannelID, contract, true, r.UserID)
174174
}
175175
}
176176
case "🐓":
@@ -245,9 +245,9 @@ func ReactionAdd(s *discordgo.Session, r *discordgo.MessageReaction) string {
245245
return returnVal
246246
}
247247

248-
func updateEstimatedTime(s *discordgo.Session, channelID string, contract *Contract, displayMsg bool) {
248+
func updateEstimatedTime(s *discordgo.Session, channelID string, contract *Contract, displayMsg bool, userID string) {
249249
if !displayMsg {
250-
startTime, contractDurationSeconds, err := track.DownloadCoopStatusTracker(contract.ContractID, contract.CoopID)
250+
startTime, contractDurationSeconds, err := track.DownloadCoopStatusTracker(contract.ContractID, contract.CoopID, userID)
251251
if err == nil {
252252
contract.StartTime = startTime
253253
contract.EstimatedDuration = time.Duration(contractDurationSeconds) * time.Second
@@ -260,7 +260,7 @@ func updateEstimatedTime(s *discordgo.Session, channelID string, contract *Contr
260260
data.Content = "⏱️ reaction received, updating contract duration."
261261
data.Flags = discordgo.MessageFlagsEphemeral
262262
msg, msgErr := s.ChannelMessageSendComplex(channelID, &data)
263-
startTime, contractDurationSeconds, err := track.DownloadCoopStatusTracker(contract.ContractID, contract.CoopID)
263+
startTime, contractDurationSeconds, err := track.DownloadCoopStatusTracker(contract.ContractID, contract.CoopID, userID)
264264
if err == nil {
265265
if msgErr == nil {
266266
_ = s.ChannelMessageDelete(msg.ChannelID, msg.ID)

src/boost/boost_speedrun.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func speedrunReactions(s *discordgo.Session, r *discordgo.MessageReaction, contr
377377
} else {
378378
log.Print("Updating estimated time")
379379
contract.EstimateUpdateTime = time.Now()
380-
go updateEstimatedTime(s, r.ChannelID, contract, true)
380+
go updateEstimatedTime(s, r.ChannelID, contract, true, r.UserID)
381381
}
382382
}
383383
}

src/boost/contract_report.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ func ContractReport(
452452

453453
// Get coop status; validate response
454454
// Using GetCoopStatusForCompletedContracts to ensure we cache completed contract data locally
455-
coopStatus, nowTime, _, err := ei.GetCoopStatusForCompletedContracts(contractID, coopID, "")
455+
callerEIID := farmerstate.GetMiscSettingString(callerUserID, "encrypted_ei_id")
456+
coopStatus, nowTime, _, err := ei.GetCoopStatusForCompletedContracts(contractID, coopID, callerEIID)
456457
if err != nil {
457458
return fmt.Errorf("%w: %v", ErrCoopStatusFetch, err)
458459
}

src/boost/estimate_scores.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ func runCsEstimate(s *discordgo.Session, i *discordgo.InteractionCreate, p csEst
235235
}
236236

237237
// Get coopStatus with the given contractID and coopID
238-
str, fields, contractScore := DownloadCoopStatusTeamwork(contractID, coopID, true)
238+
userID := bottools.GetInteractionUserID(i)
239+
eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id")
240+
str, fields, contractScore := DownloadCoopStatusTeamwork(contractID, coopID, true, eiID)
239241
if fields == nil || strings.HasSuffix(str, "no such file or directory") || strings.HasPrefix(str, "No grade found") {
240242
_, sendErr := s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
241243
Flags: p.flags,

src/boost/stones.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ func HandleStonesCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
150150
coopID = strings.ToLower(contract.CoopID)
151151
}
152152

153-
s1, urls, tiles := DownloadCoopStatusStones(contractID, coopID, details, soloName, useBuffHistory)
153+
eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id")
154+
s1, urls, tiles := DownloadCoopStatusStones(contractID, coopID, details, soloName, useBuffHistory, eiID)
154155

155156
contract := FindContractByIDs(contractID, coopID)
156157
if contract != nil {
@@ -166,6 +167,7 @@ func HandleStonesCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
166167
// Fill in our calling parameters
167168
cache.contractID = contractID
168169
cache.coopID = coopID
170+
cache.eiID = eiID
169171
cache.details = details
170172
cache.soloName = soloName
171173
cache.private = privateReply
@@ -247,11 +249,11 @@ type artifactSet struct {
247249
}
248250

249251
// DownloadCoopStatusStones will download the coop status for a given contract and coop ID
250-
func DownloadCoopStatusStones(contractID string, coopID string, details bool, soloName string, useBuffHistory bool) (string, string, []*discordgo.MessageEmbedField) {
252+
func DownloadCoopStatusStones(contractID string, coopID string, details bool, soloName string, useBuffHistory bool, eeidOverride string) (string, string, []*discordgo.MessageEmbedField) {
251253
var builderURL strings.Builder
252254
var field []*discordgo.MessageEmbedField
253255

254-
coopStatus, _, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, "")
256+
coopStatus, _, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, eeidOverride)
255257
if err != nil {
256258
return err.Error(), "", field
257259
}

src/boost/stones_pages.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ func sendStonesPage(s *discordgo.Session, i *discordgo.InteractionCreate, newMes
8181

8282
if exists && (refresh || cache.expirationTimestamp.Before(time.Now())) {
8383

84-
s1, urls, tiles := DownloadCoopStatusStones(cache.contractID, cache.coopID, cache.details, cache.soloName, cache.useBuffHistory)
84+
s1, urls, tiles := DownloadCoopStatusStones(cache.contractID, cache.coopID, cache.details, cache.soloName, cache.useBuffHistory, cache.eiID)
8585
newCache := buildStonesCache(s1, urls, tiles)
8686

8787
newCache.private = cache.private
8888
newCache.xid = cache.xid
8989
newCache.contractID = cache.contractID
9090
newCache.coopID = cache.coopID
91+
newCache.eiID = cache.eiID
9192
newCache.details = cache.details
9293
newCache.soloName = cache.soloName
9394
newCache.useBuffHistory = cache.useBuffHistory
@@ -359,6 +360,7 @@ type stonesCache struct {
359360
expirationTimestamp time.Time
360361
contractID string
361362
coopID string
363+
eiID string
362364
details bool
363365
soloName string
364366
useBuffHistory bool

src/boost/teamwork.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ func HandleTeamworkEvalCommand(s *discordgo.Session, i *discordgo.InteractionCre
172172
coopID = strings.ToLower(contract.CoopID)
173173
}
174174

175+
eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id")
175176
var str string
176-
str, fields, _ := DownloadCoopStatusTeamwork(contractID, coopID, true)
177+
str, fields, _ := DownloadCoopStatusTeamwork(contractID, coopID, true, eiID)
177178
if fields == nil || strings.HasSuffix(str, "no such file or directory") || strings.HasPrefix(str, "No grade found") {
178179
// Trim output to 3500 characters if needed
179180
trimmedStr := str
@@ -198,6 +199,7 @@ func HandleTeamworkEvalCommand(s *discordgo.Session, i *discordgo.InteractionCre
198199
// Fill in our calling parameters
199200
cache.contractID = contractID
200201
cache.coopID = coopID
202+
cache.eiID = eiID
201203
cache.public = publicReply
202204
cache.showScores = scoresFirst
203205
if eggign != "" {
@@ -224,7 +226,7 @@ func HandleTeamworkEvalCommand(s *discordgo.Session, i *discordgo.InteractionCre
224226
}
225227

226228
// DownloadCoopStatusTeamwork will download the coop status for a given contract and coop ID
227-
func DownloadCoopStatusTeamwork(contractID string, coopID string, setContractEstimate bool) (string, map[string][]TeamworkOutputData, ContractScore) {
229+
func DownloadCoopStatusTeamwork(contractID string, coopID string, setContractEstimate bool, eeidOverride string) (string, map[string][]TeamworkOutputData, ContractScore) {
228230
var dataTimestampStr string
229231
var nowTime time.Time
230232

@@ -275,7 +277,7 @@ func DownloadCoopStatusTeamwork(contractID string, coopID string, setContractEst
275277
return fmt.Sprintf("Filenames:\n%s", strings.Join(fileNames, "\n")), nil, ContractScore{}
276278
}
277279

278-
coopStatus, nowTime, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, "")
280+
coopStatus, nowTime, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, eeidOverride)
279281
if err != nil {
280282
return err.Error(), nil, ContractScore{}
281283
}

src/boost/teamwork_pages.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type teamworkCache struct {
2424
expirationTimestamp time.Time
2525
contractID string
2626
coopID string
27+
eiID string
2728
public bool
2829
names []string
2930
fields map[string][]TeamworkOutputData
@@ -91,14 +92,15 @@ func sendTeamworkPage(s *discordgo.Session, i *discordgo.InteractionCreate, newM
9192

9293
if exists && (refresh || cache.expirationTimestamp.Before(time.Now())) {
9394

94-
s1, fields, _ := DownloadCoopStatusTeamwork(cache.contractID, cache.coopID, true)
95+
s1, fields, _ := DownloadCoopStatusTeamwork(cache.contractID, cache.coopID, true, cache.eiID)
9596
newCache := buildTeamworkCache(s1, fields)
9697

9798
newCache.public = cache.public
9899
newCache.previousPage = cache.previousPage
99100
newCache.xid = cache.xid
100101
newCache.contractID = cache.contractID
101102
newCache.coopID = cache.coopID
103+
newCache.eiID = cache.eiID
102104
newCache.page = cache.page
103105
newCache.showScores = cache.showScores
104106
if refresh {

src/track/track_update.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/bwmarrin/discordgo"
99
"github.com/mkmccarty/TokenTimeBoostBot/src/ei"
10+
"github.com/mkmccarty/TokenTimeBoostBot/src/farmerstate"
1011
)
1112

1213
// HandleTrackerRefresh will call the API and update the start time and duration
@@ -37,7 +38,7 @@ func HandleTrackerRefresh(s *discordgo.Session, i *discordgo.InteractionCreate)
3738
// Update the tracker with new values
3839
t, err := getTrack(userID, name)
3940
if err == nil {
40-
startTime, contractDurationSeconds, err := DownloadCoopStatusTracker(t.ContractID, t.CoopID)
41+
startTime, contractDurationSeconds, err := DownloadCoopStatusTracker(t.ContractID, t.CoopID, userID)
4142
if err != nil {
4243
errorStr := fmt.Sprintf("Error: %s, check your coop-id", err)
4344
_, _ = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
@@ -60,15 +61,16 @@ func HandleTrackerRefresh(s *discordgo.Session, i *discordgo.InteractionCreate)
6061
}
6162

6263
// DownloadCoopStatusTracker will download the coop status for a given contract and coop ID
63-
func DownloadCoopStatusTracker(contractID string, coopID string) (time.Time, float64, error) {
64+
func DownloadCoopStatusTracker(contractID string, coopID string, userID string) (time.Time, float64, error) {
6465
nowTime := time.Now()
6566

6667
eiContract := ei.EggIncContractsAll[contractID]
6768
if eiContract.ID == "" {
6869
return time.Time{}, 0, fmt.Errorf("invalid contract ID")
6970
}
7071

71-
coopStatus, _, _, err := ei.GetCoopStatus(contractID, coopID, "")
72+
eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id")
73+
coopStatus, _, _, err := ei.GetCoopStatus(contractID, coopID, eiID)
7274
if err != nil {
7375
return time.Time{}, 0, err
7476
}

0 commit comments

Comments
 (0)